feat: fall back to system Python when pre-built binaries unavailable#1289
Open
gounthar wants to merge 1 commit intoactions:mainfrom
Open
feat: fall back to system Python when pre-built binaries unavailable#1289gounthar wants to merge 1 commit intoactions:mainfrom
gounthar wants to merge 1 commit intoactions:mainfrom
Conversation
When pre-built Python binaries are not available for the current architecture (e.g., riscv64), try using system Python as a fallback instead of failing with an error. This enables setup-python to work on architectures that don't yet have pre-built binaries in actions/python-versions, such as riscv64 self-hosted runners. The fallback only activates when: 1. No cached version is found 2. No manifest entry exists for the architecture 3. System python3 exists and satisfies the requested version spec A warning is emitted so users know the fallback was used. Fixes actions#1288 Signed-off-by: Bruno Verachten <gounthar@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a fallback path in actions/setup-python so that when no pre-built CPython binary can be found for the requested version/architecture, the action can optionally use a compatible system python3 instead of failing (targeting unsupported architectures like riscv64).
Changes:
- Add system
python3fallback resolution inuseCpythonVersionwhen toolcache + manifest lookup fails. - Emit a warning when falling back to system Python.
- Update the bundled
distoutput to include the same logic.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/find-python.ts | Adds system python3 fallback when no cached/downloadable CPython is found. |
| dist/setup/index.js | Compiled distribution output reflecting the new fallback behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+125
to
+151
| if (!installDir) { | ||
| // Try system Python as fallback (e.g., on architectures without pre-built binaries) | ||
| try { | ||
| const {exitCode, stdout} = await exec.getExecOutput('python3', [ | ||
| '-c', | ||
| 'import sys; print(sys.prefix)' | ||
| ]); | ||
| if (exitCode === 0) { | ||
| const systemPrefix = stdout.trim(); | ||
| const systemVersion = await exec.getExecOutput('python3', [ | ||
| '-c', | ||
| 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")' | ||
| ]); | ||
| if ( | ||
| systemVersion.exitCode === 0 && | ||
| semver.satisfies(systemVersion.stdout.trim(), semanticVersionSpec) | ||
| ) { | ||
| installDir = systemPrefix; | ||
| core.warning( | ||
| `Pre-built Python not available for architecture '${architecture}'. Using system Python ${systemVersion.stdout.trim()} at ${systemPrefix}.` | ||
| ); | ||
| } | ||
| } | ||
| } catch { | ||
| // System Python not available, fall through to error | ||
| } | ||
| } |
Comment on lines
+125
to
+146
| if (!installDir) { | ||
| // Try system Python as fallback (e.g., on architectures without pre-built binaries) | ||
| try { | ||
| const {exitCode, stdout} = await exec.getExecOutput('python3', [ | ||
| '-c', | ||
| 'import sys; print(sys.prefix)' | ||
| ]); | ||
| if (exitCode === 0) { | ||
| const systemPrefix = stdout.trim(); | ||
| const systemVersion = await exec.getExecOutput('python3', [ | ||
| '-c', | ||
| 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")' | ||
| ]); | ||
| if ( | ||
| systemVersion.exitCode === 0 && | ||
| semver.satisfies(systemVersion.stdout.trim(), semanticVersionSpec) | ||
| ) { | ||
| installDir = systemPrefix; | ||
| core.warning( | ||
| `Pre-built Python not available for architecture '${architecture}'. Using system Python ${systemVersion.stdout.trim()} at ${systemPrefix}.` | ||
| ); | ||
| } |
Comment on lines
+130
to
+144
| 'import sys; print(sys.prefix)' | ||
| ]); | ||
| if (exitCode === 0) { | ||
| const systemPrefix = stdout.trim(); | ||
| const systemVersion = await exec.getExecOutput('python3', [ | ||
| '-c', | ||
| 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")' | ||
| ]); | ||
| if ( | ||
| systemVersion.exitCode === 0 && | ||
| semver.satisfies(systemVersion.stdout.trim(), semanticVersionSpec) | ||
| ) { | ||
| installDir = systemPrefix; | ||
| core.warning( | ||
| `Pre-built Python not available for architecture '${architecture}'. Using system Python ${systemVersion.stdout.trim()} at ${systemPrefix}.` |
Comment on lines
+125
to
+151
| if (!installDir) { | ||
| // Try system Python as fallback (e.g., on architectures without pre-built binaries) | ||
| try { | ||
| const {exitCode, stdout} = await exec.getExecOutput('python3', [ | ||
| '-c', | ||
| 'import sys; print(sys.prefix)' | ||
| ]); | ||
| if (exitCode === 0) { | ||
| const systemPrefix = stdout.trim(); | ||
| const systemVersion = await exec.getExecOutput('python3', [ | ||
| '-c', | ||
| 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}")' | ||
| ]); | ||
| if ( | ||
| systemVersion.exitCode === 0 && | ||
| semver.satisfies(systemVersion.stdout.trim(), semanticVersionSpec) | ||
| ) { | ||
| installDir = systemPrefix; | ||
| core.warning( | ||
| `Pre-built Python not available for architecture '${architecture}'. Using system Python ${systemVersion.stdout.trim()} at ${systemPrefix}.` | ||
| ); | ||
| } | ||
| } | ||
| } catch { | ||
| // System Python not available, fall through to error | ||
| } | ||
| } |
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.
Summary
When pre-built Python binaries are not available for the current architecture, fall back to system Python instead of failing with an error.
This enables
setup-pythonto work on architectures likeriscv64that don't yet have pre-built binaries inactions/python-versions. RISC-V self-hosted runners are becoming available through programs like RISE RISC-V runners, used by numpy, llama.cpp, and pytorch.Changes
src/find-python.ts: Before throwing "version not found" error, check if systempython3exists and satisfies the requested version spec. If so, use it and emit a warning.Behavior
Test plan
npm run build)Fixes #1288