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
PEP 632: Remove the distutils package (Python 3.12) #92584
Comments
I reported this issue to pip: pypa/pip#11103 |
The distutils package was deprecated by the issue #85454. |
PEP 632 "Deprecate distutils module": https://peps.python.org/pep-0632/ |
That seems like a good plan. Thanks. |
My fear with renaming it is that it lingers indefinitely, and diverging in subtle ways from pypa/distutils. Why not address the dependencies and fully remove the functionality? Regardless, I agree renaming is preferable to not removing the module at all. |
Someone has to modify Python to no longer depend on distutils. The issue description lists code using it. It doesn't seem trivial. |
Would it be reasonable to keep it around in the repo while we don't drop the dependency but not ship it as part of Python installations? |
With my PR, the |
Do note that we have buildbots that run from an installed Python. The tests would need to also be modified to fail gracefully |
I propose skipping tests relying on _distutils if _distutils is not available. |
I wrote two PRs to avoid the deprecated distutils module in two tests:
|
test_decimal now uses shutil.which() rather than deprecated distutils.spawn.find_executable().
Rewrite test_cppext to run in a virtual environment and to build the C++ extension with setuptools rather than distutils.
Marking as 3.12.0a1 release blocker. We want to have public-facing distutils gone in the first alpha, to have as much time as possible to deal with the fallout. |
Actually we can get rid of distutils entirely. I have a working PR that gets rid of our |
`make test_cppmods` compiles C++ test extension modules.
Remove the distutils package. It was deprecated in Python 3.10 by PEP 632 "Deprecate distutils module". For projects still using distutils and cannot be updated to something else, the setuptools project can be installed: it still provides distutils. * Remove Lib/distutils/ directory * Remove test_distutils * Remove references to distutils * Skip test_check_c_globals and test_peg_generator since they use distutils
Python 3.12 alpha 2 was released without distutils. test_check_c_globals and test_peg_generator are currently skipped because of this removal. These tests should be rewritten without distutils. |
distutils.sysconfig.get_config_var('SO') was deprecated in python 3.4, and is unset in python 3.11.0. Causes PYTHON3_SO=None -> _RNA.so builds as "_RNANone" -> build failure: ``` ImportError: cannot import name '_RNA' from partially initialized module 'RNA' ``` See: python/cpython#60958, python/cpython#63754 and [deprecation notice here](https://github.com/python/cpython/blob/dd53b79de0ea98af6a11481217a961daef4e9774/Doc/whatsnew/3.4.rst#deprecations-in-the-python-api). Further, module [distutils](https://docs.python.org/3/library/distutils.html) is deprecated, and has planned removal in 3.12. Functions get_python_inc, get_python_lib are removed, see: python/cpython#92584.
distutils.sysconfig.get_config_var('SO') was deprecated in python 3.4, and is unset in python 3.11.0. Causes PYTHON3_SO=None -> _RNA.so builds as "_RNANone" -> build failure: ``` ImportError: cannot import name '_RNA' from partially initialized module 'RNA' ``` See: python/cpython#60958, python/cpython#63754 and [deprecation notice here](https://github.com/python/cpython/blob/dd53b79de0ea98af6a11481217a961daef4e9774/Doc/whatsnew/3.4.rst#deprecations-in-the-python-api). Also, module [distutils](https://docs.python.org/3/library/distutils.html) is deprecated and has planned removal in 3.12. Functions get_python_inc, get_python_lib are removed, see: python/cpython#92584.
@ericsnowcurrently: FYI test_check_c_globals is simply skipped in the main branch, since the distutils package was removed. This test should be modified to use something else to build C code, like setuptools, or simply create a virtual environment to get the distutils packages from setuptools: trick used by test_cppext. @pablogsal @lysnikolaou: test_peg_generator has the same issue, the whole test is also simply skipped in the main branch. |
You may create new issues for these two currently skipped tests. As you want. |
What do you mean is skipped? I don't feel comfortable with just skipping this test without thinking how to fix it. I think this aspect should have taken into account when merging the original PR. @vstinner I am sure you understand that is not good to just do something without thinking how to fix the problems you are creating and then throwing the issue to someone else. |
To me it looks like IMO, PEP 632 underestimated the amount of work needed, and failed to mention that no one was really interested in actually implementing it. (AFAIK we have an implicit assumption that a PEP author will manage the work if the PEP is accepted, we might want to add that to the PEP process docs.) Thanks for picking up the slack at the last moment, Victor. |
I was under the impression that the plan was to have distutils outside the standard library but available until we figure out what to do with the tests that depend on it. The PEP suggests this as well:
Using alternatives within the test suite of CPython differs from using alternatives outside because installing packages like pip and setuptools is not that straightforward. If this was the plan all along and I was under the wrong impression I apologize for the confusion but I still think having tests deactivated in |
Reverting the removal would be some churn, but there are other options:
|
FWIW, test_check_c_globals basically covers Tools/c-analyzer/check-c-globals.py. We shouldn't be losing any coverage of CPython with that test disabled. Plus, there are a few things that need to be fixed with that test that I'd been putting off. It having been disabled is an extra motivator. That said, I agree it is surprising that we merged something requiring any tests to be disabled and then fixed after the fact by someone other than the author of that PR. At the very least there should have been some discussion beforehand with the maintainers of the to-be-disabled tests and a clear agreement on how to proceed, all before the PR was merged. While what happened with distutils may seem relatively benign and innocuous, it's a risky precedent to set. |
There was an explicit agreement that the author of this PEP (me) was just putting it in writing and wasn't obligated to do all the work. But feel free to make that an explicit requirement - it just means that I won't volunteer for PEPs that we all want but nobody is willing to do (and will simply withdraw from maintaining the module that we all want to remove) ;) But yes, I agree that breaking/disabling the tests is not right. Moving |
Is distutils required to build the docs? I see uses of it in Doc/includes/setup.py and Doc/includes/test.py. Also, I'm taking care of gh-100237 (c-analyzer) via gh-102506. However, separately I'm vendoring a subset of the [reverted] distutils code under Tools/c-analyzer, in gh-102505. However, we also need distutils for Tools/peg_generator/pegen/build.py (and possibly for the docs). So it may make sense to vendor distutils in one common place (or use some other mechanism, e.g. pip install in a venv, that the reliant tools can share). |
Doc builds already rely on a venv with packages from PyPI, so making them use/assume setuptools should be okay. If we were to vendor it, I'd prefer we just vendor https://github.com/pypa/distutils directly under |
As far as I can tell via |
Turns out that the other files ( |
…2505) distutils was removed in November. However, the c-analyzer relies on it. To solve that here, we vendor the parts the tool needs so it can be run against 3.12+. (Also see gh-92584.) Note that we may end up removing this code later in favor of a solution in common with the peg_generator tool (which also relies on distutils). At the least, the copy here makes sure the c-analyzer tool works on 3.12+ in the meantime.
My PR clearly says that it skips 2 tests. It was approved by @zware. As I wrote previously, my plan was to run test_check_c_globals and test_peg_generator in a venv so distutils is provided by setuptools installed in the venv. In the meanwhile, I got catched by more urgent issues and I didn't find time to update these two tests. Removing distutils is a significant change in Python 3.12 and it's better to do it as soon as possible to give users more time to prepare their project for this change planned for a long time (PEP 632) before Python 3.12 final release. Just in Fedora, there are already at least 250 packages known to be affected by this change! Fixing the whole ecosystem for this change is tricky, there are many glitches, like this setuptools bug.
I got a burnout for 3 months. I warned you and Eric before leaving so someone else can handle the issue. There are still 6 months until Python 3.12 final version to decide how to fix the issue: add again distutils or update the 2 tests. |
Is there a reason or a technical issue which prevents to run whole test_check_c_globals and test_peg_generator files in a separated process running in a venv? We already have many tests which fully run in a child process for various reasons (usually to be "isolated", run in a controlled environment, and fully reset side effects when tests complete). Just two examples: test_atexit and test_eintr. |
This is still marked as a release blocker, so I decided to take a look. I am not familiar with the distutils situation, but I can see the following concrete issues:
We can probably afford to release the next beta without further changes here, but definitely the docs should be updated before 3.12 final. |
The distutils module was deprecated in Python 3.10 and is scheduled for removal in Python 3.12.
Right now, Python still uses distutils for different purpose:
Tools/c-analyzer/
uses distutils to get a C preprocessor.Until Python can be built and used without distutils, I propose to first rename the
distutils
package to_distutils
: rename thLib/distutils/
directory toLib/_distutils/
.Right now, test_venv fails without distutils, because pip fails on importing the distutils module in
pip/_internal/locations/_distutils.py
: https://github.com/pypa/pip/blob/cb24fb4052ca8ab8009866b0de61980c81a7e13c/src/pip/_internal/locations/_distutils.py#L9-L12I created the PR #92585 which renames distutils to _distutils.
The text was updated successfully, but these errors were encountered: