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

Stop installing setuptools and wheel #243

Merged
merged 1 commit into from
Aug 7, 2024
Merged

Stop installing setuptools and wheel #243

merged 1 commit into from
Aug 7, 2024

Conversation

edmorley
Copy link
Member

@edmorley edmorley commented Aug 7, 2024

Currently the buildpack performs a system site-packages install of not only pip, but also setuptools and wheel. This has historically been necessary for pip to be able to build source distributions (sdists) for packages that don't ship with compatible wheels.

However:

  • Thanks to PEP 517 / PEP 518, packages can now (and many already do) specify an explicit build backend using [build-system] in their pyproject.toml. The dependencies specified in that config (such as setuptools and wheel) will be installed by pip into an isolated and ephemeral build environment as part of the source distribution build process. Such packages therefore don't need/use globally installed setuptools/wheel versions.
  • As of pip v22.1, pip will now default to the isolated build environment mode (along with a fallback legacy setuptools build backend), if the setuptools package isn't installed globally. This means that packages that haven't yet migrated to a PEP 517/518 pyproject.toml build backend config can still build even if setuptools isn't installed globally. (There are a small number of rarely used packages in the wild that aren't compatible with build isolation mode, however, these typically require more build dependencies than just setuptools, which means they wouldn't have worked with this buildpack anyway.)

As such, it's no longer necessary for us to install setuptools and wheel globally - and removing their install means we'll match the behaviour of the venv and ensurepip modules in Python 3.12+, where setuptools and wheel installation has also been removed.

In addition, these packages will no longer be accessible by app dependencies after the upcoming switch to venvs (see #253), so there is no point continuing to install them in the user site-packages directory.

This change also improves parity with the default behaviour of Poetry too, whose install --sync command removes any implicitly installed packages in the current environment (other than pip).

See:

GUS-W-16437776.

@edmorley edmorley self-assigned this Aug 7, 2024
@edmorley edmorley marked this pull request as ready for review August 7, 2024 14:39
@edmorley edmorley requested a review from a team as a code owner August 7, 2024 14:39
Base automatically changed from pip-capitalisation to main August 7, 2024 16:18
Currently the buildpack performs a system site-packages install of not
only pip, but also setuptools and wheel. This has historically been
necessary for pip to be able to build source distributions (sdists) for
packages that don't ship with compatible wheels.

However:
- Thanks to PEP 518, packages can now (and many already do) specify an
  explicit build backend using `[build-system]` in their
  `pyproject.toml`. The dependencies specified in that config (such as
  setuptools and wheel) will be installed by pip into an isolated and
  ephemeral build environment as part of the source distribution build
  process. Such packages therefore don't need/use globally installed
  setuptools/wheel versions.
- As of pip v22.1, pip will now default to the isolated build environment
  mode (along with a fallback legacy setuptools build backend), if the
  setuptools package isn't installed globally. This means that packages
  that haven't yet migrated to a PEP 518 `pyproject.toml` build backend
  config can still build even if setuptools isn't installed globally.

There are a small number of rarely used packages in the wild that
aren't compatible with build isolation mode, however, these typically
require more build dependencies than just setuptools, which means they
wouldn't have worked with this buildpack anyway.

As such, it's no longer necessary for us to install setuptools and wheel
globally. This matches the behaviour of the `venv` and `ensurepip` modules
in Python 3.12+, where setuptools and wheel installation has also been
removed. And it also matches the default behaviour of Poetry too, whose
`install --sync` command removes any implicitly installed packages in the
current environment (other than pip).

See:
https://peps.python.org/pep-0518/
https://pip.pypa.io/en/stable/reference/build-system/
https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/#build-isolation
pypa/pip#10717
python/cpython#101039
pypa/get-pip#218
astral-sh/uv#2252

GUS-W-16437776.
@edmorley edmorley enabled auto-merge (squash) August 7, 2024 16:21
@edmorley edmorley merged commit 20c1272 into main Aug 7, 2024
7 checks passed
@edmorley edmorley deleted the rm-setuptools-wheel branch August 7, 2024 16:22
heroku-linguist bot added a commit to heroku/cnb-builder-images that referenced this pull request Aug 7, 2024
## heroku/python

### Removed

- Stopped explicitly installing setuptools and wheel. They will be automatically installed by pip into an isolated build environment if they are required for building a package. ([#243](heroku/buildpacks-python#243))

Co-authored-by: heroku-linguist[bot] <136119646+heroku-linguist[bot]@users.noreply.github.com>
edmorley added a commit to heroku/heroku-buildpack-python that referenced this pull request Oct 10, 2024
Add support for Python 3.13, and release 3.13.0.

The default Python version remains unchanged (at 3.12.x) for now.

Notably for Python 3.13 we now:
- No longer install setuptools and wheel - matching what the wider
  ecosystem has already done for Python 3.12+.
  (See the Python CNB's removal PR for more details:
  heroku/buildpacks-python#243)
- No longer install the SQLite headers and CLI, as the first step
  towards dropping that rarely used feature.
- Have to disable some of the tests that run during the PGO profiling
  phase when on Heroku-22 (see PR comments for more details).

In addition, for all Python versions we now also remove the `idle3`
and `pydoc3` scripts, since they do not work with relocated Python
and so have been broken for some time. Their functionality continues
to be available by invoking them via their modules instead (e.g.
`python -m pydoc`).

Release announcement:
https://blog.python.org/2024/10/python-3130-final-released.html
https://www.python.org/downloads/release/python-3130/

Details on what's new in Python 3.13:
https://docs.python.org/3.13/whatsnew/3.13.html

Binary builds:
https://github.com/heroku/heroku-buildpack-python/actions/runs/11280580537

Python 3.13 readiness status of the top 360 packages on PyPI:
https://pyreadiness.org/3.13/

GUS-W-14846826.
GUS-W-14846839.
GUS-W-16944574.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants