mirror of
https://github.com/actions/setup-python.git
synced 2026-01-19 11:28:54 +08:00
Add pip-install input
This commit is contained in:
parent
e797f83bcb
commit
9bfc313c8c
7 changed files with 167 additions and 0 deletions
|
|
@ -13,6 +13,7 @@ import {
|
|||
getVersionInputFromFile,
|
||||
getVersionsInputFromPlainFile
|
||||
} from './utils';
|
||||
import {exec} from '@actions/exec';
|
||||
|
||||
function isPyPyVersion(versionSpec: string) {
|
||||
return versionSpec.startsWith('pypy');
|
||||
|
|
@ -22,6 +23,25 @@ function isGraalPyVersion(versionSpec: string) {
|
|||
return versionSpec.startsWith('graalpy');
|
||||
}
|
||||
|
||||
async function installPipPackages() {
|
||||
const pipInstall = core.getInput('pip-install');
|
||||
|
||||
if (!pipInstall) {
|
||||
return;
|
||||
}
|
||||
core.info(`Installing pip packages: ${pipInstall}`);
|
||||
|
||||
try {
|
||||
const installArgs = pipInstall.trim().split(/\s+/);
|
||||
await exec('python', ['-m', 'pip', 'install', ...installArgs]);
|
||||
core.info('Successfully installed pip packages');
|
||||
} catch (error) {
|
||||
core.setFailed(
|
||||
`Failed to install pip packages from "${pipInstall}". Please verify that the package names and versions in the requirements file are correct, that the specified packages and versions can be resolved from PyPI or the configured package index, and that your network connection is stable and allows access to the package index.`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function cacheDependencies(cache: string, pythonVersion: string) {
|
||||
const cacheDependencyPath =
|
||||
core.getInput('cache-dependency-path') || undefined;
|
||||
|
|
@ -145,6 +165,7 @@ async function run() {
|
|||
if (cache && isCacheFeatureAvailable()) {
|
||||
await cacheDependencies(cache, pythonVersion);
|
||||
}
|
||||
await installPipPackages();
|
||||
} else {
|
||||
core.warning(
|
||||
'The `python-version` input is not set. The version of Python currently in `PATH` will be used.'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue