Skip to content

Commit

Permalink
[fix] defpysubmodules should call defpymodule* and not defpymodule
Browse files Browse the repository at this point in the history
  • Loading branch information
digikar99 committed Jun 6, 2024
1 parent 775899e commit d4aa8cf
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/import-export.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ Arguments:

;;; packages in python are collection of modules; module is a single python file
;;; In fact, all packages are modules; but all modules are not packages.
(defun defpysubmodules (pymodule-name lisp-package continue-ignoring-errors cache-p)
(defun defpysubmodules
(pymodule-name lisp-package reload safety continue-ignoring-errors
silent cache-p)
(let ((submodules
(when (pycall "hasattr" (pyvalue pymodule-name) "__path__")
(mapcar (lambda (elt)
Expand Down Expand Up @@ -238,14 +240,18 @@ Arguments:
(when (and (char/= #\_ (aref submodule 0))
(pycall "hasattr" (pyvalue pymodule-name) submodule))
(let ((*is-submodule* t))
(collect
(macroexpand-1
`(defpymodule ,submodule-fullname
,has-submodules
:cache ,cache-p
:lisp-package ,(concatenate 'string lisp-package "."
(lispify-name submodule))
:continue-ignoring-errors ,continue-ignoring-errors))))))))
(appending
(multiple-value-list
(defpymodule* submodule-fullname
has-submodules
(concatenate 'string lisp-package "."
(lispify-name submodule))
t
reload
safety
continue-ignoring-errors
silent
cache-p))))))))

(declaim (ftype (function (string string)) pymodule-import-string))
(defun pymodule-import-string (pymodule-name lisp-package)
Expand Down Expand Up @@ -424,7 +430,8 @@ Returns multiple values:
fun-names))
(package-exists-p (gensym "PACKAGE-EXISTS-P"))
(fun-symbol-names (mapcar #'symbol-name fun-symbols)))
(values `(defvar ,package-exists-p (find-package ,lisp-package))
(values `(eval-when (:compile-toplevel :load-toplevel :execute)
(defvar ,package-exists-p (find-package ,lisp-package)))
;; We need the package to even read the next form!
;; But we can only know if or not the package exists beforehand
;; before creating it! After creating it, it definitely exists!
Expand All @@ -441,7 +448,10 @@ Returns multiple values:
,@(if import-submodules
(defpysubmodules package-in-python
lisp-package
reload
safety
continue-ignoring-errors
silent
cache-p))
,@(iter (for fun-name in fun-names)
(for fun-symbol in fun-symbols)
Expand Down

0 comments on commit d4aa8cf

Please sign in to comment.