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

Q: how to replace __import__("pkg_resources").declare_namespace(__name__) by some code using importlib_metadata? #378

Closed
kloczek opened this issue May 21, 2022 · 2 comments
Labels
question Further information is requested

Comments

@kloczek
Copy link

kloczek commented May 21, 2022

I'm trying to get rid of usage 'pkg_resourcesin allsphinxcontrib-` packages.
All those packages have in source tree something like

$ cat sphinxcontrib/__init__.py
__import__("pkg_resources").declare_namespace(__name__)

I cannot figure out how to replace that to use importlib_metadata.
May I ask for help? 🤔

@jaraco
Copy link
Member

jaraco commented May 21, 2022

Unfortunately, there's no importlib replacement for declare_namespace. That technique is part of how sphinx has specified the namespace for contrib packages. The only way to eliminate that usage of pkg_resources is to switch to a different technique for namespace packages. Sadly, that will require a coordinated effort of all authors of sphinxcontrib packages and likely backward-incompatible transition because pkg_resource-style namespace packages are incompatible with pkgutil-style and native namespace packages.

I did this same transition with the jaraco namespace in early 2019. The good news is that it was mostly painless, but I also was able to update all the packages in a short period (days/weeks), so any compatibility issues that might have arisen would have been minimized.

Your best bet would be to contact the Sphinx maintainers and see if they have any plans to migrate to pkgutil or native namespace packages.

See the docs on namespace packages.

I wish I had a better answer, but I don't think there's anything that importlib can do to help here.

@jaraco jaraco closed this as completed May 21, 2022
@jaraco jaraco added the question Further information is requested label May 21, 2022
@kloczek
Copy link
Author

kloczek commented May 23, 2022

I really appreciate all those details.
Thank you very much for your time😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants