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

PEP 632: Rename the distutils package to _distutils #92584

Open
vstinner opened this issue May 9, 2022 · 11 comments
Open

PEP 632: Rename the distutils package to _distutils #92584

vstinner opened this issue May 9, 2022 · 11 comments
Labels
type-bug

Comments

@vstinner
Copy link
Member

@vstinner vstinner commented May 9, 2022

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:

  • Build C extensions which can not be built by Makefile yet. Python 3.11 can build way more C extensions with Makefile than Python 3.10.
  • peg_generator uses distutils to build C extensions.
  • test_cppext uses distutils to check that the Python C API can be used in C++.
  • 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 th Lib/distutils/ directory to Lib/_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-L12

I created the PR #92585 which renames distutils to _distutils.

@vstinner vstinner added the type-bug label May 9, 2022
vstinner added a commit to vstinner/cpython that referenced this issue May 9, 2022
Rename Lib/distutils/ directory to Lib/_distutils/.
@vstinner vstinner changed the title Remove the distutils package to _distutils Rename the distutils package to _distutils May 9, 2022
@vstinner
Copy link
Member Author

@vstinner vstinner commented May 9, 2022

Right now, test_venv fails without distutils, because pip fails on importing the distutils module in pip/_internal/locations/_distutils.py

I reported this issue to pip: pypa/pip#11103

@vstinner
Copy link
Member Author

@vstinner vstinner commented May 9, 2022

The distutils package was deprecated by the issue #85454.

@vstinner vstinner changed the title Rename the distutils package to _distutils PEP 632: Rename the distutils package to _distutils May 10, 2022
@vstinner
Copy link
Member Author

@vstinner vstinner commented May 10, 2022

PEP 632 "Deprecate distutils module": https://peps.python.org/pep-0632/

@FFY00
Copy link
Member

@FFY00 FFY00 commented May 10, 2022

That seems like a good plan. Thanks.

@jaraco
Copy link
Member

@jaraco jaraco commented May 10, 2022

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.

@vstinner
Copy link
Member Author

@vstinner vstinner commented May 10, 2022

Why not address the dependencies and fully remove the functionality?

Someone has to modify Python to no longer depend on distutils. The issue description lists code using it. It doesn't seem trivial.

@FFY00
Copy link
Member

@FFY00 FFY00 commented May 10, 2022

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?

@vstinner
Copy link
Member Author

@vstinner vstinner commented May 10, 2022

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 Lib/_distutils/ directory is not installed by make install.

@jkloth
Copy link
Contributor

@jkloth jkloth commented May 10, 2022

Do note that we have buildbots that run from an installed Python. The tests would need to also be modified to fail gracefully
(or skip) when _distutils is not available.

@vstinner
Copy link
Member Author

@vstinner vstinner commented May 10, 2022

Do note that we have buildbots that run from an installed Python. The tests would need to also be modified to fail gracefully (or skip) when _distutils is not available.

I propose skipping tests relying on _distutils if _distutils is not available.

vstinner added a commit to vstinner/cpython that referenced this issue May 10, 2022
Rewrite test_cppext to run in a virtual environment and to build the
C++ extension with setuptools rather than distutils.
vstinner added a commit to vstinner/cpython that referenced this issue May 10, 2022
test_decimal now uses shutil.which() rather than deprecated
distutils.spawn.find_executable().
@vstinner
Copy link
Member Author

@vstinner vstinner commented May 10, 2022

I wrote two PRs to avoid the deprecated distutils module in two tests:

  • #92639: test_cppext uses setuptools
  • #92640: test_decimal uses shutil.which() -- IMO an uncontroversial change

vstinner added a commit that referenced this issue May 10, 2022
test_decimal now uses shutil.which() rather than deprecated
distutils.spawn.find_executable().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug
Projects
None yet
Development

No branches or pull requests

4 participants