mirror of
				https://kkgithub.com/actions/setup-python.git
				synced 2025-11-04 12:44:05 +08:00 
			
		
		
		
	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
This commit is contained in:
		
							
								
								
									
										4
									
								
								.github/workflows/e2e-cache-freethreaded.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/workflows/e2e-cache-freethreaded.yml
									
									
									
									
										vendored
									
									
								
							@ -58,7 +58,7 @@ jobs:
 | 
				
			|||||||
            macos-latest,
 | 
					            macos-latest,
 | 
				
			||||||
            macos-13
 | 
					            macos-13
 | 
				
			||||||
          ]
 | 
					          ]
 | 
				
			||||||
        python-version: [3.13.0t, 3.13.1t, 3.13.2t]
 | 
					        python-version: [3.13.1t, 3.13.2t, 3.13.5t]
 | 
				
			||||||
    steps:
 | 
					    steps:
 | 
				
			||||||
      - uses: actions/checkout@v4
 | 
					      - uses: actions/checkout@v4
 | 
				
			||||||
      - name: Setup Python
 | 
					      - name: Setup Python
 | 
				
			||||||
@ -148,7 +148,7 @@ jobs:
 | 
				
			|||||||
            macos-latest,
 | 
					            macos-latest,
 | 
				
			||||||
            macos-13
 | 
					            macos-13
 | 
				
			||||||
          ]
 | 
					          ]
 | 
				
			||||||
        python-version: [3.13.0t, 3.13.1t, 3.13.2t]
 | 
					        python-version: [3.13.1t, 3.13.2t, 3.13.5t]
 | 
				
			||||||
    steps:
 | 
					    steps:
 | 
				
			||||||
      - uses: actions/checkout@v4
 | 
					      - uses: actions/checkout@v4
 | 
				
			||||||
      - name: Setup Python
 | 
					      - name: Setup Python
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										3
									
								
								.github/workflows/e2e-tests.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								.github/workflows/e2e-tests.yml
									
									
									
									
										vendored
									
									
								
							@ -38,7 +38,7 @@ jobs:
 | 
				
			|||||||
      - name: Verify 3.9.13
 | 
					      - name: Verify 3.9.13
 | 
				
			||||||
        run: python __tests__/verify-python.py 3.9.13
 | 
					        run: python __tests__/verify-python.py 3.9.13
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Run with setup-python 3.9.13
 | 
					      - name: Run with setup-python 3.10.11
 | 
				
			||||||
        uses: ./
 | 
					        uses: ./
 | 
				
			||||||
        with:
 | 
					        with:
 | 
				
			||||||
          python-version: 3.10.11
 | 
					          python-version: 3.10.11
 | 
				
			||||||
@ -89,6 +89,7 @@ jobs:
 | 
				
			|||||||
          python-version: '<3.13'
 | 
					          python-version: '<3.13'
 | 
				
			||||||
      - name: Verify <3.13
 | 
					      - name: Verify <3.13
 | 
				
			||||||
        run: python __tests__/verify-python.py 3.12
 | 
					        run: python __tests__/verify-python.py 3.12
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - name: Test Raw Endpoint Access
 | 
					      - name: Test Raw Endpoint Access
 | 
				
			||||||
        run: |
 | 
					        run: |
 | 
				
			||||||
          curl -L https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json | jq empty
 | 
					          curl -L https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json | jq empty
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										25
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										25
									
								
								dist/setup/index.js
									
									
									
									
										vendored
									
									
								
							@ -96103,11 +96103,32 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest
 | 
				
			|||||||
            if (utils_1.IS_WINDOWS) {
 | 
					            if (utils_1.IS_WINDOWS) {
 | 
				
			||||||
                // Add --user directory
 | 
					                // Add --user directory
 | 
				
			||||||
                // `installDir` from tool cache should look like $RUNNER_TOOL_CACHE/Python/<semantic version>/x64/
 | 
					                // `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`
 | 
					                // Extract version details
 | 
				
			||||||
                const version = path.basename(path.dirname(installDir));
 | 
					                const version = path.basename(path.dirname(installDir));
 | 
				
			||||||
                const major = semver.major(version);
 | 
					                const major = semver.major(version);
 | 
				
			||||||
                const minor = semver.minor(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);
 | 
					                core.addPath(userScriptsDir);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            // On Linux and macOS, pip will create the --user directory and add it to PATH as needed.
 | 
					            // On Linux and macOS, pip will create the --user directory and add it to PATH as needed.
 | 
				
			||||||
 | 
				
			|||||||
@ -71,8 +71,8 @@ export async function useCpythonVersion(
 | 
				
			|||||||
    // Use the freethreaded version if it was specified in the input, e.g., 3.13t
 | 
					    // Use the freethreaded version if it was specified in the input, e.g., 3.13t
 | 
				
			||||||
    freethreaded = true;
 | 
					    freethreaded = true;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
 | 
				
			||||||
  if (freethreaded) {
 | 
					  if (freethreaded) {
 | 
				
			||||||
    // Free threaded versions use an architecture suffix like `x64-freethreaded`
 | 
					    // Free threaded versions use an architecture suffix like `x64-freethreaded`
 | 
				
			||||||
    core.debug(`Using freethreaded version of ${semanticVersionSpec}`);
 | 
					    core.debug(`Using freethreaded version of ${semanticVersionSpec}`);
 | 
				
			||||||
@ -176,15 +176,36 @@ export async function useCpythonVersion(
 | 
				
			|||||||
    if (IS_WINDOWS) {
 | 
					    if (IS_WINDOWS) {
 | 
				
			||||||
      // Add --user directory
 | 
					      // Add --user directory
 | 
				
			||||||
      // `installDir` from tool cache should look like $RUNNER_TOOL_CACHE/Python/<semantic version>/x64/
 | 
					      // `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`
 | 
					      // Extract version details
 | 
				
			||||||
      const version = path.basename(path.dirname(installDir));
 | 
					      const version = path.basename(path.dirname(installDir));
 | 
				
			||||||
      const major = semver.major(version);
 | 
					      const major = semver.major(version);
 | 
				
			||||||
      const minor = semver.minor(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(
 | 
					      const userScriptsDir = path.join(
 | 
				
			||||||
        process.env['APPDATA'] || '',
 | 
					        basePath,
 | 
				
			||||||
        'Python',
 | 
					        'Python',
 | 
				
			||||||
        `Python${major}${minor}`,
 | 
					        `Python${versionSuffix}`,
 | 
				
			||||||
        'Scripts'
 | 
					        'Scripts'
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
      core.addPath(userScriptsDir);
 | 
					      core.addPath(userScriptsDir);
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user