@@ -34,7 +34,8 @@ user> (py/py. np linspace 2 3 :num 10)
3434 [libpython-clj2.python.windows :as win]
3535 [tech.v3.datatype.ffi :as dtype-ffi]
3636 [tech.v3.datatype.errors :as errors]
37- [clojure.tools.logging :as log])
37+ [clojure.tools.logging :as log]
38+ clojure.edn)
3839 (:import [java.util Map List]
3940 [clojure.lang IFn]))
4041
@@ -47,6 +48,26 @@ user> (py/py. np linspace 2 3 :num 10)
4748 " Initialize the python library. If library path is not provided, then the system
4849 attempts to execute a simple python program and have python return system info.
4950
51+ Note: all of the options passed to `initialize!` may now be provided in
52+ a root-level `python.edn` file. Example:
53+
54+ ```
55+ ;; python.edn
56+ {:python-executable \" /usr/bin/python3.7\"
57+ :python-library-path \" /usr/lib/libpython3.7m.so\"
58+ :python-home \" /usr/lib/python3.7\"
59+ :python-verbose true}
60+ ```
61+ or, using a local virtual environment:
62+ ```
63+ ;; python.edn
64+ {:python-executable \" env/bin/python\" }
65+ ```
66+
67+ The file MUST be named `python.edn` and be in the root of the classpath.
68+ With a `python.edn` file in place, the `initialize!` function may be called
69+ with no arguments and the options will be read from the file. If arguments are
70+ passed to `initialize!` then they will override the values in the file.
5071
5172 Returns either `:ok` in which case the initialization completed successfully or
5273 `:already-initialized` in which case we detected that python has already been
@@ -72,8 +93,12 @@ user> (py/py. np linspace 2 3 :num 10)
7293 no-io-redirect?]
7394 :as options}]
7495 (if-not (and (py-ffi/library-loaded? )
75- (= 1 (py-ffi/Py_IsInitialized )))
76- (let [info (py-info/detect-startup-info options)
96+ (= 1 (py-ffi/Py_IsInitialized )))
97+ (let [python-edn-opts (-> (try (slurp " python.edn" )
98+ (catch java.io.FileNotFoundException _ " {}" ))
99+ clojure.edn/read-string)
100+ options (merge python-edn-opts options)
101+ info (py-info/detect-startup-info options)
77102 _ (log/infof " Startup info %s" info)
78103 _ (when-let [lib-path (:java-library-path-addendum
79104 options (:java-library-path-addendum info))]
0 commit comments