Library recipes: run a recipe's steps with a minimal environment, not the build container's

Aperta
#48 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
52/100
Tipo di issue
Refactoring
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
github-actions, python

Direzione di ricerca

Start with build_env() and the subprocess.run call in build_libraries() in scripts/gap_wheels.py, then check scripts/container_build.sh for the image's PATH. Add a library_env(prefix) for recipe steps only, and leave Windows on the old path with a comment. Done when tests/test_gap_wheels.py shows that CFLAGS, MAKEFLAGS and LD_LIBRARY_PATH set in the test's os.environ never reach a recipe step, and the PyYAML pair still builds to the same sha256.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement help wanted

A recipe's build steps are fixed argument lists, so that nothing outside the reviewed recipe decides how the library is built. But each step runs with the whole environment of the process that started it:

# scripts/gap_wheels.py
def build_env() -> dict[str, str]:
    env = dict(os.environ, PIP_DISABLE_PIP_VERSION_CHECK="1", PIP_NO_INPUT="1", SOURCE_DATE_EPOCH="1700000000",
               PYTHONHASHSEED="0")
...
# build_libraries()
done = subprocess.run(argv, cwd=src, check=False, env=build_env(), ...)

./configure and make read a lot from the environment: CC, CFLAGS, LDFLAGS, CPPFLAGS, MAKEFLAGS, PKG_CONFIG_PATH, LD_LIBRARY_PATH, LANG, TZ, HOME, USER. Whatever the image, the runner or the workflow sets for any of them goes into the library, and none of it is in the recipe's sha256 (digest() in scripts/library_recipes.py covers the recipe's own fields only). An image update that starts exporting CFLAGS=-g, or a workflow edit that sets MAKEFLAGS, changes the library while the recorded recipe digest stays the same. The two builds of a pair would still match each other, so nothing would notice.

The README promises more than that: "built with the recipe's steps, which are argument lists in this repo (no shell, nothing from the package or from a workflow input)".

Where

scripts/gap_wheels.py: build_env() and the subprocess.run in build_libraries(). The package's own build (run_build()) is a different question and out of scope here.

What to do

  • Add library_env(prefix) and use it for recipe steps only. Start from an empty dict and set a short fixed list:
    • PATH: on Linux the image's standard one, written out (/usr/local/bin:/usr/bin:/bin, plus the manylinux toolchain's folder if the image's compiler lives outside those; check scripts/container_build.sh and the image);
    • HOME and TMPDIR: folders under the build's work folder;
    • LANG=C.UTF-8, LC_ALL=C.UTF-8, TZ=UTC;
    • SOURCE_DATE_EPOCH, as build_env() sets it.
  • On Windows nothing has a recipe yet. MSVC needs its own variables (INCLUDE, LIB, Path from the developer environment), so for now keep build_env() there and say so in a comment, or pass through a named allowlist. Don't break the Windows path for a future recipe.
  • Record the environment's variable names and values in the recipe record or the build's tool provenance, so a change to the list is a visible change. If that touches RECORD_KEYS or the manifest's shape, describe it in the PR first: verification compares these records between builds.
  • A recipe that needs a variable sets it in its own step arguments (CFLAGS=-O2 -fPIC is already an argument to ./configure in the libyaml recipe), which is inside the digest.

Done when:

  • A test in tests/test_gap_wheels.py runs build_libraries() with a recipe whose one step prints its environment to a file under the prefix (the existing build_libraries() tests, around gap_wheels.build_libraries([recipe], tmp / "work", tmp / "root"), show how to give it a small recipe), with CFLAGS, MAKEFLAGS and LD_LIBRARY_PATH set in the test's own os.environ, and shows none of them reach the step.
  • A test pins the exact set of variable names a Linux step gets.
  • The PyYAML pair still builds twice to the same sha256 with the change: the PR links two gap-wheel-build.yml runs from your fork.
  • The README's "In the build" paragraph says the steps get a fixed environment.
  • uvx --python 3.14 [email protected] passes, offline.
Lingua principale
Python
Stelle
0
Fork
1
Merge medio
5h 59m
PR unite (30g)
19

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di wheelgap/wheels

Tutte le issue di wheelgap/wheels

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.