You've already forked setup-python
mirror of
https://github.com/actions/setup-python.git
synced 2025-10-08 20:41:26 +07:00
Add support for pip-install input (#1201)
* Add pip-install input * Improve error message * Logic update --------- Co-authored-by: “gowridurgad” <“hgowridurgad@github.com>
This commit is contained in:
@ -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,19 @@ function isGraalPyVersion(versionSpec: string) {
|
||||
return versionSpec.startsWith('graalpy');
|
||||
}
|
||||
|
||||
async function installPipPackages(pipInstall: string) {
|
||||
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, versions, or requirements files provided are correct and installable, 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 +159,10 @@ async function run() {
|
||||
if (cache && isCacheFeatureAvailable()) {
|
||||
await cacheDependencies(cache, pythonVersion);
|
||||
}
|
||||
const pipInstall = core.getInput('pip-install');
|
||||
if (pipInstall) {
|
||||
await installPipPackages(pipInstall);
|
||||
}
|
||||
} else {
|
||||
core.warning(
|
||||
'The `python-version` input is not set. The version of Python currently in `PATH` will be used.'
|
||||
|
Reference in New Issue
Block a user