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

buildout with z3c packages fails with import-error #687

Closed
pylint-bot opened this issue Oct 30, 2015 · 2 comments
Closed

buildout with z3c packages fails with import-error #687

pylint-bot opened this issue Oct 30, 2015 · 2 comments
Labels

Comments

@pylint-bot
Copy link

Originally reported by: Adam Groszer (BitBucket: agroszer, GitHub: @agroszer?)


When running $ bin/pylint playground.form

The result is:

No config file found, using default configuration
************* Module playground.form
C:  1, 0: Missing module docstring (missing-docstring)
E:  7, 0: No name 'form' in module 'z3c' (no-name-in-module)
E:  7, 0: Unable to import 'z3c.form' (import-error)
E:  8, 0: No name 'form' in module 'z3c' (no-name-in-module)
E:  8, 0: Unable to import 'z3c.form.browser' (import-error)

But when you run bin/test the test passes, IOW z3c packages can be imported.

I created a repo to repro this:

https://github.com/agroszer/playground


@pylint-bot
Copy link
Author

Original comment by Adam Groszer (BitBucket: agroszer, GitHub: @agroszer?):


I guess I figured the z3c part.
It is bad namespace declaration, z3c packages use a variation of

#!python

try:
    # Declare this a namespace package if pkg_resources is available.
    import pkg_resources
    pkg_resources.declare_namespace('z3c')
except ImportError:
    pass

zope packages use

# this is a namespace package
try:
    import pkg_resources
    pkg_resources.declare_namespace(__name__)
except ImportError:
    import pkgutil
    __path__ = pkgutil.extend_path(__path__, __name__)

astroid has a workaround that checks for pkgutil.extend_path but not for pkg_resources.declare_namespace (in modutils.py def _module_file).
That's why z3c packages are import-error despite being on PYTHONPATH

Added https://bitbucket.org/logilab/astroid/issues/243/modutils-_module_file-ignores for astroid

@PCManticore
Copy link
Contributor

This seems to work with the master branch. astroid got support for declare_namespace as well: https://github.com/PyCQA/astroid/blob/master/astroid/interpreter/_import/spec.py#L178

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

No branches or pull requests

2 participants