mirror of
https://github.com/actions/setup-python.git
synced 2025-04-24 07:22:14 +00:00
Support installation specified of Python version for Linux
This commit is contained in:
parent
4ff1108c39
commit
d3f7e79d54
3 changed files with 336 additions and 212 deletions
75
dist/index.js
vendored
75
dist/index.js
vendored
|
@ -1250,6 +1250,73 @@ module.exports = SemVer
|
||||||
|
|
||||||
module.exports = require("os");
|
module.exports = require("os");
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 98:
|
||||||
|
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||||
|
result["default"] = mod;
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const exec = __importStar(__webpack_require__(986));
|
||||||
|
function getVariable(variableName) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
let variableValue = '';
|
||||||
|
const options = {
|
||||||
|
listeners: {
|
||||||
|
stdout: (data) => {
|
||||||
|
variableValue += data.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
yield exec.exec('bash', ['-c', `echo $${variableName}`], options);
|
||||||
|
return variableValue.trim();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function downloadLinuxCpython(version) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const home = yield getVariable('HOME');
|
||||||
|
yield exec.exec('bash', [
|
||||||
|
'-c',
|
||||||
|
`
|
||||||
|
set -e # Any command which returns non-zero exit code will cause this shell script to exit immediately
|
||||||
|
set -x # Activate debugging to show execution details: all commands will be printed before execution
|
||||||
|
|
||||||
|
sudo apt-get install build-essential checkinstall
|
||||||
|
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
|
||||||
|
|
||||||
|
cd $HOME
|
||||||
|
wget https://www.python.org/ftp/python/${version}/Python-${version}.tgz
|
||||||
|
|
||||||
|
tar -xvf Python-${version}.tgz
|
||||||
|
cd Python-${version}
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
sudo checkinstall -y
|
||||||
|
`
|
||||||
|
]);
|
||||||
|
return `${home}/Python-${version}`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.downloadLinuxCpython = downloadLinuxCpython;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 120:
|
/***/ 120:
|
||||||
|
@ -6279,6 +6346,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const os = __importStar(__webpack_require__(87));
|
const os = __importStar(__webpack_require__(87));
|
||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
const semver = __importStar(__webpack_require__(876));
|
const semver = __importStar(__webpack_require__(876));
|
||||||
|
const downloader = __importStar(__webpack_require__(98));
|
||||||
let cacheDirectory = process.env['RUNNER_TOOLSDIRECTORY'] || '';
|
let cacheDirectory = process.env['RUNNER_TOOLSDIRECTORY'] || '';
|
||||||
if (!cacheDirectory) {
|
if (!cacheDirectory) {
|
||||||
let baseLocation;
|
let baseLocation;
|
||||||
|
@ -6299,6 +6367,7 @@ if (!cacheDirectory) {
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const tc = __importStar(__webpack_require__(533));
|
const tc = __importStar(__webpack_require__(533));
|
||||||
const IS_WINDOWS = process.platform === 'win32';
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
|
const IS_LINUX = process.platform === 'linux';
|
||||||
// Python has "scripts" or "bin" directories where command-line tools that come with packages are installed.
|
// 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.
|
// This is where pip is, along with anything that pip installs.
|
||||||
// There is a seperate directory for `pip install --user`.
|
// There is a seperate directory for `pip install --user`.
|
||||||
|
@ -6354,7 +6423,11 @@ function useCpythonVersion(version, architecture) {
|
||||||
const desugaredVersionSpec = desugarDevVersion(version);
|
const desugaredVersionSpec = desugarDevVersion(version);
|
||||||
const semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec);
|
const semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec);
|
||||||
core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
|
core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
|
||||||
const installDir = tc.find('Python', semanticVersionSpec, architecture);
|
let installDir = tc.find('Python', semanticVersionSpec, architecture);
|
||||||
|
if (!installDir && IS_LINUX) {
|
||||||
|
core.info(`Can't find installed CPython ${version}; trying to download`);
|
||||||
|
installDir = yield downloader.downloadLinuxCpython(version);
|
||||||
|
}
|
||||||
if (!installDir) {
|
if (!installDir) {
|
||||||
// Fail and list available versions
|
// Fail and list available versions
|
||||||
const x86Versions = tc
|
const x86Versions = tc
|
||||||
|
|
43
src/download-python.ts
Normal file
43
src/download-python.ts
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
import * as exec from '@actions/exec';
|
||||||
|
|
||||||
|
async function getVariable(variableName: string): Promise<string> {
|
||||||
|
let variableValue = '';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
listeners: {
|
||||||
|
stdout: (data: Buffer) => {
|
||||||
|
variableValue += data.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await exec.exec('bash', ['-c', `echo $${variableName}`], options);
|
||||||
|
|
||||||
|
return variableValue.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function downloadLinuxCpython(version: string): Promise<string> {
|
||||||
|
const home = await getVariable('HOME');
|
||||||
|
|
||||||
|
await exec.exec('bash', [
|
||||||
|
'-c',
|
||||||
|
`
|
||||||
|
set -e # Any command which returns non-zero exit code will cause this shell script to exit immediately
|
||||||
|
set -x # Activate debugging to show execution details: all commands will be printed before execution
|
||||||
|
|
||||||
|
sudo apt-get install build-essential checkinstall
|
||||||
|
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
|
||||||
|
|
||||||
|
cd $HOME
|
||||||
|
wget https://www.python.org/ftp/python/${version}/Python-${version}.tgz
|
||||||
|
|
||||||
|
tar -xvf Python-${version}.tgz
|
||||||
|
cd Python-${version}
|
||||||
|
./configure
|
||||||
|
make
|
||||||
|
sudo checkinstall -y
|
||||||
|
`
|
||||||
|
]);
|
||||||
|
|
||||||
|
return `${home}/Python-${version}`;
|
||||||
|
}
|
|
@ -3,6 +3,8 @@ import * as path from 'path';
|
||||||
|
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
|
|
||||||
|
import * as downloader from './download-python';
|
||||||
|
|
||||||
let cacheDirectory = process.env['RUNNER_TOOLSDIRECTORY'] || '';
|
let cacheDirectory = process.env['RUNNER_TOOLSDIRECTORY'] || '';
|
||||||
|
|
||||||
if (!cacheDirectory) {
|
if (!cacheDirectory) {
|
||||||
|
@ -24,6 +26,7 @@ import * as core from '@actions/core';
|
||||||
import * as tc from '@actions/tool-cache';
|
import * as tc from '@actions/tool-cache';
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === 'win32';
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
|
const IS_LINUX = process.platform === 'linux';
|
||||||
|
|
||||||
// Python has "scripts" or "bin" directories where command-line tools that come with packages are installed.
|
// 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.
|
// This is where pip is, along with anything that pip installs.
|
||||||
|
@ -92,11 +95,16 @@ async function useCpythonVersion(
|
||||||
const semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec);
|
const semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec);
|
||||||
core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
|
core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
|
||||||
|
|
||||||
const installDir: string | null = tc.find(
|
let installDir: string | null = tc.find(
|
||||||
'Python',
|
'Python',
|
||||||
semanticVersionSpec,
|
semanticVersionSpec,
|
||||||
architecture
|
architecture
|
||||||
);
|
);
|
||||||
|
if (!installDir && IS_LINUX) {
|
||||||
|
core.info(`Can't find installed CPython ${version}; trying to download`);
|
||||||
|
installDir = await downloader.downloadLinuxCpython(version);
|
||||||
|
}
|
||||||
|
|
||||||
if (!installDir) {
|
if (!installDir) {
|
||||||
// Fail and list available versions
|
// Fail and list available versions
|
||||||
const x86Versions = tc
|
const x86Versions = tc
|
||||||
|
|
Loading…
Add table
Reference in a new issue