Skip to content

Commit 65b47d6

Browse files
author
digikar99
committed
[int] rewrite defpysubmodules without any changes
1 parent 270400b commit 65b47d6

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/import-export.lisp

+17-16
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@ Arguments:
212212
continue-ignoring-errors silent cache-p)
213213
(declare (optimize debug))
214214
(if (null submodule-names) (return-from defpysubmodules nil))
215+
;; The AND clauses in (EQL T) clause below correspond to:
216+
;; 1. Avoid private modules / packages
217+
;; 2. The above processing using pkgutil.iter_modules above returns *all*
218+
;; the possible submodules of PYMODULE-NAME. However, consider this behavior -
219+
;; Some of these submodules may not actually be imported while
220+
;; importing PYMODULE-NAME. For example, the above processing for
221+
;; "matplotlib" outputs "pyplot" as a submodule of matplotlib.
222+
;; However, "import matplotlib" does not import "pyplot".
223+
;; See https://stackoverflow.com/questions/14812342/matplotlib-has-no-attribute-pyplot
224+
;; We want to preserve this behavior. That is why, we first check if PYMODULE-NAME
225+
;; actually has SUBMODULE as an attribute. If not, we do not process this any further.
215226
(let ((submodules
216227
(when (pycall "hasattr" (pyvalue pymodule-name) "__path__")
217228
(remove-if
@@ -252,22 +263,12 @@ Arguments:
252263
(pycall "pkgutil.iter_modules"
253264
(pyslot-value (pyvalue pymodule-name)
254265
"__path__")))))))))
255-
(iter (for (submodule . subsubmodules) in submodules)
256-
(for submodule-fullname = (concatenate 'string
257-
pymodule-name "." submodule))
258-
;; The AND clauses in WHEN below correspond to:
259-
;; 1. Avoid private modules / packages
260-
;; 2. The above processing using pkgutil.iter_modules above returns *all*
261-
;; the possible submodules of PYMODULE-NAME. However, consider this behavior -
262-
;; Some of these submodules may not actually be imported while
263-
;; importing PYMODULE-NAME. For example, the above processing for
264-
;; "matplotlib" outputs "pyplot" as a submodule of matplotlib.
265-
;; However, "import matplotlib" does not import "pyplot".
266-
;; See https://stackoverflow.com/questions/14812342/matplotlib-has-no-attribute-pyplot
267-
;; We want to preserve this behavior. That is why, we first check if PYMODULE-NAME
268-
;; actually has SUBMODULE as an attribute. If not, we do not process this any further.
269-
(let ((*is-submodule* t)
270-
(*hidden-submodule* (eq :hidden submodule-names)))
266+
267+
(let ((*is-submodule* t)
268+
(*hidden-submodule* (eq :hidden submodule-names)))
269+
(iter (for (submodule . subsubmodules) in submodules)
270+
(for submodule-fullname = (concatenate 'string
271+
pymodule-name "." submodule))
271272
(appending
272273
(multiple-value-list
273274
(defpymodule* submodule-fullname

0 commit comments

Comments
 (0)