From 7469b5436f0584ad06ceb6bafb3150830a5f9027 Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Fri, 6 Jun 2025 18:39:01 +0530 Subject: [PATCH 1/3] logic to update install oath with --user flg --- dist/setup/index.js | 27 +++++++++++++++++++++++---- src/find-python.ts | 31 +++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 4e3f2673..fd3d14a3 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -96164,13 +96164,32 @@ 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//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. diff --git a/src/find-python.ts b/src/find-python.ts index ddb027cb..2e317d9c 100644 --- a/src/find-python.ts +++ b/src/find-python.ts @@ -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}`); @@ -152,17 +152,36 @@ export async function useCpythonVersion( core.addPath(_binDir); if (IS_WINDOWS) { - // Add --user directory - // `installDir` from tool cache should look like $RUNNER_TOOL_CACHE/Python//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); From 2e54943954f660f87e08d487bd6fcb3aa5556750 Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Fri, 6 Jun 2025 18:51:53 +0530 Subject: [PATCH 2/3] format update --- __tests__/verify_windows_install_path_user.py | 43 +++++++++++++++++++ dist/setup/index.js | 3 +- src/find-python.ts | 5 +-- 3 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 __tests__/verify_windows_install_path_user.py diff --git a/__tests__/verify_windows_install_path_user.py b/__tests__/verify_windows_install_path_user.py new file mode 100644 index 00000000..9ee8eb36 --- /dev/null +++ b/__tests__/verify_windows_install_path_user.py @@ -0,0 +1,43 @@ +import os +import sys + +def build_expected_path(architecture, freethreaded): + major = 3 + minor = 13 + version_suffix = f"{major}{minor}" + + if architecture == "x86" and (major > 3 or (major == 3 and minor >= 10)): + version_suffix += "-32" + elif architecture == "arm64": + version_suffix += "-arm64" + + if freethreaded == "true": + version_suffix += "t" + if architecture == "x86": + version_suffix += "-32" + elif architecture == "arm64": + version_suffix += "-arm64" + + base_path = os.getenv("APPDATA", "") + return os.path.join(base_path, "Python", f"Python{version_suffix}", "Scripts") + +def main(): + if len(sys.argv) != 3: + print("Usage: python verify_windows_install_path.py ") + sys.exit(1) + + architecture = sys.argv[1] + freethreaded = sys.argv[2] + + expected_path = build_expected_path(architecture, freethreaded) + print(f"Expected PATH entry: {expected_path}") + + path_env = os.getenv("PATH", "") + if expected_path.lower() not in path_env.lower(): + print("Expected path not found in PATH") + sys.exit(1) + else: + print("Correct path present in PATH") + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/dist/setup/index.js b/dist/setup/index.js index fd3d14a3..491c85a8 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -96171,8 +96171,7 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest 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))) { + if (architecture === 'x86' && (major > 3 || (major === 3 && minor >= 10))) { versionSuffix += '-32'; } else if (architecture === 'arm64') { diff --git a/src/find-python.ts b/src/find-python.ts index 2e317d9c..58ec4347 100644 --- a/src/find-python.ts +++ b/src/find-python.ts @@ -160,10 +160,7 @@ export async function useCpythonVersion( 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)) - ) { + if (architecture === 'x86' && (major > 3 || (major === 3 && minor >= 10))){ versionSuffix += '-32'; } else if (architecture === 'arm64') { versionSuffix += '-arm64'; From 4c7c4b45a87b4469af18ce299b169f990f5d42f0 Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Fri, 6 Jun 2025 18:54:18 +0530 Subject: [PATCH 3/3] format update --- dist/setup/index.js | 3 ++- src/find-python.ts | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 491c85a8..fd3d14a3 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -96171,7 +96171,8 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest 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))) { + if (architecture === 'x86' && + (major > 3 || (major === 3 && minor >= 10))) { versionSuffix += '-32'; } else if (architecture === 'arm64') { diff --git a/src/find-python.ts b/src/find-python.ts index 58ec4347..2e317d9c 100644 --- a/src/find-python.ts +++ b/src/find-python.ts @@ -160,7 +160,10 @@ export async function useCpythonVersion( 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))){ + if ( + architecture === 'x86' && + (major > 3 || (major === 3 && minor >= 10)) + ) { versionSuffix += '-32'; } else if (architecture === 'arm64') { versionSuffix += '-arm64';