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

Pylint 2.7.2 can't find its plugins on PYTHONPATH if the latter points to cwd #4252

Closed
stanislavlevin opened this issue Mar 25, 2021 · 9 comments · Fixed by #4258
Closed

Comments

@stanislavlevin
Copy link
Contributor

Steps to reproduce

[builder@localhost test]$ touch pylint_plugins.py
[builder@localhost test]$ PYTHONPATH=. python3 -m pylint --load-plugins pylint_plugins

Current behavior

Pylint can't find plugins in current working directory(PYTHONPATH is set to this directory):

Traceback (most recent call last):
  File "/usr/lib64/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/src/.local/lib/python3/site-packages/pylint/__main__.py", line 18, in <module>
    pylint.run_pylint()
  File "/usr/src/.local/lib/python3/site-packages/pylint/__init__.py", line 22, in run_pylint
    PylintRun(sys.argv[1:])
  File "/usr/src/.local/lib/python3/site-packages/pylint/lint/run.py", line 266, in __init__
    linter.load_plugin_modules(self._plugins)
  File "/usr/src/.local/lib/python3/site-packages/pylint/lint/pylinter.py", line 490, in load_plugin_modules
    module = modutils.load_module_from_name(modname)
  File "/usr/src/.local/lib/python3/site-packages/astroid/modutils.py", line 210, in load_module_from_name
    return importlib.import_module(dotted_name)
  File "/usr/lib64/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pylint_plugins'

The regression is caused by cc8d918:

> /usr/src/.local/lib/python3/site-packages/pylint/__main__.py(17)<module>()
-> sys.path = [p for p in sys.path if p not in ("", os.getcwd())]
(Pdb) sys.path
['/usr/src/test', '/usr/src/test', '/usr/lib64/python39.zip', '/usr/lib64/python3.9', '/usr/lib64/python3.9/lib-dynload', '/usr/src/.local/lib/python3/site-packages', '/usr/lib64/python3/site-packages', '/usr/lib/python3/site-packages']
(Pdb) n
> /usr/src/.local/lib/python3/site-packages/pylint/__main__.py(19)<module>()
-> pylint.run_pylint()
(Pdb) sys.path
['/usr/lib64/python39.zip', '/usr/lib64/python3.9', '/usr/lib64/python3.9/lib-dynload', '/usr/src/.local/lib/python3/site-packages', '/usr/lib64/python3/site-packages', '/usr/lib/python3/site-packages']
(Pdb) 

Changing the cwd can workaround this.

In the meantime:

[builder@localhost test]$ PYTHONPATH=. pylint.py3 --load-plugins pylint_plugins
> /usr/src/.local/lib/python3/site-packages/pylint/__init__.py(22)run_pylint()
-> try:
(Pdb) sys.path
['/usr/bin', '/usr/src/test', '/usr/lib64/python39.zip', '/usr/lib64/python3.9', '/usr/lib64/python3.9/lib-dynload', '/usr/src/.local/lib/python3/site-packages', '/usr/lib64/python3/site-packages', '/usr/lib/python3/site-packages', '/usr/src/.local/lib/python3/site-packages/astroid/brain']
(Pdb) 

predictable doesn't cause such behaviour.

Expected behavior

Pylint should find its plugins in PYTHONPATH.

pylint --version output

Result of pylint --version output:

[builder@localhost test]$ python3 -m pylint --version
pylint 2.7.2
astroid 2.5.1
Python 3.9.2 (default, Feb 26 2021, 15:33:46) 
[GCC 10.2.1 20201125 (ALT Sisyphus 10.2.1-alt2)]

Also checked on master(same result).

@stanislavlevin
Copy link
Contributor Author

CC: @cdce8p, @sbraz.

@sbraz
Copy link
Contributor

sbraz commented Mar 25, 2021

Hi @stanislavlevin,
Was this not the case in older versions? Does PYTHONPATH="$(cwd)" make a difference?

@stanislavlevin
Copy link
Contributor Author

@sbraz, neither absolute nor relative path work. I pointed to concrete commit with which the issue happens.

@stanislavlevin
Copy link
Contributor Author

This worked for years. In particular, the regression breaks FreeIPA (https://github.com/freeipa/freeipa/blob/master/Makefile.am#L363).

@sbraz
Copy link
Contributor

sbraz commented Mar 25, 2021

Shrug, I just wanted to fix some failing tests, maybe the commit should just be reverted.

stanislavlevin added a commit to stanislavlevin/freeipa that referenced this issue Mar 26, 2021
stanislavlevin added a commit to stanislavlevin/fc-admin that referenced this issue Mar 26, 2021
This is not distro-friendly(script name differs from distro to distro).
Revert this back after fixing:
pylint-dev/pylint#4252

Signed-off-by: Stanislav Levin <slev@altlinux.org>
stanislavlevin added a commit to stanislavlevin/fc-admin that referenced this issue Mar 26, 2021
This is not distro-friendly(script name differs from distro to distro).
Revert this back after fixing:
pylint-dev/pylint#4252

Signed-off-by: Stanislav Levin <slev@altlinux.org>
olivergs pushed a commit to fleet-commander/fc-admin that referenced this issue Mar 26, 2021
This is not distro-friendly(script name differs from distro to distro).
Revert this back after fixing:
pylint-dev/pylint#4252

Signed-off-by: Stanislav Levin <slev@altlinux.org>
@cdce8p
Copy link
Member

cdce8p commented Mar 27, 2021

@Pierre-Sassoulas Do you have a suggestion how we should handle this one? Should we revert the change? If so, it might make sense to include it in 2.7.3

@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.7.3 milestone Mar 27, 2021
@Pierre-Sassoulas
Copy link
Member

We'll need to add tests again, but I don't know how to fix precisely. Those change were done to handle python path starting or ending with a colon, so I think not being able to use our plugins is a bigger problem than not handling python starting or ending with a colon. I think the fast thing to do would be to revert and add something in the doc about the current pythonpath limitation, what do you think ?

@cdce8p
Copy link
Member

cdce8p commented Mar 27, 2021

I might have found a way to fix this one without reverting the previous change: #4258

@stanislavlevin
Copy link
Contributor Author

The fix was verified. Thank you!

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

Successfully merging a pull request may close this issue.

4 participants