Skip to content

Commit

Permalink
Adding back in java library path shenanigans
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuernber committed Mar 8, 2021
1 parent 8760054 commit e72eeda
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.10.2" :scope "provided"]
[camel-snake-kebab "0.4.0"]
[cnuernber/dtype-next "6.07"]
[cnuernber/dtype-next "6.08"]
[net.java.dev.jna/jna "5.7.0"]
[org.clojure/data.json "1.0.0"]]
:profiles {:dev {:dependencies [[criterium "0.4.5"]
Expand Down
3 changes: 1 addition & 2 deletions scripts/conda-repl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ source activate pyclj
export LD_LIBRARY_PATH="$(python3-config --prefix)/lib"

lein update-in :dependencies conj \[nrepl\ \"0.6.0\"\]\
-- update-in :plugins conj \[cider/cider-nrepl\ \"0.22.4\"\]\
-- update-in :plugins conj \[cider/cider-nrepl\ \"0.25.5\"\]\
-- repl :headless :host localhost

3 changes: 1 addition & 2 deletions scripts/py38-repl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash

lein update-in :dependencies conj \[nrepl\ \"0.6.0\"\]\
-- update-in :plugins conj \[cider/cider-nrepl\ \"0.22.4\"\]\
-- update-in :plugins conj \[cider/cider-nrepl\ \"0.25.5\"\]\
-- repl :headless :host localhost

9 changes: 8 additions & 1 deletion src/libpython_clj2/python.clj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ user> (py/py. np linspace 2 3 :num 10)
(= 1 (py-ffi/Py_IsInitialized)))
(let [info (py-info/detect-startup-info options)
_ (log/infof "Startup info %s" info)
_ (when-let [lib-path (:java-library-path-addendum
options (:java-library-path-addendum info))]
(log/infof "Prefixing java library path: %s" lib-path)
(py-ffi/append-java-library-path! lib-path))
libname (->> (concat (when library-path [library-path]) (:libnames info))
(dechunk-map identity)
(filter #(try
Expand All @@ -86,7 +90,10 @@ user> (py/py. np linspace 2 3 :num 10)
libname (:python-home info)
(assoc options
:program-name (:program-name options (:executable info))
:python-home (:python-home options (:python-home info))))
:python-home (:python-home options (:python-home info))
:java-library-path-addendum (:java-library-path-addendum
options
(:java-library-path-addendum info))))

(when-not (nil? windows-anaconda-activate-bat)
(win/setup-windows-conda! windows-anaconda-activate-bat
Expand Down
10 changes: 10 additions & 0 deletions src/libpython_clj2/python/ffi.clj
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,16 @@ Each call must be matched with PyGILState_Release"}
@format-exc-pyfn*)


(defn append-java-library-path!
[new-search-path]
(let [existing-paths (-> (System/getProperty "java.library.path")
(s/split #":"))]
(when-not (contains? (set existing-paths) new-search-path)
(let [new-path-str (s/join ":" (concat [new-search-path]
existing-paths))]
(System/setProperty "java.library.path" new-path-str)))))


(defn initialize!
[libpath python-home & [{:keys [signals? program-name python-home]
:or {signals? true
Expand Down
4 changes: 2 additions & 2 deletions src/libpython_clj2/python/info.clj
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ print(json.dumps(


(defn java-library-path-addendum
[system-info & [{:keys [python-home]}]]
[python-home]
(when python-home
(-> (Paths/get python-home
(into-array String ["lib"]))
Expand All @@ -87,7 +87,7 @@ print(json.dumps(
(log/info "Detecting startup info"))
(let [system-info (find-python-info options)
python-home (find-python-home system-info options)
java-lib-path (java-library-path-addendum system-info options)
java-lib-path (java-library-path-addendum python-home)
[ver-maj ver-med _ver-min] (:version system-info)
lib-version (format "%s.%s" ver-maj ver-med)
libname (or library-path
Expand Down

0 comments on commit e72eeda

Please sign in to comment.