Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add pip-version input
  • Loading branch information
priyagupta108 committed Jun 5, 2025
commit 0ba3db92d7851981765048af7c63d012721f282b
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ inputs:
freethreaded:
description: "When 'true', use the freethreaded version of Python."
default: false
pip-version:
description: "Used to specify the version of pip to install with the Python. Supported format: major[.minor][.patch]."
outputs:
python-version:
description: "The installed Python or PyPy version. Useful when given a version range as input."
Expand Down
17 changes: 17 additions & 0 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96068,6 +96068,7 @@ const semver = __importStar(__nccwpck_require__(2088));
const installer = __importStar(__nccwpck_require__(1919));
const core = __importStar(__nccwpck_require__(7484));
const tc = __importStar(__nccwpck_require__(3472));
const exec = __importStar(__nccwpck_require__(5236));
// Python has "scripts" or "bin" directories where command-line tools that come with packages are installed.
// This is where pip is, along with anything that pip installs.
// There is a separate directory for `pip install --user`.
Expand All @@ -96088,6 +96089,20 @@ function binDir(installDir) {
return path.join(installDir, 'bin');
}
}
function installPip(pythonLocation) {
return __awaiter(this, void 0, void 0, function* () {
const pipVersion = core.getInput('pip-version');
// Validate pip-version format: major[.minor][.patch]
const versionRegex = /^\d+(\.\d+)?(\.\d+)?$/;
if (pipVersion && !versionRegex.test(pipVersion)) {
throw new Error(`Invalid pip-version "${pipVersion}". Please specify a version in the format major[.minor][.patch].`);
}
if (pipVersion) {
core.info(`pip-version input is specified. Installing pip version ${pipVersion}`);
yield exec.exec(`${pythonLocation}/python -m pip install --upgrade pip==${pipVersion} --disable-pip-version-check --no-warn-script-location`);
}
});
}
function useCpythonVersion(version, architecture, updateEnvironment, checkLatest, allowPreReleases, freethreaded) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
Expand Down Expand Up @@ -96183,6 +96198,8 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest
}
core.setOutput('python-version', pythonVersion);
core.setOutput('python-path', pythonPath);
const binaryPath = utils_1.IS_WINDOWS ? installDir : _binDir;
yield installPip(binaryPath);
return { impl: 'CPython', version: pythonVersion };
});
}
Expand Down
25 changes: 25 additions & 0 deletions src/find-python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as installer from './install-python';

import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import * as exec from '@actions/exec';

// Python has "scripts" or "bin" directories where command-line tools that come with packages are installed.
// This is where pip is, along with anything that pip installs.
Expand All @@ -30,6 +31,27 @@ function binDir(installDir: string): string {
}
}

async function installPip(pythonLocation: string) {
const pipVersion = core.getInput('pip-version');

// Validate pip-version format: major[.minor][.patch]
const versionRegex = /^\d+(\.\d+)?(\.\d+)?$/;
if (pipVersion && !versionRegex.test(pipVersion)) {
throw new Error(
`Invalid pip-version "${pipVersion}". Please specify a version in the format major[.minor][.patch].`
);
}

if (pipVersion) {
core.info(
`pip-version input is specified. Installing pip version ${pipVersion}`
);
await exec.exec(
`${pythonLocation}/python -m pip install --upgrade pip==${pipVersion} --disable-pip-version-check --no-warn-script-location`
);
}
}

export async function useCpythonVersion(
version: string,
architecture: string,
Expand Down Expand Up @@ -179,6 +201,9 @@ export async function useCpythonVersion(
core.setOutput('python-version', pythonVersion);
core.setOutput('python-path', pythonPath);

const binaryPath = IS_WINDOWS ? installDir : _binDir;
await installPip(binaryPath);

return {impl: 'CPython', version: pythonVersion};
}

Expand Down