Conversation
Part of flagos-ai#378 The seven platform provisioning scripts each carried their own copy of pip_retry (five slightly different spellings), flag_gems_installed and install_flag_gems (six copies each), strip_vendor_paths (three) and venv_is_usable (two), plus a 21-line FlagGems VCS-install rationale duplicated verbatim in six of them. A fix had to be applied seven times and was easy to miss. Add .github/scripts/lib/set_env_common.sh and have every script source it, removing the local copies and the now-duplicated comments (the shared rationale moved into the library). The per-platform main flows, SDK discovery and vendor-torch handling are unchanged; only the shared helpers moved. The interpreter comes from ${VENV_PYTHON:-python}: every script but MetaX sets VENV_PYTHON to its job-local venv, and MetaX runs the image's /opt/venv via PATH and keeps using `python`. pip_retry additionally honours PIP_RETRY_PYTHON (the CUDA script drives several interpreters, so it now sets that per call instead of passing the interpreter as $1), PIP_RETRY_TIMEOUT and PIP_RETRY_NO_CACHE (CUDA keeps its 600s timeout and build cache; the rest keep 300s + --no-cache-dir). Changes: - .github/scripts/lib/set_env_common.sh (new): the five helpers. - .github/scripts/set_env_*.sh: source the library; drop the local helpers and their duplicated comments; CUDA prefixes its 7 pip_retry calls with PIP_RETRY_PYTHON. - tests/unit/test_set_env_common.py (new): the library defines the helpers, no script redefines them, every script sources it, and CUDA still selects its interpreter per call. - .github/workflows/agnostic-checks.yml: bash -n the library; run the new test. Net -675/+285 across the seven scripts (the shared logic now exists once). Tested: bash -n on all scripts and the library; ruff clean; 26 pure-text unit tests pass; the only non-function code removed is CUDA's pip_retry call sites, rewritten in place. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
19 tasks
Collaborator
Author
|
Superseded by #420, which stacked on this branch's commit (cafd32f) and merged. Everything here — the shared |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AI Agent Information
refactor/set-env-common. The unifiedset_env.shrunner and a constraints file are deferred.Summary
Adds
.github/scripts/lib/set_env_common.shwith the five helpers the seven platform provisioning scripts each carried their own copy of (pip_retry,flag_gems_installed,install_flag_gems,strip_vendor_paths,venv_is_usable), plus the 21-line FlagGems VCS-install rationale that was duplicated verbatim in six of them. Every script sources the library and drops its local copies; the per-platform main flows are unchanged. Net -676/+285 across the seven scripts.Change Type
Platforms Affected
Problem Analysis
What was broken/missing?
Each of
.github/scripts/set_env_{cuda,ascend,dcu,gcu,metax,musa,ppu}.shcarried its own copy of:pip_retry-- five slightly different spellings (interpreter, timeout 300 vs 600,--no-cache-diron/off);flag_gems_installedandinstall_flag_gems-- six copies each, two variants;strip_vendor_paths-- three identical copies;venv_is_usable-- two copies;A fix had to be applied seven times and was easy to miss.
Why did it happen?
Each new platform job copied the previous script and patched the vendor-specific lines; the shared skeleton was never factored out.
Investigation process:
pip_retry5,flag_gems_installed/install_flag_gems2,strip_vendor_paths1).VENV_PYTHON; MetaX runs the image's/opt/venvviaPATHand uses barepython. CUDA drives several interpreters per call.Solution Design
Implementation approach:
One sourced library; each script sources it after the pin file and deletes its local copies.
Key design decisions:
${VENV_PYTHON:-python}. Preserves MetaX'spython(it sets noVENV_PYTHON) and everyone else'sVENV_PYTHON.pip_retryparameterized by environment, not by argument.PIP_RETRY_PYTHON(per-call interpreter override for CUDA),PIP_RETRY_TIMEOUT(default 300),PIP_RETRY_NO_CACHE(default 1). CUDA sets 600/0 once and prefixes its 7 calls withPIP_RETRY_PYTHON=…instead of passing the interpreter as$1; every other script's call sites are unchanged.set_env.sh --platform <p>runner (item 2) and aconstraints.txt(item 3) are separate, larger changes; deferred.Code changes by file:
.github/scripts/lib/set_env_common.sh(new): the five helpers + the moved rationale..github/scripts/set_env_*.sh: source the library; drop the local helpers and duplicated comments; CUDA prefixes itspip_retrycalls.tests/unit/test_set_env_common.py(new): the library defines the helpers, no script redefines them, every script sources it, CUDA still selects its interpreter per call..github/workflows/agnostic-checks.yml:bash -nthe library; run the new test.Changes by commit:
cafd32f-ci: share the set_env_* helper functions in one library: the whole change.Verification
Pre-submission Checklist
bash -n; removed-code audit)Linting Results
Test Results
Manual Verification
The end-to-end check is the platform CI jobs, which source these scripts; the shared helpers resolve the same interpreter and flags as before.
Breaking Changes
None. Each script resolves the same interpreter and pip flags as before; only where the helper is defined changed.
Code Quality Verification
Style Consistency
${VENV_PYTHON:-python}conventionEdge Cases Considered
VENV_PYTHON, so${VENV_PYTHON:-python}keeps itspython.PIP_RETRY_PYTHONper call; the test pins that all 7 calls do.set -uis in effect in every script: every variable read by the library is either set by the caller or has a:-default.Potential Risks
set -u;bash -ncatches syntax, and the platform CI jobs exercise the scripts end to end.Rollback Plan
Revert the single commit; the scripts regain their local helpers.
Related Work
Explicitly Not Included
.github/scripts/set_env.sh --platform <p>runner with per-platform hooks (issue item 2) -- a large inversion of control over seven vendor scripts, verifiable only on the vendor runners.constraints.txtfor the CI venvs (issue item 3).setup.py'sflag_gems>=5.0.2floor with CI's pinned git revision (issue item 4).Human Review Notes
Areas needing special attention:
pythonand CUDA's per-call interpreters).Questions for reviewer:
Additional Context
Base:
upstream/mainat877afb1.🤖 Generated with Claude Code