Skip to content

Commit

Permalink
Python-require issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnuernber committed Dec 14, 2019
1 parent 2cafb93 commit 4a9ae56
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Time for a ChangeLog!


## 1.25


Fixed (with tests) major issue with require-python.


## 1.24


Expand Down
17 changes: 11 additions & 6 deletions src/libpython_clj/require.clj
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,13 @@
python-namespace (find-ns module-name-or-ns)
this-module (import-module (str module-name))]

(when reload?
(remove-ns module-name)
(reload-module this-module))
(create-ns module-name-or-ns)
(cond
reload?
(do
(remove-ns module-name)
(reload-module this-module))
(not python-namespace)
(create-ns module-name-or-ns))

;; bind the python module to its symbolic name
;; in the current namespace
Expand Down Expand Up @@ -252,8 +255,10 @@
(into {}))]

;;Always make the loaded namespace available to the current namespace.
(intern current-ns-sym (with-meta module-name-or-ns
{:doc (doc this-module)}))
(intern current-ns-sym
(with-meta module-name-or-ns
{:doc (doc this-module)})
this-module)
(let [refer-symbols
(cond
;; include everything into the current namespace,
Expand Down
5 changes: 4 additions & 1 deletion test/libpython_clj/require_python_test.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns libpython-clj.require-python-test
(:require [libpython-clj.require :refer [require-python]]
[libpython-clj.python :as py]
[clojure.test :refer :all]))


Expand All @@ -8,7 +9,8 @@

(require-python '[math
:refer :*
:exclude [sin cos]])
:exclude [sin cos]
:as pymath])


(deftest base-require-test
Expand All @@ -17,4 +19,5 @@
(is (contains? publics 'floor))
(is (not (contains? publics 'sin)))
(is (= 10.0 (double (floor 10.1))))
(is (= pymath (py/import-module "math")))
(is (thrown? Throwable (require-python '[math :refer [blah]])))))

0 comments on commit 4a9ae56

Please sign in to comment.