clj-python / libpython-clj

Python bindings for Clojure
Eclipse Public License 2.0
1.08k stars 68 forks source link

added load-file function #176

Closed behrica closed 2 years ago

behrica commented 2 years ago

as discussed here: https://clojurians.zulipchat.com/#narrow/stream/215609-libpython-clj-dev/topic/embeded.20cli.20apps

behrica commented 2 years ago

I am not sure, about the use case of "not boot/up kill the vm". Is it a "python developer", which wants to use Clojure (maybe due to one specific library)?

My use case is the equivalent of "clj hello.clj",

in which hello.clj contains some libpython-clj code.

Concretely I run it like thgis:

docker run  ..... ..... my-lib python3  -c "import sys;sys.path.append('/home/user');import cljbridge;cljbridge.load_clojure_file(clj_file='hello.clj)"
behrica commented 2 years ago

But indeed, I can see the "need" to "load" several clojure files, one after the other.

behrica commented 2 years ago

Maybe we should put this on hold. I see know a more generalise requirement of configuring the "bootstrap" of the JVM/Clojure process. Example would be to start "a notespace server together with the nrepl": I could look like this in python

    require("notespace.api")
    resolve_call_fn("notespace.api/init")
    resolve_call_fn("libpython-clj2.embedded/start-repl!",
                    py_dict_to_keyword_map(kw_args))

I am not sure, if this belongs here, or should that be done in Clojure side ?

My use case would be a Docker container, which start nrepl and notespace on startup

behrica commented 2 years ago

I now went a bit more into a general "init_clojure" function, with 3 option flags, which controls:

The default could be current behaviour, so:

cnuernber commented 2 years ago

I think this looks good to me at this point. I think we should integrate this, let it be and see if people respond.

behrica commented 2 years ago

I have not implemented any default . Is this needed ?

behrica commented 2 years ago

I just came to an other use case, namely running of unit tests. I started to develop libraries which rely on "libpython-clj" , so I started to write unit tests. They need of course a working libpython-clj. (embedded)

behrica commented 2 years ago

maybe teh "real need" is a cli tool, so a replacement for the "clj" launcher, clj-py which starts libpython clj on startup and then does the "right" think, supporting all options to execute clojure (as the clj) tool does.

Is this even feasable ?

cnuernber commented 2 years ago

I think it is feasible but this right now is a reasonable half step.

behrica commented 2 years ago

I think "both functions" is best compromise. I can see three use cases:

  1. start repl
  2. run Clojure units tests, which require libpython-clj
  3. run Clojure "clj" files for long running calculations / data transformation / model training using libpython-clj -> i do that a lot, as well in Docker
cnuernber commented 2 years ago

Sounds good to me. Are you OK if I merge this? I need to release a version of libpython-clj that works on m-1 mac.

behrica commented 2 years ago

yes, thanks