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 doesn't understand imports in "development mode" #7701

Closed
scottgasch opened this issue Nov 1, 2022 · 14 comments
Closed

Pylint doesn't understand imports in "development mode" #7701

scottgasch opened this issue Nov 1, 2022 · 14 comments
Labels
Duplicate 🐫 Duplicate of an already existing issue Question

Comments

@scottgasch
Copy link

scottgasch commented Nov 1, 2022

If I install a project via pip from PyPi and it is placed under lib/site-packages in my venv, pylint can find/import it just fine:

$ pip install pyutils
Installing collected packages: pyutils
Successfully installed pyutils-0.0.1b6

$ pylint ./program.py
program.py:129:13: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
program.py:175:19: W0703: Catching too general exception Exception (broad-except)
------------------------------------------------------------------
Your code has been rated at 9.88/10 (previous run: 9.88/10, +0.00)

But if I install this module from local sources in development mode then pylint can't figure out code that imports it:

$ pip uninstall pyutils
Found existing installation: pyutils 0.0.1b6
Uninstalling pyutils-0.0.1b6:
  Would remove:
    /usr/home/scott/py39-venv/lib/python3.9/site-packages/pyutils-0.0.1b6.dist-info/*
    /usr/home/scott/py39-venv/lib/python3.9/site-packages/pyutils/*
Proceed (Y/n)? y
  Successfully uninstalled pyutils-0.0.1b6

$ pip install -e .
Building wheels for collected packages: pyutils
  Building editable for pyutils (pyproject.toml) ... done
  Created wheel for pyutils: filename=pyutils-0.0.1b6-0.editable-py3-none-any.whl size=6552 sha256=4631e0a79f9028f0a38608e51d18af96f8fed902778b38ffba8bde32a0f9c60a
  Stored in directory: /tmp/pip-ephem-wheel-cache-qv2fcy5j/wheels/d1/b8/4e/99b126b6c6fcf38f67396da4748884306f3ca2ac09c5a42df4
Successfully built pyutils
Installing collected packages: pyutils
Successfully installed pyutils-0.0.1b6

$ pylint ./program.py
program.py:15:0: E0401: Unable to import 'pyutils' (import-error)
program.py:16:0: E0401: Unable to import 'pyutils.ansi' (import-error)
program.py:17:0: E0401: Unable to import 'pyutils.datetimes' (import-error)
program.py:18:0: E0401: Unable to import 'pyutils.files' (import-error)
program.py:129:13: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
program.py:175:19: W0703: Catching too general exception Exception (broad-except)

------------------------------------------------------------------
Your code has been rated at 8.64/10 (previous run: 9.88/10, -1.23)

I've tried various workaround involving PYTHONPATH and the system path in pylint's init-hooks and found none that really work well. Is this a known bug? Is there another recommended fix or workaround for this?

@Pierre-Sassoulas Pierre-Sassoulas added Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning Question labels Nov 1, 2022
@Pierre-Sassoulas
Copy link
Member

pylint generally work well with pip editable installs, there's a problem specific to your installation / environnement, that we'll have a hard time debugging without more details.

@scottgasch
Copy link
Author

scottgasch commented Nov 1, 2022 via email

@DanielNoord
Copy link
Collaborator

Can you reproduce this outside of PyPy? There are many variables here that can potentially cause this (setuptools, pip, PyPy, venv etc.) Just trying to see what the common factor is

@scottgasch
Copy link
Author

scottgasch commented Nov 1, 2022 via email

@DanielNoord
Copy link
Collaborator

Oh my bad, I completely misread you question and thought this was happening on PyPy.

I think I actually already know what this issue is, namely:
pylint-dev/astroid#1752

This is likely a duplicate of #7306. Could you test with a lower version of setuptools?

@scottgasch
Copy link
Author

scottgasch commented Nov 1, 2022 via email

@DanielNoord
Copy link
Collaborator

Hm, that's weird. Although I must say I have had many issues while working on that PR with getting stuff to reproduce. pip doesn't always seem to use the setuptools installation you expect it to.
It seems likely that this is a duplicate, but I can't confirm 100% obviously..

@scottgasch
Copy link
Author

scottgasch commented Nov 1, 2022 via email

@DanielNoord
Copy link
Collaborator

Does that also happen with the lower version of setuptools?

@scottgasch
Copy link
Author

scottgasch commented Nov 1, 2022 via email

@DanielNoord
Copy link
Collaborator

Hm, I would need to look into that. I'm almost certain we don't support that json file, and I wonder how it ends up there. I feel like I saw recent discussion about using json files, but maybe setuptools also did so on older versions.

@niander
Copy link

niander commented Nov 9, 2022

I am having the same issue. Installing "setupotools<63.0.0" did not fix. However, using SETUPTOOLS_ENABLE_FEATURES="legacy-editable" did fix my issue

@scottgasch
Copy link
Author

scottgasch commented Nov 9, 2022 via email

@Pierre-Sassoulas
Copy link
Member

I'm closing as a duplicate of #7306

@Pierre-Sassoulas Pierre-Sassoulas closed this as not planned Won't fix, can't repro, duplicate, stale Nov 9, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Duplicate 🐫 Duplicate of an already existing issue and removed Needs reproduction 🔍 Need a way to reproduce it locally on a maintainer's machine Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning labels Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate 🐫 Duplicate of an already existing issue Question
Projects
None yet
Development

No branches or pull requests

4 participants