mirror of
https://code.forgejo.org/actions/setup-python
synced 2025-06-18 16:50:25 +02:00
Add freethreaded input and fix handling of prerelease versions
This commit is contained in:
parent
d653c0b66e
commit
72902a03bd
7 changed files with 163 additions and 55 deletions
48
dist/setup/index.js
vendored
48
dist/setup/index.js
vendored
|
@ -91034,17 +91034,21 @@ function binDir(installDir) {
|
|||
return path.join(installDir, 'bin');
|
||||
}
|
||||
}
|
||||
function useCpythonVersion(version, architecture, updateEnvironment, checkLatest, allowPreReleases) {
|
||||
function useCpythonVersion(version, architecture, updateEnvironment, checkLatest, allowPreReleases, freethreaded) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var _a;
|
||||
let manifest = null;
|
||||
const [desugaredVersionSpec, freethreaded] = desugarVersion(version);
|
||||
const { version: desugaredVersionSpec, freethreaded: versionFreethreaded } = desugarVersion(version);
|
||||
let semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec, allowPreReleases);
|
||||
if (versionFreethreaded) {
|
||||
// Use the freethreaded version if it was specified in the input, e.g., 3.13t
|
||||
freethreaded = true;
|
||||
}
|
||||
core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
|
||||
if (freethreaded) {
|
||||
// Free threaded versions use an architecture suffix like `x64-freethreaded`
|
||||
core.debug(`Using freethreaded version of ${semanticVersionSpec}`);
|
||||
architecture += freethreaded;
|
||||
architecture += '-freethreaded';
|
||||
}
|
||||
if (checkLatest) {
|
||||
manifest = yield installer.getManifest();
|
||||
|
@ -91122,27 +91126,33 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest
|
|||
exports.useCpythonVersion = useCpythonVersion;
|
||||
/* Desugar free threaded and dev versions */
|
||||
function desugarVersion(versionSpec) {
|
||||
const [desugaredVersionSpec, freethreaded] = desugarFreeThreadedVersion(versionSpec);
|
||||
const desugaredVersionSpec2 = desugarDevVersion(desugaredVersionSpec);
|
||||
return [desugaredVersionSpec2, freethreaded];
|
||||
const { version, freethreaded } = desugarFreeThreadedVersion(versionSpec);
|
||||
return { version: desugarDevVersion(version), freethreaded };
|
||||
}
|
||||
exports.desugarVersion = desugarVersion;
|
||||
/* Identify freethreaded versions like, 3.13t, 3.13.1t, 3.13t-dev, 3.14.0a1t.
|
||||
* Returns the version without the `t` and the architectures suffix, if freethreaded */
|
||||
function desugarFreeThreadedVersion(versionSpec) {
|
||||
const prereleaseVersion = /(\d+\.\d+\.\d+)(t)((?:a|b|rc)\d*)/g;
|
||||
// e.g., 3.14.0a1t -> 3.14.0a1
|
||||
const prereleaseVersion = /(\d+\.\d+\.\d+)((?:a|b|rc)\d*)(t)/g;
|
||||
if (prereleaseVersion.test(versionSpec)) {
|
||||
return [versionSpec.replace(prereleaseVersion, '$1$3'), '-freethreaded'];
|
||||
return {
|
||||
version: versionSpec.replace(prereleaseVersion, '$1$2'),
|
||||
freethreaded: true
|
||||
};
|
||||
}
|
||||
const majorMinor = /^(\d+\.\d+(\.\d+)?)(t)$/;
|
||||
if (majorMinor.test(versionSpec)) {
|
||||
return [versionSpec.replace(majorMinor, '$1'), '-freethreaded'];
|
||||
return { version: versionSpec.replace(majorMinor, '$1'), freethreaded: true };
|
||||
}
|
||||
const devVersion = /^(\d+\.\d+)(t)(-dev)$/;
|
||||
if (devVersion.test(versionSpec)) {
|
||||
return [versionSpec.replace(devVersion, '$1$3'), '-freethreaded'];
|
||||
return {
|
||||
version: versionSpec.replace(devVersion, '$1$3'),
|
||||
freethreaded: true
|
||||
};
|
||||
}
|
||||
return [versionSpec, ''];
|
||||
return { version: versionSpec, freethreaded: false };
|
||||
}
|
||||
/** Convert versions like `3.8-dev` to a version like `~3.8.0-0`. */
|
||||
function desugarDevVersion(versionSpec) {
|
||||
|
@ -91157,15 +91167,22 @@ function versionFromPath(installDir) {
|
|||
}
|
||||
/**
|
||||
* Python's prelease versions look like `3.7.0b2`.
|
||||
* This is the one part of Python versioning that does not look like semantic versioning, which specifies `3.7.0-b2`.
|
||||
* This is the one part of Python versioning that does not look like semantic versioning, which specifies `3.7.0-beta.2`.
|
||||
* If the version spec contains prerelease versions, we need to convert them to the semantic version equivalent.
|
||||
*
|
||||
* For easier use of the action, we also map 'x.y' to allow pre-release before 'x.y.0' release if allowPreReleases is true
|
||||
*/
|
||||
function pythonVersionToSemantic(versionSpec, allowPreReleases) {
|
||||
const prereleaseVersion = /(\d+\.\d+\.\d+)((?:a|b|rc)\d*)/g;
|
||||
const preleaseMap = {
|
||||
a: 'alpha',
|
||||
b: 'beta',
|
||||
rc: 'rc'
|
||||
};
|
||||
const prereleaseVersion = /(\d+\.\d+\.\d+)(a|b|rc)(\d+)/g;
|
||||
let result = versionSpec.replace(prereleaseVersion, (_, p1, p2, p3) => {
|
||||
return `${p1}-${preleaseMap[p2]}.${p3}`;
|
||||
});
|
||||
const majorMinor = /^(\d+)\.(\d+)$/;
|
||||
let result = versionSpec.replace(prereleaseVersion, '$1-$2');
|
||||
if (allowPreReleases) {
|
||||
result = result.replace(majorMinor, '~$1.$2.0-0');
|
||||
}
|
||||
|
@ -91881,6 +91898,7 @@ function run() {
|
|||
const versions = resolveVersionInput();
|
||||
const checkLatest = core.getBooleanInput('check-latest');
|
||||
const allowPreReleases = core.getBooleanInput('allow-prereleases');
|
||||
const freethreaded = core.getBooleanInput('freethreaded');
|
||||
if (versions.length) {
|
||||
let pythonVersion = '';
|
||||
const arch = core.getInput('architecture') || os.arch();
|
||||
|
@ -91901,7 +91919,7 @@ function run() {
|
|||
if (version.startsWith('2')) {
|
||||
core.warning('The support for python 2.7 was removed on June 19, 2023. Related issue: https://github.com/actions/setup-python/issues/672');
|
||||
}
|
||||
const installed = yield finder.useCpythonVersion(version, arch, updateEnvironment, checkLatest, allowPreReleases);
|
||||
const installed = yield finder.useCpythonVersion(version, arch, updateEnvironment, checkLatest, allowPreReleases, freethreaded);
|
||||
pythonVersion = installed.version;
|
||||
core.info(`Successfully set up ${installed.impl} (${pythonVersion})`);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue