@@ -212,6 +212,17 @@ Arguments:
212
212
continue-ignoring-errors silent cache-p)
213
213
(declare (optimize debug ))
214
214
(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.
215
226
(let ((submodules
216
227
(when (pycall " hasattr" (pyvalue pymodule-name) " __path__" )
217
228
(remove-if
@@ -252,22 +263,12 @@ Arguments:
252
263
(pycall " pkgutil.iter_modules"
253
264
(pyslot-value (pyvalue pymodule-name)
254
265
" __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))
271
272
(appending
272
273
(multiple-value-list
273
274
(defpymodule* submodule-fullname
0 commit comments