pylint-bot / pylint-unofficial

UNOFFICIAL playground for pylint github migration
0 stars 0 forks source link

buildout with z3c packages fails with import-error #687

Open pylint-bot opened 9 years ago

pylint-bot commented 9 years ago

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 commented 9 years ago

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