add support for python-version-file (#336) · mshabdiz/setup-python@53e1529 · GitHub
Skip to content

Commit 53e1529

Browse files
authored
add support for python-version-file (actions#336)
* add support for python-version-file * Update action.yml * update to v4, remove python-version default * python-version overrides python-version-file, like setup-node * checks '.python-version' by default if nothing else specified * update tests, update to checkout@v3 * update build * appease the linter * remove old test for default python version * revert readme changes * update build
1 parent 3f82819 commit 53e1529

5 files changed

Lines changed: 82 additions & 16 deletions

File tree

‎.github/workflows/test-python.yml‎

Lines changed: 25 additions & 11 deletions

‎action.yml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ description: 'Set up a specific version of Python and add the command-line tools
44
author: 'GitHub'
55
inputs:
66
python-version:
7-
description: "Version range or exact version of a Python version to use, using SemVer's version range syntax."
8-
default: '3.x'
7+
description: "Version range or exact version of Python to use, using SemVer's version range syntax. Reads from .python-version if unset."
8+
python-version-file:
9+
description: "File containing the Python version to use. Example: .python-version"
910
cache:
1011
description: 'Used to specify a package manager for caching in the default directory. Supported values: pip, pipenv, poetry.'
1112
required: false

‎dist/setup/index.js‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64527,12 +64527,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
6452764527
step((generator = generator.apply(thisArg, _arguments || [])).next());
6452864528
});
6452964529
};
64530+
var __importDefault = (this && this.__importDefault) || function (mod) {
64531+
return (mod && mod.__esModule) ? mod : { "default": mod };
64532+
};
6453064533
Object.defineProperty(exports, "__esModule", ({ value: true }));
6453164534
const core = __importStar(__nccwpck_require__(2186));
6453264535
const finder = __importStar(__nccwpck_require__(9996));
6453364536
const finderPyPy = __importStar(__nccwpck_require__(4003));
6453464537
const path = __importStar(__nccwpck_require__(1017));
6453564538
const os = __importStar(__nccwpck_require__(2037));
64539+
const fs_1 = __importDefault(__nccwpck_require__(7147));
6453664540
const cache_factory_1 = __nccwpck_require__(7549);
6453764541
const utils_1 = __nccwpck_require__(1314);
6453864542
function isPyPyVersion(versionSpec) {
@@ -64545,6 +64549,23 @@ function cacheDependencies(cache, pythonVersion) {
6454564549
yield cacheDistributor.restoreCache();
6454664550
});
6454764551
}
64552+
function resolveVersionInput() {
64553+
let version = core.getInput('python-version');
64554+
const versionFile = core.getInput('python-version-file');
64555+
if (version && versionFile) {
64556+
core.warning('Both python-version and python-version-file inputs are specified, only python-version will be used');
64557+
}
64558+
if (version) {
64559+
return version;
64560+
}
64561+
const versionFilePath = path.join(process.env.GITHUB_WORKSPACE, versionFile || '.python-version');
64562+
if (!fs_1.default.existsSync(versionFilePath)) {
64563+
throw new Error(`The specified python version file at: ${versionFilePath} does not exist`);
64564+
}
64565+
version = fs_1.default.readFileSync(versionFilePath, 'utf8');
64566+
core.info(`Resolved ${versionFile} as ${version}`);
64567+
return version;
64568+
}
6454864569
function run() {
6454964570
var _a;
6455064571
return __awaiter(this, void 0, void 0, function* () {
@@ -64556,7 +64577,7 @@ function run() {
6455664577
core.debug(`Python is expected to be installed into RUNNER_TOOL_CACHE==${process.env['RUNNER_TOOL_CACHE']}`);
6455764578
}
6455864579
try {
64559-
const version = core.getInput('python-version');
64580+
const version = resolveVersionInput();
6456064581
if (version) {
6456164582
let pythonVersion;
6456264583
const arch = core.getInput('architecture') || os.arch();

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "setup-python",
3-
"version": "3.1.1",
3+
"version": "4.0.0",
44
"private": true,
55
"description": "Setup python action",
66
"main": "dist/index.js",

‎src/setup-python.ts‎

Lines changed: 31 additions & 1 deletion

0 commit comments

Comments
 (0)