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

Add a post initialization step for optional stldib modules #3856

Open
rth opened this issue May 14, 2023 · 1 comment
Open

Add a post initialization step for optional stldib modules #3856

rth opened this issue May 14, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@rth
Copy link
Member

rth commented May 14, 2023

The stdlib modules have some number of optional components that we also allow to be optionally installed.

Unfortunately, CPython does not operate under the assumption that such modules can be installed at runtime. Modules would have a

try:
   import optional_feature
except ImportError:
   feature_available = False

and if the optional_feature is installed after this module is imported, the module would still behave as though it's not installed. A good example of this can be found in koenvo/pyodide-http#33 (comment) for the SSL module.

A solution is to minimize the import of modules before the installation, but it's not always possible in downstream applications.

We could raise this issue with CPython but it's unlikely that would want to make this feature detection more dynamic, instead of pre-determined at import time.

The other alternative is to have a list of modules that do this and reload them (if they are already imported and present in sys.modules) when such an optional stdlib module is installed. For instance, looking, at

rg -U "try:\n\s+import ssl"  cpython/Lib

gives some idea of the impacted modules. This dependency tree could probably be determined automatically by parsing the code.

It would help, but probably not address more complex dependencies as outlined in the above-linked issue.

@rth rth added bug Something isn't working enhancement New feature or request and removed bug Something isn't working labels May 14, 2023
@ryanking13
Copy link
Member

Thanks for opening the issue @rth. Dealing with optional stdlib modules is indeed quite tricky... not sure reloading can solve the complex dependencies that you mentioned but it is worth trying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants