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

Namespace package does not appear to be properly defined #26

Closed
kevin-brown opened this issue Feb 9, 2018 · 3 comments
Closed

Namespace package does not appear to be properly defined #26

kevin-brown opened this issue Feb 9, 2018 · 3 comments

Comments

@kevin-brown
Copy link

This is a weird one, which we noticed a while back but I didn't bother tracking down until today.

When anyone tries to import pkg_resources, which is provided by setuptools, it will parse through all of your Python modules to determine what packages exist. An ImportWarning is triggered because, while the backports directory exists, it does not contain a __init__.py file so it's not technically a Python package. This does not appear to have any negative impact on how it enumerates the Python packages, but it is a sign that the namespace package is not properly being set up.

You can verify that this issue exists with the latest version, 1.0.5, by running the following command. I've included the output that I'm getting for reference.

$ python -W error::ImportWarning -c 'import pkg_resources;'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2927, in <module>
    @_call_aside
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2913, in _call_aside
    f(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2952, in _initialize_master_working_set
    add_activation_listener(lambda dist: dist.activate())
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 956, in subscribe
    callback(dist)
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2952, in <lambda>
    add_activation_listener(lambda dist: dist.activate())
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2515, in activate
    declare_namespace(pkg)
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2097, in declare_namespace
    _handle_ns(packageName, path_item)
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2031, in _handle_ns
    loader = importer.find_module(packageName)
  File "/usr/lib/python2.7/pkgutil.py", line 186, in find_module
    file, filename, etc = imp.find_module(subname, path)
ImportWarning: Not importing directory '/usr/local/lib/python2.7/dist-packages/backports': missing __init__.py

I can verify that the namespace package is in fact missing the __init__.py file by checking out the package directory.

$ ls /usr/local/lib/python2.7/dist-packages/backports
configparser  csv.py  csv.pyc

I'll note that while I included the reduced scope example of directly importing the module, we were seeing this in the wild while running both the unittest and pytest test runners.

@ryanhiebert
Copy link
Owner

Thanks for the bug report. Obviously, backported namespace packages can be finnicky, to say the least. Can you give me steps to reproduce this in a clean environment? It looks like you may have configparser and csv both installed, so could it be related to having both of them? I'm not necessarily trying to cast blame, but could it be an issue in configparser?

@kevin-brown
Copy link
Author

This is actually a fairly well-known issue in configparser apparently, it's a shame they haven't tried to correct it.

https://bitbucket.org/ambv/configparser/issues/17/importerror-when-used-with-other-backports
https://bitbucket.org/ambv/configparser/issues/20/importwarning-missing-__init__py

My apologies for assuming it was this backported library that was causing the issue. It looks like configparser is required by pytest at the moment, so it's not actually possible to work around this warning.

@ryanhiebert
Copy link
Owner

Oh, that's annoying. Thank you for reporting back.

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