Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basilisp's require always requires all parent namespaces #963

Open
chrisrink10 opened this issue Aug 16, 2024 · 0 comments
Open

Basilisp's require always requires all parent namespaces #963

chrisrink10 opened this issue Aug 16, 2024 · 0 comments
Labels
component:importer Issue pertaining the import/require logic issue-type:bug Something isn't working

Comments

@chrisrink10
Copy link
Member

Basilisp's require mechanism is built on top of Python's importlib. Specifically, calling (require 'some-ns.child) delegates the importing logic to importlib.import_module("some_ns.child") which ultimately makes uses the Basilisp finder/loader to find and load files. This allows us to use a lot of existing Python machinery for caching and loading and also allows Python files to easily import Basilisp code so long as the Basilisp library is available in their environment.

However, because of how Python's packages and modules work, importlib.import_module always attempts to import parent namespaces (modules) before loading the requested namespace because in Python the children of a namespace are set as attributes on the parent so the parent must be loaded. On the other hand, Clojure namespaces are purely organizational and there is no defined hierarchical relationship between "parent" and "child" namespaces. In Clojure, requiring some-ns.child will not force some-ns to be loaded first.

The specific solution for how we handle this is not clear to me because importlib does not actually allow loaders or finders to override this portion of the import logic.

The most obvious potential solution is lazily loading modules. The builtin lazy loading mechanism assumes it's dealing with a standard Python module, so we would likely need to create a custom lazy loader for Basilisp.

Further discussion in #957

@chrisrink10 chrisrink10 added issue-type:bug Something isn't working component:importer Issue pertaining the import/require logic labels Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:importer Issue pertaining the import/require logic issue-type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant