-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
false positive 'c-extension-no-member' when running in environment with setuptools>=60.0 #5704
Comments
Possibly related reading: pypa/setuptools#2896
Edit Edit: I was wrong, |
Doing some digging here. I'm using today's origin/main for pylint (gently mangled with debug prints) and astroid==2.9.3. I see some failures for socket.AF_UNIX, socket.SOCK_STREAM, socket.timeout, socket.AF_INET, socket.SOL_SOCKET, socket.SO_REUSEADDR, socket.SCM_RIGHTS, struct.pack, readline.set_history_length, readline.set_completer, readline.parse_and_bind, readline.set_completer_delims, readline.read_history_file, and readline.write_history_file. I'm looking at this pylint method in @check_messages("no-member", "c-extension-no-member")
def visit_attribute(self, node: nodes.Attribute) -> None:
... the Modifying the stanza that calls
Hm. Well, nosing around in Astroid, I notice STD_LIB_DIRS does some different things.
It's certainly looking like the odd one out here is the setuptools 60.0.0 install with Python 3.7, where it wants to use I do indeed have a @Pierre-Sassoulas - This is the best triage I can do, it's in your hands now. 😔 Edit: Just kidding, I can't leave well enough alone. CPython 3.9 has a distutils that uses Looks like https://docs.python.org/3/library/sys.html#sys.platlibdir might be the culprit, so the actual behavior here is... "pylint gives false positives on Fedora and SuSE systems running Python 3.7 or Python 3.8 that are using setuptools >= 60.0.0." Looking at the setuptools distutils code https://github.com/pypa/setuptools/blob/main/setuptools/_distutils/sysconfig.py#L172 it looks as though we will TRY to use platlibdir, but we'll have a hard-fallback to 'lib'. Mmmmk. What's not clear to me right now then is why this ever worked under Python 3.7 or Python 3.8, even without the new setuptools arrangement ... Oh, Fedora ships its own patched distutils, naturally. And so with the switch to a setuptools-provided distutils, this function is no longer patched on Fedora distributions, and so it breaks. Uh. Well then. Not sure where to go from here. 😅 |
The thing is, we have changed Python 3.9 and 3.10 to work with the setuptools 60+ distutils, but not yet 3.8 or 3.7. |
Oh, I see that it is Fedora 34. |
bah. we have figured out how to move our distutils patch to sysconfig for the |
This is however very weird :/ Maybe the environment value isn't propagated deep enough? |
I've opened pypa/distutils#110 |
Yup, I goofed. I think it was getting dropped in an intermediate process somewhere.
So just in case anyone wanders in from Thanks @hroncok ! |
setuptools is a package that replaces the python stdlib 'distutils'. It is generally installed by all venv-creating tools "by default". It isn't actually needed at runtime for the qemu package, so our own setup.cfg does not mention it as a dependency. However, tox will create virtual environments that include it, and will upgrade it to the very latest version. the 'venv' tool will also include whichever version your host system happens to have. Unfortunately, setuptools version 60.0.0 and above include a hack to forcibly overwrite python's built-in distutils. The pylint tool that we use to run code analysis checks on this package relies on distutils and suffers regressions when setuptools >= 60.0.0 is present at all, see pylint-dev/pylint#5704 Instruct tox and the 'check-dev' targets to avoid setuptools packages that are too new, for now. Pipenv is unaffected, because setuptools 60 does not offer Python 3.6 support, and our pipenv config is pinned against Python 3.6. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Beraldo Leal <bleal@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Tested-by: Cleber Rosa <crosa@redhat.com> Message-id: 20220121005221.142236-1-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
@hroncok Just trying to see if there is anything we can do to solve this. Should we wait for an upstream fix for this or can we do anything in |
You could apply a dirty workaround. If you detect Python version is lower than 3.9 you can monkeypatch https://github.com/pypa/setuptools/blob/v60.0.0/_distutils_hack/__init__.py#L41 to return |
Do you have any timeframe for the fix to be live? If it's a matter of weeks I think we might hold off on it: we'll likely forget about it and might up with unnecessary fixes in the codebase. /CC: @Pierre-Sassoulas |
It currently seems that it will be easy, so matter of days. However, there might be unexpected problems, as always. |
@jnsnow If I give you this PR https://src.fedoraproject.org/rpms/python3.8/pull-request/56 with this CI build for Fedora 34 https://koji.fedoraproject.org/koji/taskinfo?taskID=81784999 you can upgrade Python 3.8 with:
My questions for you:
|
setuptools is a package that replaces the python stdlib 'distutils'. It is generally installed by all venv-creating tools "by default". It isn't actually needed at runtime for the qemu package, so our own setup.cfg does not mention it as a dependency. However, tox will create virtual environments that include it, and will upgrade it to the very latest version. the 'venv' tool will also include whichever version your host system happens to have. Unfortunately, setuptools version 60.0.0 and above include a hack to forcibly overwrite python's built-in distutils. The pylint tool that we use to run code analysis checks on this package relies on distutils and suffers regressions when setuptools >= 60.0.0 is present at all, see pylint-dev/pylint#5704 Instruct tox and the 'check-dev' targets to avoid setuptools packages that are too new, for now. Pipenv is unaffected, because setuptools 60 does not offer Python 3.6 support, and our pipenv config is pinned against Python 3.6. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Beraldo Leal <bleal@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Tested-by: Cleber Rosa <crosa@redhat.com> Message-id: 20220121005221.142236-1-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
@jnsnow Any chance you were able to test the provided Python 3.8 build? |
There is also this PR https://src.fedoraproject.org/rpms/python3.7/pull-request/41 with this CI build for Fedora 34 https://koji.fedoraproject.org/koji/taskinfo?taskID=82345254 you can upgrade Python 3.7 with:
|
@hroncok Sorry about that, didn't catch the github notif. I tried the 3.8 package and left 3.7 alone, and can observe my test suites in QEMU upstream working for 3.8 (and failing for 3.7), so that gives me some good confidence in the fix making a difference here. I tried the 3.7 package afterwards, and everything looks green as far as I can see. Thanks! |
I'm going to close the issue then! Thanks @hroncok for your work on this and getting back to us! |
Fedora updates: The updates will soon be installable from the Sorry for the delay. |
Setuptools v60 and later include a bundled version of distutils, a deprecated standard library scheduled for removal in future versions of Python. Setuptools v60 is only possible to install for Python 3.7 and later. Python has a distutils.sysconfig.get_python_lib() function that returns '/usr/lib/pythonX.Y' on posix systems. RPM-based systems actually use '/usr/lib64/pythonX.Y' instead, so Fedora patches stdlib distutils for Python 3.7 and Python 3.8 to return the correct value. Python 3.9 and later introduce a sys.platlibdir property, which returns the correct value on RPM-based systems. The change to a distutils package not provided by Fedora on Python 3.7 and 3.8 causes a regression in distutils.sysconfig.get_python_lib() that ultimately causes false positives to be emitted by pylint, because it can no longer find the system source libraries. Many Python tools are fairly aggressive about updating setuptools packages, and so even though this package is a fair bit newer than Python 3.7/3.8, it's not entirely unreasonable for a given user to have such a modern package with a fairly old Python interpreter. Updates to Python 3.7 and Python 3.8 are being produced for Fedora which will fix the problem on up-to-date systems. Until then, we can force the loading of platform-provided distutils when running the pylint test. This is the least-invasive yet most comprehensive fix. References: pypa/setuptools#2896 pylint-dev/pylint#5704 pypa/distutils#110 Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20220204221804.2047468-2-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
Setuptools v60 and later include a bundled version of distutils, a deprecated standard library scheduled for removal in future versions of Python. Setuptools v60 is only possible to install for Python 3.7 and later. Python has a distutils.sysconfig.get_python_lib() function that returns '/usr/lib/pythonX.Y' on posix systems. RPM-based systems actually use '/usr/lib64/pythonX.Y' instead, so Fedora patches stdlib distutils for Python 3.7 and Python 3.8 to return the correct value. Python 3.9 and later introduce a sys.platlibdir property, which returns the correct value on RPM-based systems. The change to a distutils package not provided by Fedora on Python 3.7 and 3.8 causes a regression in distutils.sysconfig.get_python_lib() that ultimately causes false positives to be emitted by pylint, because it can no longer find the system source libraries. Many Python tools are fairly aggressive about updating setuptools packages, and so even though this package is a fair bit newer than Python 3.7/3.8, it's not entirely unreasonable for a given user to have such a modern package with a fairly old Python interpreter. Updates to Python 3.7 and Python 3.8 are being produced for Fedora which will fix the problem on up-to-date systems. Until then, we can force the loading of platform-provided distutils when running the pylint test. This is the least-invasive yet most comprehensive fix. References: pypa/setuptools#2896 pylint-dev/pylint#5704 pypa/distutils#110 Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20220204221804.2047468-2-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
Setuptools v60 and later include a bundled version of distutils, a deprecated standard library scheduled for removal in future versions of Python. Setuptools v60 is only possible to install for Python 3.7 and later. Python has a distutils.sysconfig.get_python_lib() function that returns '/usr/lib/pythonX.Y' on posix systems. RPM-based systems actually use '/usr/lib64/pythonX.Y' instead, so Fedora patches stdlib distutils for Python 3.7 and Python 3.8 to return the correct value. Python 3.9 and later introduce a sys.platlibdir property, which returns the correct value on RPM-based systems. The change to a distutils package not provided by Fedora on Python 3.7 and 3.8 causes a regression in distutils.sysconfig.get_python_lib() that ultimately causes false positives to be emitted by pylint, because it can no longer find the system source libraries. Many Python tools are fairly aggressive about updating setuptools packages, and so even though this package is a fair bit newer than Python 3.7/3.8, it's not entirely unreasonable for a given user to have such a modern package with a fairly old Python interpreter. Updates to Python 3.7 and Python 3.8 are being produced for Fedora which will fix the problem on up-to-date systems. Until then, we can force the loading of platform-provided distutils when running the pylint test. This is the least-invasive yet most comprehensive fix. References: pypa/setuptools#2896 pylint-dev/pylint#5704 pypa/distutils#110 Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20220204221804.2047468-2-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
Setuptools v60 and later include a bundled version of distutils, a deprecated standard library scheduled for removal in future versions of Python. Setuptools v60 is only possible to install for Python 3.7 and later. Python has a distutils.sysconfig.get_python_lib() function that returns '/usr/lib/pythonX.Y' on posix systems. RPM-based systems actually use '/usr/lib64/pythonX.Y' instead, so Fedora patches stdlib distutils for Python 3.7 and Python 3.8 to return the correct value. Python 3.9 and later introduce a sys.platlibdir property, which returns the correct value on RPM-based systems. The change to a distutils package not provided by Fedora on Python 3.7 and 3.8 causes a regression in distutils.sysconfig.get_python_lib() that ultimately causes false positives to be emitted by pylint, because it can no longer find the system source libraries. Many Python tools are fairly aggressive about updating setuptools packages, and so even though this package is a fair bit newer than Python 3.7/3.8, it's not entirely unreasonable for a given user to have such a modern package with a fairly old Python interpreter. Updates to Python 3.7 and Python 3.8 are being produced for Fedora which will fix the problem on up-to-date systems. Until then, we can force the loading of platform-provided distutils when running the pylint test. This is the least-invasive yet most comprehensive fix. References: pypa/setuptools#2896 pylint-dev/pylint#5704 pypa/distutils#110 Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20220204221804.2047468-2-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
Bug description
For some reason that I definitely don't understand, if I am using Python 3.7 (3.7.12) and I am running my pylint tests from inside of a venv that simply happens to have setuptools
>=60.0.0
installed, pylint gives me warnings I do not see in any other circumstance:or
or
I see this on pylint versions from as old as
2.8.0
all the way up to2.12.0
.It does not seem to matter what version of setuptools I had on-hand when I installed other packages, merely having this package in the venv appears to change the behavior of pylint.
In fact, uninstalling setuptools from the test venv fixes the problem:
Uhm, can someone please call me an exorcist?
Command used
Pylint output
Expected behavior
I would expect either these errors to show all of the time ... or none of the time. As it stands, I have no idea why they show up when they do, so I can't control CI behavior to accommodate them. I am pursued by phantasms I can neither see nor perceive.
Pylint version
> python3 -m pylint --version pylint 2.12.2 astroid 2.9.3 Python 3.7.12 (default, Sep 6 2021, 13:38:52) [GCC 11.2.1 20210728 (Red Hat 11.2.1-1)]
(Also appears to be a problem in Python 3.8, but not under Python 3.9 or Python 3.10.)
OS / Environment
The text was updated successfully, but these errors were encountered: