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

Incorrect value of constant NAMESPACE_PACKAGE_INIT #2070

Closed
Cykooz opened this issue Apr 14, 2020 · 2 comments
Closed

Incorrect value of constant NAMESPACE_PACKAGE_INIT #2070

Cykooz opened this issue Apr 14, 2020 · 2 comments

Comments

@Cykooz
Copy link

Cykooz commented Apr 14, 2020

"Python Packaging User Guide" does not recommend to use namespace __init__.py with code like this:

try:
    __import__('pkg_resources').declare_namespace(__name__)
except ImportError:
    __path__ = __import__('pkgutil').extend_path(__path__, __name__)

https://packaging.python.org/guides/packaging-namespace-packages/#pkg-resources-style-namespace-packages

But constant NAMESPACE_PACKAGE_INIT contains this version of code.

NAMESPACE_PACKAGE_INIT = '''\
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
'''

At least, this affects the "namespace-detector" in PyCharm. PyCharm does not support this method of namespace definition (because it is not recommended) - https://youtrack.jetbrains.com/issue/PY-38434).

Need to replace value of this constant with:

__path__ = __import__('pkgutil').extend_path(__path__, __name__)
@jaraco
Copy link
Member

jaraco commented May 28, 2020

Thanks for the report. I believe the code can be replaced by just the pkg_resources declaration. That's the form that's meant to go along with packages that declare "namespace_packages". Is this change needed for Python 2 environments, or is the change in the master, Python-3-only branch okay?

@jaraco
Copy link
Member

jaraco commented May 28, 2020

Also, this code is only used when setuptools converts a wheel to an egg, which should only really happen with setup_requires compatibility installations, which I wouldn't expect to be installed in a user's environment. Is this an actual issue or a just a potential one based on code search?

@jaraco jaraco closed this as completed in 3b32ab2 May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants