From 3d4a2f821b96972ef4bfaa9206aafe10d1e7c81b Mon Sep 17 00:00:00 2001 From: Carsten Behring Date: Tue, 12 Oct 2021 18:50:07 +0200 Subject: [PATCH 1/6] added load-file function --- cljbridge.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cljbridge.py b/cljbridge.py index 1385047..3cd5100 100644 --- a/cljbridge.py +++ b/cljbridge.py @@ -161,6 +161,23 @@ def init_clojure_repl(**kw_args): resolve_call_fn("libpython-clj2.embedded/start-repl!", py_dict_to_keyword_map(kw_args)) +def load_clojure_file(**kw_args): + """Initializes clojure and loads and runs a Clojure file. This function load the specified clojure file + and kills then the jvm and returns. + + Keyword arguments are: + + * `classpath_args` - List of additional arguments that be passed to the clojure + process when building the classpath. + * `clj_file` Clojure file to be loaded with Clojure `load-file` fn + """ + javabridge.start_vm(run_headless=True, class_path=repl_classpath(**kw_args)) + init_clojure_runtime() + init_libpy_embedded() + resolve_call_fn("clojure.core/load-file", + kw_args["clj_file"]) + javabridge.kill_vm() + class GenericJavaObj: __str__ = javabridge.make_method("toString", "()Ljava/lang/String;") From 084fc6738f3038af42885146018d8b622f587887 Mon Sep 17 00:00:00 2001 From: Carsten Behring Date: Tue, 12 Oct 2021 19:03:50 +0200 Subject: [PATCH 2/6] added docu for loading clojure file in embedded --- topics/embedded.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/topics/embedded.md b/topics/embedded.md index 039894b..c4384d3 100644 --- a/topics/embedded.md +++ b/topics/embedded.md @@ -154,6 +154,15 @@ in the main module - Printing from Clojure: [1 2 3 4 Embedded Clojure FTW!!] >>> ``` +## Loading and running a Clojure file in embedded mode + +We can runs as well a .clj file in embedded mode. +The following does this without an interactive pytho shell, it just runs the provided clj file with +`clojure.core/load-file` + +```bash +python3 -c 'import cljbridge;cljbridge.load_clojure_file(clj_file="my-file.clj")' +``` ## Are You Not Entertained??? From 0a08c1e4e2d7e19a152e7de85c90c1722dc90cc3 Mon Sep 17 00:00:00 2001 From: Carsten Behring Date: Wed, 13 Oct 2021 00:08:38 +0200 Subject: [PATCH 3/6] added finally --- cljbridge.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cljbridge.py b/cljbridge.py index 3cd5100..58e0fd8 100644 --- a/cljbridge.py +++ b/cljbridge.py @@ -174,9 +174,12 @@ def load_clojure_file(**kw_args): javabridge.start_vm(run_headless=True, class_path=repl_classpath(**kw_args)) init_clojure_runtime() init_libpy_embedded() - resolve_call_fn("clojure.core/load-file", - kw_args["clj_file"]) - javabridge.kill_vm() + try: + resolve_call_fn("clojure.core/load-file", + kw_args["clj_file"]) + + finally: + javabridge.kill_vm() class GenericJavaObj: From 77e5514d061be546fff6e0f3dc5c23dbf386f0a5 Mon Sep 17 00:00:00 2001 From: Carsten Behring Date: Tue, 19 Oct 2021 15:50:54 +0200 Subject: [PATCH 4/6] proposal of single clojure-init function --- cljbridge.py | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/cljbridge.py b/cljbridge.py index 58e0fd8..8ca8848 100644 --- a/cljbridge.py +++ b/cljbridge.py @@ -138,7 +138,7 @@ def py_dict_to_keyword_map(py_dict): return hash_map -def init_clojure_repl(**kw_args): +def init_clojure(**kw_args): """Initialize clojure with extra arguments specifically for embedding a cider-nrepl server. Then start an nrepl server. The port will both be printed to stdout and output to a .nrepl_server file. This function does not return as it leaves the GIL @@ -157,28 +157,16 @@ def init_clojure_repl(**kw_args): bind=\"0.0.0.0\"""" javabridge.start_vm(run_headless=True, class_path=repl_classpath(**kw_args)) init_clojure_runtime() + if "run_user_clj" in kw_args: + resolve_call_fn("clojure.core/load-file", + "user.clj") init_libpy_embedded() - resolve_call_fn("libpython-clj2.embedded/start-repl!", - py_dict_to_keyword_map(kw_args)) - -def load_clojure_file(**kw_args): - """Initializes clojure and loads and runs a Clojure file. This function load the specified clojure file - and kills then the jvm and returns. - Keyword arguments are: - - * `classpath_args` - List of additional arguments that be passed to the clojure - process when building the classpath. - * `clj_file` Clojure file to be loaded with Clojure `load-file` fn - """ - javabridge.start_vm(run_headless=True, class_path=repl_classpath(**kw_args)) - init_clojure_runtime() - init_libpy_embedded() - try: - resolve_call_fn("clojure.core/load-file", - kw_args["clj_file"]) + if "start_repl" in kw_args: + resolve_call_fn("libpython-clj2.embedded/start-repl!", + py_dict_to_keyword_map(kw_args)) - finally: + if "kill_vm_after" in kw_args: javabridge.kill_vm() From e715b9ac7455892e4289fd6309bd2d67ae2e6998 Mon Sep 17 00:00:00 2001 From: Carsten Behring Date: Tue, 19 Oct 2021 16:12:06 +0200 Subject: [PATCH 5/6] fixed fn name and args --- cljbridge.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cljbridge.py b/cljbridge.py index 8ca8848..9d28481 100644 --- a/cljbridge.py +++ b/cljbridge.py @@ -138,7 +138,7 @@ def py_dict_to_keyword_map(py_dict): return hash_map -def init_clojure(**kw_args): +def init_jvm(**kw_args): """Initialize clojure with extra arguments specifically for embedding a cider-nrepl server. Then start an nrepl server. The port will both be printed to stdout and output to a .nrepl_server file. This function does not return as it leaves the GIL @@ -157,7 +157,7 @@ def init_clojure(**kw_args): bind=\"0.0.0.0\"""" javabridge.start_vm(run_headless=True, class_path=repl_classpath(**kw_args)) init_clojure_runtime() - if "run_user_clj" in kw_args: + if "load_user_clj" in kw_args: resolve_call_fn("clojure.core/load-file", "user.clj") init_libpy_embedded() From 404b4425277ede0bbc7b91b591c31e40eb7257a1 Mon Sep 17 00:00:00 2001 From: Carsten Behring Date: Thu, 21 Oct 2021 23:08:40 +0200 Subject: [PATCH 6/6] added load_clojure_file --- cljbridge.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cljbridge.py b/cljbridge.py index 9d28481..720a857 100644 --- a/cljbridge.py +++ b/cljbridge.py @@ -169,6 +169,24 @@ def init_jvm(**kw_args): if "kill_vm_after" in kw_args: javabridge.kill_vm() +def load_clojure_file(**kw_args): + """Initializes clojure and loads and runs a Clojure file. This function load the specified clojure file + and kills then the jvm and returns. + + Keyword arguments are: + + * `classpath_args` - List of additional arguments that be passed to the clojure + process when building the classpath. + * `clj_file` Clojure file to be loaded with Clojure `load-file` fn + """ + javabridge.start_vm(run_headless=True, class_path=repl_classpath(**kw_args)) + init_clojure_runtime() + init_libpy_embedded() + try: + resolve_call_fn("clojure.core/load-file", + kw_args["clj_file"]) + finally: + javabridge.kill_vm() class GenericJavaObj: __str__ = javabridge.make_method("toString", "()Ljava/lang/String;") pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy