From 114b4684b80eee9545c35caf905203e137d03fb5 Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Mon, 28 Apr 2025 15:49:13 +0530 Subject: [PATCH] code update for free threaded --- dist/setup/index.js | 26 +++++++++++++------------- src/find-python.ts | 44 +++++++++++++++++++++++--------------------- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 6253d0b0..73dd0c6d 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -96883,25 +96883,25 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest core.addPath(installDir); core.addPath(_binDir); if (utils_1.IS_WINDOWS) { + // Add --user directory const version = path.basename(path.dirname(installDir)); const major = semver.major(version); const minor = semver.minor(version); - 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); + 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 { - // 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); + // For Python >= 3.10 and architecture 'x64', or other versions, use the default user path + const userScriptsDir = path.join(process.env['APPDATA'] || '', 'Python', `Python${major}${minor}`, 'Scripts'); + core.addPath(userScriptsDir); } + // Dynamically handle case for Python314t + const pythonPath = path.join(process.env['APPDATA'] || '', 'Python', `Python${major}${minor}t`, 'Scripts'); + core.addPath(pythonPath); } // 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 add4c135..188bc4c7 100644 --- a/src/find-python.ts +++ b/src/find-python.ts @@ -152,42 +152,44 @@ export async function useCpythonVersion( core.addPath(_binDir); if (IS_WINDOWS) { + // Add --user directory const version = path.basename(path.dirname(installDir)); const major = semver.major(version); const minor = semver.minor(version); - if (major > 3 || (major === 3 && minor >= 10)) { - // Handle Python >= 3.10 - const isFreeThreaded = core.getBooleanInput('freethreaded'); - const arch = architecture === 'x86' ? '-32' : ''; + 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 baseName = `Python${major}${minor}${ - isFreeThreaded ? 't' : '' - }${arch}`; - - const pythonPath = path.join( + const userScriptsDir = path.join( process.env['APPDATA'] || '', 'Python', - baseName, + `Python${major}${minor}-${arch}`, 'Scripts' ); - - core.addPath(pythonPath); + core.addPath(userScriptsDir); } else { - // Handle Python < 3.10 - const isFreeThreaded = core.getBooleanInput('freethreaded'); - const suffix = isFreeThreaded ? 't' : ''; - const baseName = `Python${major}${minor}${suffix}`; - - const pythonPath = path.join( + // For Python >= 3.10 and architecture 'x64', or other versions, use the default user path + const userScriptsDir = path.join( process.env['APPDATA'] || '', 'Python', - baseName, + `Python${major}${minor}`, 'Scripts' ); - - core.addPath(pythonPath); + core.addPath(userScriptsDir); } + + // Dynamically handle case for Python314t + const pythonPath = path.join( + process.env['APPDATA'] || '', + 'Python', + `Python${major}${minor}t`, + 'Scripts' + ); + core.addPath(pythonPath); } // On Linux and macOS, pip will create the --user directory and add it to PATH as needed. }