Skip to content

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

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 0 additions & 10 deletions .github/workflows/test-python-freethreaded.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
macos-13,
Expand Down Expand Up @@ -62,7 +61,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
macos-13,
Expand Down Expand Up @@ -102,8 +100,6 @@ jobs:
os:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
macos-13,
Expand Down Expand Up @@ -142,7 +138,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
macos-13,
Expand Down Expand Up @@ -184,7 +179,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
macos-13,
Expand Down Expand Up @@ -226,7 +220,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
macos-13,
Expand Down Expand Up @@ -258,7 +251,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
macos-13,
Expand Down Expand Up @@ -371,7 +363,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
macos-13,
Expand Down Expand Up @@ -461,7 +452,6 @@ jobs:
[
macos-latest,
windows-latest,
ubuntu-20.04,
ubuntu-22.04,
ubuntu-22.04-arm,
macos-13,
Expand Down
21 changes: 16 additions & 5 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96883,14 +96883,25 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest
core.addPath(installDir);
core.addPath(_binDir);
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`
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');
core.addPath(userScriptsDir);
if (major > 3 || (major === 3 && minor >= 10)) {
// Handle Python >= 3.10
const isFreeThreaded = core.getBooleanInput('freethreaded');
const arch = architecture === 'x86' ? '-32' : '';
const baseName = `Python${major}${minor}${isFreeThreaded ? 't' : ''}${arch}`;
const pythonPath = path.join(process.env['APPDATA'] || '', 'Python', baseName, 'Scripts');
core.addPath(pythonPath);
}
else {
// Handle Python < 3.10
const isFreeThreaded = core.getBooleanInput('freethreaded');
const suffix = isFreeThreaded ? 't' : '';
const baseName = `Python${major}${minor}${suffix}`;
const pythonPath = path.join(process.env['APPDATA'] || '', 'Python', baseName, 'Scripts');
core.addPath(pythonPath);
}
}
// On Linux and macOS, pip will create the --user directory and add it to PATH as needed.
}
Expand Down
42 changes: 32 additions & 10 deletions src/find-python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,42 @@ export async function useCpythonVersion(
core.addPath(_binDir);

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`
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'
);
core.addPath(userScriptsDir);
if (major > 3 || (major === 3 && minor >= 10)) {
// Handle Python >= 3.10
const isFreeThreaded = core.getBooleanInput('freethreaded');
const arch = architecture === 'x86' ? '-32' : '';

const baseName = `Python${major}${minor}${
isFreeThreaded ? 't' : ''
}${arch}`;

const pythonPath = path.join(
process.env['APPDATA'] || '',
'Python',
baseName,
'Scripts'
);

core.addPath(pythonPath);
} else {
// Handle Python < 3.10
const isFreeThreaded = core.getBooleanInput('freethreaded');
const suffix = isFreeThreaded ? 't' : '';
const baseName = `Python${major}${minor}${suffix}`;

const pythonPath = path.join(
process.env['APPDATA'] || '',
'Python',
baseName,
'Scripts'
);

core.addPath(pythonPath);
}
}
// On Linux and macOS, pip will create the --user directory and add it to PATH as needed.
}
Expand Down