Skip to content

Commit 822c528

Browse files
Add Architecture-Specific PATH Management for Python with --user Flag on Windows (#1122)
* logic to update install oath with --user flg * format update * format update * update * test job to validate --user flag installtion * updated the script * updated the yaml * update the inputs * updated script * update the correct script file name * updated script and yaml * npm run format-check * fix-test failures * path update * check failure fix * updated test * update free threaded version * updated the comments
1 parent b8b5d60 commit 822c528

File tree

4 files changed

+52
-9
lines changed

4 files changed

+52
-9
lines changed

.github/workflows/e2e-cache-freethreaded.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
macos-latest,
5959
macos-13
6060
]
61-
python-version: [3.13.0t, 3.13.1t, 3.13.2t]
61+
python-version: [3.13.1t, 3.13.2t, 3.13.5t]
6262
steps:
6363
- uses: actions/checkout@v4
6464
- name: Setup Python
@@ -148,7 +148,7 @@ jobs:
148148
macos-latest,
149149
macos-13
150150
]
151-
python-version: [3.13.0t, 3.13.1t, 3.13.2t]
151+
python-version: [3.13.1t, 3.13.2t, 3.13.5t]
152152
steps:
153153
- uses: actions/checkout@v4
154154
- name: Setup Python

.github/workflows/e2e-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- name: Verify 3.9.13
3939
run: python __tests__/verify-python.py 3.9.13
4040

41-
- name: Run with setup-python 3.9.13
41+
- name: Run with setup-python 3.10.11
4242
uses: ./
4343
with:
4444
python-version: 3.10.11
@@ -89,6 +89,7 @@ jobs:
8989
python-version: '<3.13'
9090
- name: Verify <3.13
9191
run: python __tests__/verify-python.py 3.12
92+
9293
- name: Test Raw Endpoint Access
9394
run: |
9495
curl -L https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json | jq empty

dist/setup/index.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96134,11 +96134,32 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest
9613496134
if (utils_1.IS_WINDOWS) {
9613596135
// Add --user directory
9613696136
// `installDir` from tool cache should look like $RUNNER_TOOL_CACHE/Python/<semantic version>/x64/
96137-
// So if `findLocalTool` succeeded above, we must have a conformant `installDir`
96137+
// Extract version details
9613896138
const version = path.basename(path.dirname(installDir));
9613996139
const major = semver.major(version);
9614096140
const minor = semver.minor(version);
96141-
const userScriptsDir = path.join(process.env['APPDATA'] || '', 'Python', `Python${major}${minor}`, 'Scripts');
96141+
const basePath = process.env['APPDATA'] || '';
96142+
let versionSuffix = `${major}${minor}`;
96143+
// Append '-32' for x86 architecture if Python version is >= 3.10
96144+
if (architecture === 'x86' &&
96145+
(major > 3 || (major === 3 && minor >= 10))) {
96146+
versionSuffix += '-32';
96147+
}
96148+
else if (architecture === 'arm64') {
96149+
versionSuffix += '-arm64';
96150+
}
96151+
// Append 't' for freethreaded builds
96152+
if (freethreaded) {
96153+
versionSuffix += 't';
96154+
if (architecture === 'x86-freethreaded') {
96155+
versionSuffix += '-32';
96156+
}
96157+
else if (architecture === 'arm64-freethreaded') {
96158+
versionSuffix += '-arm64';
96159+
}
96160+
}
96161+
// Add user Scripts path
96162+
const userScriptsDir = path.join(basePath, 'Python', `Python${versionSuffix}`, 'Scripts');
9614296163
core.addPath(userScriptsDir);
9614396164
}
9614496165
// On Linux and macOS, pip will create the --user directory and add it to PATH as needed.

src/find-python.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export async function useCpythonVersion(
7171
// Use the freethreaded version if it was specified in the input, e.g., 3.13t
7272
freethreaded = true;
7373
}
74-
core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
7574

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

184+
const basePath = process.env['APPDATA'] || '';
185+
let versionSuffix = `${major}${minor}`;
186+
// Append '-32' for x86 architecture if Python version is >= 3.10
187+
if (
188+
architecture === 'x86' &&
189+
(major > 3 || (major === 3 && minor >= 10))
190+
) {
191+
versionSuffix += '-32';
192+
} else if (architecture === 'arm64') {
193+
versionSuffix += '-arm64';
194+
}
195+
// Append 't' for freethreaded builds
196+
if (freethreaded) {
197+
versionSuffix += 't';
198+
if (architecture === 'x86-freethreaded') {
199+
versionSuffix += '-32';
200+
} else if (architecture === 'arm64-freethreaded') {
201+
versionSuffix += '-arm64';
202+
}
203+
}
204+
// Add user Scripts path
184205
const userScriptsDir = path.join(
185-
process.env['APPDATA'] || '',
206+
basePath,
186207
'Python',
187-
`Python${major}${minor}`,
208+
`Python${versionSuffix}`,
188209
'Scripts'
189210
);
190211
core.addPath(userScriptsDir);

0 commit comments

Comments
 (0)
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