From 404bd3b57d617f093a6e069cd829baa003ee20c0 Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Wed, 30 Apr 2025 18:15:24 +0530 Subject: [PATCH] update the logic --- dist/setup/index.js | 24 +++++++++++------------- src/find-python.ts | 42 ++++++++++++++---------------------------- 2 files changed, 25 insertions(+), 41 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 72e00b8d..7b2a2d4a 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -96883,26 +96883,24 @@ 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`// Add --user directory + // 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))) { - // For Python >= 3.10 and architecture='x86', add the architecture-specific folder to the path - const arch = '32'; // Only for x86 architecture - const userScriptsDir = path.join(process.env['APPDATA'] || '', 'Python', `Python${major}${minor}-${arch}`, 'Scripts'); - core.addPath(userScriptsDir); + versionSuffix += '-32'; } - else { - const userScriptsDir = path.join(process.env['APPDATA'] || '', 'Python', `Python${major}${minor}`, 'Scripts'); - core.addPath(userScriptsDir); + // Append 't' for freethreaded builds + if (freethreaded) { + versionSuffix += 't'; } - // for free-freethreaded versions, add the freethreaded scripts directory - const pythonPath = path.join(process.env['APPDATA'] || '', 'Python', `Python${major}${minor}t`, 'Scripts'); - core.addPath(pythonPath); + // 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 3a21f5c0..e6f24c86 100644 --- a/src/find-python.ts +++ b/src/find-python.ts @@ -152,45 +152,31 @@ 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`// Add --user directory + // 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)) ) { - // For Python >= 3.10 and architecture='x86', add the architecture-specific folder to the path - const arch = '32'; // Only for x86 architecture - - const userScriptsDir = path.join( - process.env['APPDATA'] || '', - 'Python', - `Python${major}${minor}-${arch}`, - 'Scripts' - ); - core.addPath(userScriptsDir); - } else { - const userScriptsDir = path.join( - process.env['APPDATA'] || '', - 'Python', - `Python${major}${minor}`, - 'Scripts' - ); - core.addPath(userScriptsDir); + versionSuffix += '-32'; } - - // for free-freethreaded versions, add the freethreaded scripts directory - const pythonPath = path.join( - process.env['APPDATA'] || '', + // Append 't' for freethreaded builds + if (freethreaded) { + versionSuffix += 't'; + } + // Add user Scripts path + const userScriptsDir = path.join( + basePath, 'Python', - `Python${major}${minor}t`, + `Python${versionSuffix}`, 'Scripts' ); - core.addPath(pythonPath); + core.addPath(userScriptsDir); } // On Linux and macOS, pip will create the --user directory and add it to PATH as needed. }