Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

PYTHONPATH hacks break inner pylint imports #104

Closed
cblp opened this issue Dec 14, 2015 · 7 comments
Closed

PYTHONPATH hacks break inner pylint imports #104

cblp opened this issue Dec 14, 2015 · 7 comments
Labels

Comments

@cblp
Copy link

cblp commented Dec 14, 2015

To reproduce: jsut create and open empty file types.py:

Error: Error processing line 1 of /usr/lib/python3/dist-packages/logilab_common-1.0.2-nspkg.pth: Traceback (most recent call last): File "/usr/lib/python3.4/site.py", line 173, in addpackage exec(line) File "", line 1, in AttributeError: 'module' object has no attribute 'ModuleType' Remainder of file ignored Traceback (most recent call last): File "/usr/bin/pylint3", line 3, in run_pylint() File "/usr/lib/python3/dist-packages/pylint/init.py", line 20, in run_pylint from pylint.lint import Run File "/usr/lib/python3/dist-packages/pylint/lint.py", line 30, in from pylint.checkers import utils #pylint: disable=unused-import File "/usr/lib/python3/dist-packages/pylint/checkers/init.py", line 45, in from logilab.common.configuration import OptionsProviderMixIn File "/usr/lib/python3/dist-packages/logilab/common/init.py", line 31, in import pkg_resources File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 25, in import zipfile File "/usr/lib/python3.4/zipfile.py", line 9, in import importlib.util File "/usr/lib/python3.4/importlib/util.py", line 12, in from contextlib import contextmanager File "/usr/lib/python3.4/contextlib.py", line 5, in from functools import wraps File "/usr/lib/python3.4/functools.py", line 22, in from types import MappingProxyType ImportError: cannot import name 'MappingProxyType' Error in sys.excepthook: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook from apport.fileutils import likely_packaged, get_recent_crashes File "/usr/lib/python3/dist-packages/apport/init.py", line 5, in from apport.report import Report File "/usr/lib/python3/dist-packages/apport/report.py", line 12, in import subprocess, tempfile, os.path, re, pwd, grp, os, time File "/usr/lib/python3.4/tempfile.py", line 30, in import functools as _functools File "/usr/lib/python3.4/functools.py", line 22, in from types import MappingProxyType ImportError: cannot import name 'MappingProxyType' Original exception was: Traceback (most recent call last): File "/usr/bin/pylint3", line 3, in run_pylint() File "/usr/lib/python3/dist-packages/pylint/init.py", line 20, in run_pylint from pylint.lint import Run File "/usr/lib/python3/dist-packages/pylint/lint.py", line 30, in from pylint.checkers import utils #pylint: disable=unused-import File "/usr/lib/python3/dist-packages/pylint/checkers/init.py", line 45, in from logilab.common.configuration import OptionsProviderMixIn File "/usr/lib/python3/dist-packages/logilab/common/init.py", line 31, in import pkg_resources File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 25, in import zipfile File "/usr/lib/python3.4/zipfile.py", line 9, in import importlib.util File "/usr/lib/python3.4/importlib/util.py", line 12, in from contextlib import contextmanager File "/usr/lib/python3.4/contextlib.py", line 5, in from functools import wraps File "/usr/lib/python3.4/functools.py", line 22, in from types import MappingProxyType ImportError: cannot import name 'MappingProxyType'
Error: Error processing line 1 of /usr/lib/python3/dist-packages/logilab_common-1.0.2-nspkg.pth:
  Traceback (most recent call last):
    File "/usr/lib/python3.4/site.py", line 173, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
  AttributeError: 'module' object has no attribute 'ModuleType'
Remainder of file ignored
Traceback (most recent call last):
  File "/usr/bin/pylint3", line 3, in <module>
    run_pylint()
  File "/usr/lib/python3/dist-packages/pylint/__init__.py", line 20, in run_pylint
    from pylint.lint import Run
  File "/usr/lib/python3/dist-packages/pylint/lint.py", line 30, in <module>
    from pylint.checkers import utils #pylint: disable=unused-import
  File "/usr/lib/python3/dist-packages/pylint/checkers/__init__.py", line 45, in <module>
    from logilab.common.configuration import OptionsProviderMixIn
  File "/usr/lib/python3/dist-packages/logilab/common/__init__.py", line 31, in <module>
    import pkg_resources
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 25, in <module>
    import zipfile
  File "/usr/lib/python3.4/zipfile.py", line 9, in <module>
    import importlib.util
  File "/usr/lib/python3.4/importlib/util.py", line 12, in <module>
    from contextlib import contextmanager
  File "/usr/lib/python3.4/contextlib.py", line 5, in <module>
    from functools import wraps
  File "/usr/lib/python3.4/functools.py", line 22, in <module>
    from types import MappingProxyType
ImportError: cannot import name 'MappingProxyType'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 12, in <module>
    import subprocess, tempfile, os.path, re, pwd, grp, os, time
  File "/usr/lib/python3.4/tempfile.py", line 30, in <module>
    import functools as _functools
  File "/usr/lib/python3.4/functools.py", line 22, in <module>
    from types import MappingProxyType
ImportError: cannot import name 'MappingProxyType'
Original exception was:
Traceback (most recent call last):
  File "/usr/bin/pylint3", line 3, in <module>
    run_pylint()
  File "/usr/lib/python3/dist-packages/pylint/__init__.py", line 20, in run_pylint
    from pylint.lint import Run
  File "/usr/lib/python3/dist-packages/pylint/lint.py", line 30, in <module>
    from pylint.checkers import utils #pylint: disable=unused-import
  File "/usr/lib/python3/dist-packages/pylint/checkers/__init__.py", line 45, in <module>
    from logilab.common.configuration import OptionsProviderMixIn
  File "/usr/lib/python3/dist-packages/logilab/common/__init__.py", line 31, in <module>
    import pkg_resources
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 25, in <module>
    import zipfile
  File "/usr/lib/python3.4/zipfile.py", line 9, in <module>
    import importlib.util
  File "/usr/lib/python3.4/importlib/util.py", line 12, in <module>
    from contextlib import contextmanager
  File "/usr/lib/python3.4/contextlib.py", line 5, in <module>
    from functools import wraps
  File "/usr/lib/python3.4/functools.py", line 22, in <module>
    from types import MappingProxyType
ImportError: cannot import name 'MappingProxyType'
    at /home/cblp/felix/home/.atom/packages/linter-pylint/lib/main.coffee:99:23

Pylint tries to import system module types, but local file types.py steps in.

@romanchyla
Copy link

this has tortured me today, thank you @cblp; i'm new to atom and without this hint - i was looking into wrong places

basically, when linter-pylint exports PYTHONPATH; it can break the python!

i believe the right solution IFF you want to export PYTHONPATH (and only if it is not set already):

is to mege the user setting with the default path, ie:

python -c "import sys; import os; print(os.pathsep.join(sys.path))"

and append the user setting to this value

@danielfrg
Copy link

Basically the error here is that fileDir is being added to the PYTHONPATH always see https://github.com/AtomLinter/linter-pylint/blob/master/lib/main.coffee#L81 - Removing fileDir fixed this issue for me.

+1 for a better default PYTHONPATH

@cblp cblp changed the title PYTHONPATH hacks break inner pylnt imports PYTHONPATH hacks break inner pylint imports Feb 5, 2016
@xiata
Copy link

xiata commented Mar 16, 2016

I also ran into this same problem because I have a file named keyword.py. The current behavior is dangerous and prone to blowing pylint up.

Proposing this change:

  • Create a new variable for the existing python path (e.g. %e)
  • Default Python Path setting to: %e, %f, %p (preserving current broken behavior)
  • Split Python Path on /\s*,\s*/g, rejoin with path.delimiter and assign PYTHONPATH to that instead of the _.compact() stuff it currently does.

And put a warning on the setting that %f and %p may cause pylint to trigger errors if any modules shadows standard library file names.

@jacebrowning
Copy link

I am also experiencing this problem. I have a package named types.

@nbonnotte
Copy link

nbonnotte commented Jun 2, 2016

I am also having the same issues right now. The types variable happens to be bound to pandas/tests/types/__init__.py from the pandas git repo, on which I'm working...

And removing fileDir does not always fixe the problem... It seems to depend on the folder on which I am launching atom.

@ddaanet
Copy link
Contributor

ddaanet commented May 7, 2017

linter-pylint messes with PYTHON_PATH in ways that cannot be configured out. That is WRONG.

The immediate problem I am encountering is linting files in a package that contains a "importlib" module. It conflicts with the global importlib, which prevent pylint from running. It might be poor style but it must not prevent the linter from running!

You need to add projectDir or fileDir? Use the existing pythonPath configuration system.

Do not make the current broken behaviour into a default that is going to waste the time of thousand of people in the future.

Just fix it. I am making a PR right now.

@ddaanet
Copy link
Contributor

ddaanet commented May 7, 2017

PR #213

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

No branches or pull requests

8 participants