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

Remove bundled setuptools #95299

Closed
sbidoul opened this issue Jul 26, 2022 · 9 comments
Closed

Remove bundled setuptools #95299

sbidoul opened this issue Jul 26, 2022 · 9 comments
Labels
3.12 bugs and security fixes topic-ensurepip type-feature A feature request or enhancement

Comments

@sbidoul
Copy link
Contributor

sbidoul commented Jul 26, 2022

Feature or enhancement

Remove the bundled setuptools so that ensurepip and python -m venv only installs pip.

Context

The setup.py install command of setuptools is deprecated.

However, in an environment where setuptools is installed but wheel is not (such as one created with python -m venv), pip falls back on running the deprecated and non-standard setup.py install.

Since version 22.1 pip works correctly by default in environments where setuptools is not installed, by enabling its PEP 517 mode automatically, leading to unsurprising installations in most cases.

So, in order to progressively expose more users to standard-based installation workflows, we (the pip team) would like that virtual environments are created without setuptools by default.

Users faced with failing installations following this change (likely due to packages with customized setup.py that do not support building a wheel) can easily pip install setuptools to solve the issue.

Previous discussion

pypa/pip#8102 (comment) and following comments has some more context.

Linked PRs

@sbidoul sbidoul added the type-feature A feature request or enhancement label Jul 26, 2022
@sbidoul
Copy link
Contributor Author

sbidoul commented Jul 26, 2022

@pablogsal do you think it is still acceptable to do this in 3.11? If positive we can likely land a PR on time for RC1.

@pablogsal
Copy link
Member

Unfortunately I don't feel comfortable landing this so late in the release cycle, specially so close to RC1 and given the current stability of 3.11 :(

This will need to wait until 3.12.

@rafrafek
Copy link

rafrafek commented Nov 7, 2022

It feels strange that setuptools is included when using -m venv, but wheel is not included.

@pradyunsg
Copy link
Member

I've filed #101039 for this (almost had a number with three 0s), targetting 3.12.

@edmorley
Copy link

Since version 22.1 pip works correctly by default in environments where setuptools is not installed, by enabling its PEP 517 mode automatically, leading to unsurprising installations in most cases.

Do you have some examples of cases where the PEP 517 mode doesn't work for legacy packages? :-)

@FFY00
Copy link
Member

FFY00 commented Mar 4, 2023

PEP 517 is backwards compatible, it should work on legacy packages, the opposite is the issue, pip trying to use the legacy path for packages that need PEP 517.

pradyunsg added a commit to pradyunsg/cpython that referenced this issue Apr 6, 2023
pradyunsg added a commit to pradyunsg/cpython that referenced this issue Apr 9, 2023
# This is the 1st commit message:

pythongh-95299: Rework test_cppext.py to not invoke setup.py directly

# This is the commit message #2:

Add tests/cppextdata data to `TESTSUBDIRS`

# This is the commit message #3:

Revert "Add tests/cppextdata data to `TESTSUBDIRS`"

This reverts commit 635492e.
pradyunsg added a commit that referenced this issue Apr 13, 2023
)

* gh-95299: Rework test_cppext.py to not invoke setup.py directly

* Add tests/cppextdata data to `TESTSUBDIRS`

* Revert "Add tests/cppextdata data to `TESTSUBDIRS`"

This reverts commit 635492e.

* Revert "gh-95299: Rework test_cppext.py to not invoke setup.py directly"

This reverts commit 41c5a66.

* Build and install the extension in a temporary directory instead

* Pull in wheels for setuptools and wheel for testing extension builds
carljm added a commit to carljm/cpython that referenced this issue Apr 13, 2023
* main:
  pythongh-103479: [Enum] require __new__ to be considered a data type (pythonGH-103495)
  pythongh-103365: [Enum] STRICT boundary corrections (pythonGH-103494)
  pythonGH-103488: Use return-offset, not yield-offset. (pythonGH-103502)
  pythongh-103088: Fix test_venv error message to avoid bytes/str warning (pythonGH-103500)
  pythonGH-103082: Turn on branch events for FOR_ITER instructions. (python#103507)
  pythongh-102978: Fix mock.patch function signatures for class and staticmethod decorators (python#103228)
  pythongh-103462: Ensure SelectorSocketTransport.writelines registers a writer when data is still pending (python#103463)
  pythongh-95299: Rework test_cppext.py to not invoke setup.py directly (python#103316)
pradyunsg added a commit that referenced this issue Apr 18, 2023
…101039)

Remove the bundled setuptools wheel from ensurepip, and stop installing setuptools in environments created by venv.

Co-Authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: C.A.M. Gerlach <[email protected]>
Co-authored-by: Oleg Iarygin <[email protected]>
@pradyunsg
Copy link
Member

https://docs.python.org/3.12/library/venv.html#an-example-of-extending-envbuilder is the final piece of work here -- that example needs to be updated to use something more modern or otherwise behave differently to showcase extending behaviours of the class.

aisk pushed a commit to aisk/cpython that referenced this issue Apr 18, 2023
…python#103316)

* pythongh-95299: Rework test_cppext.py to not invoke setup.py directly

* Add tests/cppextdata data to `TESTSUBDIRS`

* Revert "Add tests/cppextdata data to `TESTSUBDIRS`"

This reverts commit 635492e.

* Revert "pythongh-95299: Rework test_cppext.py to not invoke setup.py directly"

This reverts commit 41c5a66.

* Build and install the extension in a temporary directory instead

* Pull in wheels for setuptools and wheel for testing extension builds
zooba added a commit to zooba/cpython that referenced this issue Apr 18, 2023
carljm added a commit to carljm/cpython that referenced this issue Apr 20, 2023
* main: (24 commits)
  pythongh-98040: Move the Single-Phase Init Tests Out of test_imp (pythongh-102561)
  pythongh-83861: Fix datetime.astimezone() method (pythonGH-101545)
  pythongh-102856: Clean some of the PEP 701 tokenizer implementation (python#103634)
  pythongh-102856: Skip test_mismatched_parens in WASI builds (python#103633)
  pythongh-102856: Initial implementation of PEP 701 (python#102855)
  pythongh-103583: Add ref. dependency between multibytecodec modules (python#103589)
  pythongh-83004: Harden msvcrt further (python#103420)
  pythonGH-88342: clarify that `asyncio.as_completed` accepts generators yielding tasks (python#103626)
  pythongh-102778: IDLE - make sys.last_exc available in Shell after traceback (python#103314)
  pythongh-103582: Remove last references to `argparse.REMAINDER` from docs (python#103586)
  pythongh-103583: Always pass multibyte codec structs as const (python#103588)
  pythongh-103617: Fix compiler warning in _iomodule.c (python#103618)
  pythongh-103596: [Enum] do not shadow mixed-in methods/attributes (pythonGH-103600)
  pythonGH-100530: Change the error message for non-class class patterns (pythonGH-103576)
  pythongh-95299: Remove lingering setuptools reference in installer scripts (pythonGH-103613)
  [Doc] Fix a typo in optparse.rst (python#103504)
  pythongh-101100: Fix broken reference `__format__` in `string.rst` (python#103531)
  pythongh-95299: Stop installing setuptools as a part of ensurepip and venv (python#101039)
  pythonGH-103484: Docs: add linkcheck allowed redirects entries for most cases (python#103569)
  pythongh-67230: update whatsnew note for csv changes (python#103598)
  ...
jirimoravcik added a commit to apify/apify-shared-python that referenced this issue Jul 4, 2024
This PR fixes GitHub actions for unit tests by adding setuptools as they
are not pre-installed anymore.
python/cpython#95299
openstack-mirroring pushed a commit to openstack/openstack that referenced this issue Jul 10, 2024
* Update swift from branch 'master'
  to 9c38d756e0233eaa5f9e26066756eea9ce6a11ad
  - Merge "Use entry_points for server executables"
  - Use entry_points for server executables
    
    The old [files]scripts method of specifying executable Python scripts
    triggers some legacy easy-install-like mode for editable installs,
    which relies on pkg_resources. Recent versions of setuptools (67.5.0+)
    have started emitting warnings when importing pkg_resources, which in
    turn cause quite noticeable slowdowns in process startup. This is
    particularly prominant on py312, which stopped pre-installing (an often
    older version of) setuptools in new venvs.
    
    See also:
     - python/cpython#95299
     - pypa/setuptools#3843
     - pypa/setuptools#3966
    
    Now, use [entry_points]console_scripts to specify these executables,
    which does not use pkg_resources in the generated script files.
    
    Change-Id: Ifcc8138e7b55d5b82bea0d411ec6bfcca2c77c83
openstack-mirroring pushed a commit to openstack/swift that referenced this issue Jul 10, 2024
The old [files]scripts method of specifying executable Python scripts
triggers some legacy easy-install-like mode for editable installs,
which relies on pkg_resources. Recent versions of setuptools (67.5.0+)
have started emitting warnings when importing pkg_resources, which in
turn cause quite noticeable slowdowns in process startup. This is
particularly prominant on py312, which stopped pre-installing (an often
older version of) setuptools in new venvs.

See also:
 - python/cpython#95299
 - pypa/setuptools#3843
 - pypa/setuptools#3966

Now, use [entry_points]console_scripts to specify these executables,
which does not use pkg_resources in the generated script files.

Change-Id: Ifcc8138e7b55d5b82bea0d411ec6bfcca2c77c83
smoser added a commit to wolfi-dev/os that referenced this issue Aug 8, 2024
This does:
1. update python-3.12 to 3.12.5 which released yesterday
2. Replace the bundled wheels of pip and setuptools that
   are found in python with dependencies on 
   * py3-pip-wheel for python 3.10, 3.11, 3.12
   * py3-setuptools-wheel for python 3.10, 3.11
3. Add tests running 'python -m venv' and
   'pip check' to make sure that the included versions are
   supported with the used python.
4. compile python with `--with-wheel-pkg-dir=/usr/share/python-wheels`.
   This enables ensurepip to find the wheels added in 2.

Things to note:
* python3.12 no longer has setuptools included
  python/cpython#95299

---------

Co-authored-by: Dimitri John Ledkov <[email protected]>
github-merge-queue bot pushed a commit to grafana/oncall that referenced this issue Aug 9, 2024
# What this PR does

_tldr;_ I think we should install `setuptools` into our engine
`Dockerfile` + in our CI env because Python 3.12 no longer installs
`distutils` by default. This should unblock us from being able to merge
#4656 and #4555.

**More details**

I would like to be able to merge #4656 and #4555. _However_, in both of
these PRs `setuptools` is being removed from `requirements-dev.txt`
([here](https://github.com/grafana/oncall/pull/4555/files#diff-d8146d0816a943b0fa69a20399d7bbdb58e1c84c8b7933b2ba6dea7c10c410f5L113-L116)
and
[here](https://github.com/grafana/oncall/pull/4656/files#diff-d8146d0816a943b0fa69a20399d7bbdb58e1c84c8b7933b2ba6dea7c10c410f5L113-L116)).
This leads to things breaking because of:
```bash
File "/opt/hostedtoolcache/Python/3.12.3/x64/lib/python3.12/site-packages/polymorphic/__init__.py", line 9, in <module>
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'
```

-
https://github.com/grafana/oncall/actions/runs/9865348392/job/27242117474?pr=4555#step:5:98
-
https://github.com/grafana/oncall/actions/runs/10078898966/job/27864920455?pr=4656#step:5:100

Python 3.12 made a change to no longer pre-install `distutils`
([relevant release
notes](https://docs.python.org/3/whatsnew/3.12.html#:~:text=The%20third%2Dparty%20Setuptools%20package%20continues%20to%20provide%20distutils%2C%20if%20you%20still%20require%20it%20in%20Python%203.12%20and%20beyond)):
> [PEP 632](https://peps.python.org/pep-0632/): Remove the distutils
package. See [the migration
guide](https://peps.python.org/pep-0632/#migration-advice) for advice
replacing the APIs it provided. The third-party
[Setuptools](https://setuptools.pypa.io/en/latest/deprecated/distutils-legacy.html)
package continues to provide distutils, if you still require it in
Python 3.12 and beyond.
>
> [gh-95299](python/cpython#95299): Do not
pre-install setuptools in virtual environments created with
[venv](https://docs.python.org/3/library/venv.html#module-venv). This
means that distutils, setuptools, pkg_resources, and easy_install will
no longer available by default; to access these run pip install
setuptools in the
[activated](https://docs.python.org/3/library/venv.html#venv-explanation)
virtual environment.

Additionally, `setuptools` is in `pip-tools` `UNSAFE_PACKAGES` list
([related GitHub
issue](pypa/pipenv#1417 (comment))),
hence why I think Dependabot is removing it in #4656 and #4555.

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
edmorley added a commit to edmorley/python-build-standalone that referenced this issue Aug 24, 2024
For parity with the `ensurepip` and `venv` modules, which no
longer install setuptools as of Python 3.12:
- python/cpython#95299
- python/cpython@ece20db

Fixes indygreg#300.
edmorley added a commit to edmorley/python-build-standalone that referenced this issue Sep 7, 2024
For parity with the `ensurepip` and `venv` modules, which no
longer install setuptools as of Python 3.12:
- python/cpython#95299
- python/cpython@ece20db

Fixes indygreg#300.
zanieb pushed a commit to indygreg/python-build-standalone that referenced this issue Sep 9, 2024
For parity with the `ensurepip` and `venv` modules, which no
longer install setuptools as of Python 3.12:
- python/cpython#95299
- python/cpython@ece20db

Fixes #300.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes topic-ensurepip type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

8 participants