Skip to content

added load-file function #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions cljbridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def py_dict_to_keyword_map(py_dict):
return hash_map


def init_clojure_repl(**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
Expand All @@ -157,10 +157,36 @@ 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 "load_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))

if "start_repl" in kw_args:
resolve_call_fn("libpython-clj2.embedded/start-repl!",
py_dict_to_keyword_map(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;")
Expand Down
9 changes: 9 additions & 0 deletions topics/embedded.md
Original file line number Diff line number Diff line change
Expand Up @@ -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???
Expand Down
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