Skip to content

components: add pip repo for Python distributions - #167

Open
yeetypete wants to merge 6 commits into
coreos:mainfrom
yeetypete:feat/pip-backend
Open

yeetypete wants to merge 6 commits into
coreos:mainfrom
yeetypete:feat/pip-backend

Conversation

@yeetypete

Copy link
Copy Markdown

Add a component repo for Python distributions installed by pip, uv, or any other installer following the "Recording installed projects" specification (PEP 376).

chunkah is pretty nice for Python-heavy images. Any ML/CUDA venvs can get to be 10s of gigs in size 😅. The classic workaround is to manually split the installation into separate RUN commands so large dependencies land in their own layers (see astral-sh/uv#16113 and astral-sh/uv#7712). With this, each distribution becomes its own component and layers can be reused across updates regardless of how the image was built.

How it works:

  • Files listed in RECORD are strongly claimed, along with their parent directories up to site-packages. Directories shared between distributions end up in each component's layer, as with the other repos.
  • Names are normalized per PEP 503, so Foo_Pkg-1.2.3.dist-info becomes pip/foo-pkg.
  • Bytecode compiled after installation (not in RECORD, e.g. by uv's --compile-bytecode) is claimed for the component owning the corresponding .py.
  • Distributions vendored inside another one (e.g. setuptools/_vendor, see Stop vendoring packages pypa/setuptools#2825) belong to the outer distribution.
  • We set the PipRepo priority below distro package managers so Python packages installed by the distro package manager stay with the distro package.
  • PyPI packages don't have any changelog data. We assume a fixed 30-day update interval for stability.

Assisted-by: AI

Signed-off-by: Peter Siegel <psiegel2000@icloud.com>
Add a component repo for Python distributions installed by pip, uv, or
any other installer following the "Recording installed projects" spec.
Distributions are discovered via their `*.dist-info/RECORD` files
anywhere in the rootfs, so this covers system site-packages as well as
virtualenvs. Files listed in RECORD are strongly claimed, along with
their parent directories up to site-packages. Bytecode compiled after
installation (not in RECORD) is claimed for the component owning the
corresponding source file.

The repo is below distro package managers in priority so that Python
packages installed by the distro package manager stay with their distro
package.

Assisted-by: AI
Signed-off-by: Peter Siegel <psiegel2000@icloud.com>
Install packages with pip into system site-packages and with uv into a
venv, and check that they become pip components while rpm-installed
Python packages stay with rpm. Covers bytecode both recorded in RECORD
(pip) and not (uv --compile-bytecode).

Assisted-by: AI
Signed-off-by: Peter Siegel <psiegel2000@icloud.com>
Signed-off-by: Peter Siegel <psiegel2000@icloud.com>
…-importable filenames which contain dots

Signed-off-by: Peter Siegel <psiegel2000@icloud.com>
Some distributions vendor their dependencies as complete installs, with
their own dist-info and RECORD nested inside the outer package (e.g.
setuptools/_vendor, see pypa/setuptools#2825).
Process dist-infos outermost first and skip any whose RECORD is already
claimed, so vendored copies belong to the outer distribution.

Assisted-by: AI
Signed-off-by: Peter Siegel <psiegel2000@icloud.com>
@yeetypete

Copy link
Copy Markdown
Author

@jlebon if you have a chance to take a look that would be great! I think this could be a big win for people doing ML stuff with lage Python wheels + using containerization :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant