Skip to content

Add Architecture-Specific PATH Management for Python with --user Flag on Windows #1122

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/e2e-cache-freethreaded.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
macos-latest,
macos-13
]
python-version: [3.13.0t, 3.13.1t, 3.13.2t]
python-version: [3.13.1t, 3.13.2t, 3.13.5t]
steps:
- uses: actions/checkout@v4
- name: Setup Python
Expand Down Expand Up @@ -148,7 +148,7 @@ jobs:
macos-latest,
macos-13
]
python-version: [3.13.0t, 3.13.1t, 3.13.2t]
python-version: [3.13.1t, 3.13.2t, 3.13.5t]
steps:
- uses: actions/checkout@v4
- name: Setup Python
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Verify 3.9.13
run: python __tests__/verify-python.py 3.9.13

- name: Run with setup-python 3.9.13
- name: Run with setup-python 3.10.11
uses: ./
with:
python-version: 3.10.11
Expand Down Expand Up @@ -89,6 +89,7 @@ jobs:
python-version: '<3.13'
- name: Verify <3.13
run: python __tests__/verify-python.py 3.12

- name: Test Raw Endpoint Access
run: |
curl -L https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json | jq empty
Expand Down
25 changes: 23 additions & 2 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96166,11 +96166,32 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest
if (utils_1.IS_WINDOWS) {
// Add --user directory
// `installDir` from tool cache should look like $RUNNER_TOOL_CACHE/Python/<semantic version>/x64/
// So if `findLocalTool` succeeded above, we must have a conformant `installDir`
// Extract version details
const version = path.basename(path.dirname(installDir));
const major = semver.major(version);
const minor = semver.minor(version);
const userScriptsDir = path.join(process.env['APPDATA'] || '', 'Python', `Python${major}${minor}`, 'Scripts');
const basePath = process.env['APPDATA'] || '';
let versionSuffix = `${major}${minor}`;
// Append '-32' for x86 architecture if Python version is >= 3.10
if (architecture === 'x86' &&
(major > 3 || (major === 3 && minor >= 10))) {
versionSuffix += '-32';
}
else if (architecture === 'arm64') {
versionSuffix += '-arm64';
}
// Append 't' for freethreaded builds
if (freethreaded) {
versionSuffix += 't';
if (architecture === 'x86-freethreaded') {
versionSuffix += '-32';
}
else if (architecture === 'arm64-freethreaded') {
versionSuffix += '-arm64';
}
}
// Add user Scripts path
const userScriptsDir = path.join(basePath, 'Python', `Python${versionSuffix}`, 'Scripts');
core.addPath(userScriptsDir);
}
// On Linux and macOS, pip will create the --user directory and add it to PATH as needed.
Expand Down
29 changes: 25 additions & 4 deletions src/find-python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export async function useCpythonVersion(
// Use the freethreaded version if it was specified in the input, e.g., 3.13t
freethreaded = true;
}
core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);

core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
if (freethreaded) {
// Free threaded versions use an architecture suffix like `x64-freethreaded`
core.debug(`Using freethreaded version of ${semanticVersionSpec}`);
Expand Down Expand Up @@ -154,15 +154,36 @@ export async function useCpythonVersion(
if (IS_WINDOWS) {
// Add --user directory
// `installDir` from tool cache should look like $RUNNER_TOOL_CACHE/Python/<semantic version>/x64/
// So if `findLocalTool` succeeded above, we must have a conformant `installDir`
// Extract version details
const version = path.basename(path.dirname(installDir));
const major = semver.major(version);
const minor = semver.minor(version);

const basePath = process.env['APPDATA'] || '';
let versionSuffix = `${major}${minor}`;
// Append '-32' for x86 architecture if Python version is >= 3.10
if (
architecture === 'x86' &&
(major > 3 || (major === 3 && minor >= 10))
) {
versionSuffix += '-32';
} else if (architecture === 'arm64') {
versionSuffix += '-arm64';
}
// Append 't' for freethreaded builds
if (freethreaded) {
versionSuffix += 't';
if (architecture === 'x86-freethreaded') {
versionSuffix += '-32';
} else if (architecture === 'arm64-freethreaded') {
versionSuffix += '-arm64';
}
}
// Add user Scripts path
const userScriptsDir = path.join(
process.env['APPDATA'] || '',
basePath,
'Python',
`Python${major}${minor}`,
`Python${versionSuffix}`,
'Scripts'
);
core.addPath(userScriptsDir);
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy