mirror of
https://github.com/actions/setup-python.git
synced 2025-01-27 12:47:58 +01:00
Fix desugaring of 3.13.1t
and add test case.
This commit is contained in:
parent
c70f76ebc5
commit
d653c0b66e
3 changed files with 44 additions and 14 deletions
18
__tests__/find-python.test.ts
Normal file
18
__tests__/find-python.test.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import {desugarVersion} from '../src/find-python';
|
||||
|
||||
describe('desugarVersion', () => {
|
||||
it.each([
|
||||
['3.13', ['3.13', '']],
|
||||
['3.13t', ['3.13', '-freethreaded']],
|
||||
['3.13.1', ['3.13.1', '']],
|
||||
['3.13.1t', ['3.13.1', '-freethreaded']],
|
||||
['3.14-dev', ['~3.14.0-0', '']],
|
||||
['3.14t-dev', ['~3.14.0-0', '-freethreaded']],
|
||||
['3.14.0a4', ['3.14.0a4', '']],
|
||||
['3.14.0ta4', ['3.14.0a4', '-freethreaded']],
|
||||
['3.14.0rc1', ['3.14.0rc1', '']],
|
||||
['3.14.0trc1', ['3.14.0rc1', '-freethreaded']]
|
||||
])('%s -> %s', (input, expected) => {
|
||||
expect(desugarVersion(input)).toEqual(expected);
|
||||
});
|
||||
});
|
20
dist/setup/index.js
vendored
20
dist/setup/index.js
vendored
|
@ -91006,7 +91006,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.pythonVersionToSemantic = exports.useCpythonVersion = void 0;
|
||||
exports.pythonVersionToSemantic = exports.desugarVersion = exports.useCpythonVersion = void 0;
|
||||
const os = __importStar(__nccwpck_require__(2037));
|
||||
const path = __importStar(__nccwpck_require__(1017));
|
||||
const utils_1 = __nccwpck_require__(1314);
|
||||
|
@ -91038,9 +91038,8 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest
|
|||
return __awaiter(this, void 0, void 0, function* () {
|
||||
var _a;
|
||||
let manifest = null;
|
||||
const [desugaredVersionSpec, freethreaded] = desugarFreeThreadedVersion(version);
|
||||
const desugaredVersionSpec2 = desugarDevVersion(desugaredVersionSpec);
|
||||
let semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec2, allowPreReleases);
|
||||
const [desugaredVersionSpec, freethreaded] = desugarVersion(version);
|
||||
let semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec, allowPreReleases);
|
||||
core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
|
||||
if (freethreaded) {
|
||||
// Free threaded versions use an architecture suffix like `x64-freethreaded`
|
||||
|
@ -91121,14 +91120,21 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest
|
|||
});
|
||||
}
|
||||
exports.useCpythonVersion = useCpythonVersion;
|
||||
/* Identify freethreaded versions like, 3.13t, 3.13t-dev, 3.14.0a1t. Returns
|
||||
* the version without the `t` and the architectures suffix, if freethreaded */
|
||||
/* Desugar free threaded and dev versions */
|
||||
function desugarVersion(versionSpec) {
|
||||
const [desugaredVersionSpec, freethreaded] = desugarFreeThreadedVersion(versionSpec);
|
||||
const desugaredVersionSpec2 = desugarDevVersion(desugaredVersionSpec);
|
||||
return [desugaredVersionSpec2, 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;
|
||||
if (prereleaseVersion.test(versionSpec)) {
|
||||
return [versionSpec.replace(prereleaseVersion, '$1$3'), '-freethreaded'];
|
||||
}
|
||||
const majorMinor = /^(\d+\.\d+)(t)$/;
|
||||
const majorMinor = /^(\d+\.\d+(\.\d+)?)(t)$/;
|
||||
if (majorMinor.test(versionSpec)) {
|
||||
return [versionSpec.replace(majorMinor, '$1'), '-freethreaded'];
|
||||
}
|
||||
|
|
|
@ -38,11 +38,9 @@ export async function useCpythonVersion(
|
|||
allowPreReleases: boolean
|
||||
): Promise<InstalledVersion> {
|
||||
let manifest: tc.IToolRelease[] | null = null;
|
||||
const [desugaredVersionSpec, freethreaded] =
|
||||
desugarFreeThreadedVersion(version);
|
||||
const desugaredVersionSpec2 = desugarDevVersion(desugaredVersionSpec);
|
||||
const [desugaredVersionSpec, freethreaded] = desugarVersion(version);
|
||||
let semanticVersionSpec = pythonVersionToSemantic(
|
||||
desugaredVersionSpec2,
|
||||
desugaredVersionSpec,
|
||||
allowPreReleases
|
||||
);
|
||||
core.debug(`Semantic version spec of ${version} is ${semanticVersionSpec}`);
|
||||
|
@ -167,14 +165,22 @@ export async function useCpythonVersion(
|
|||
return {impl: 'CPython', version: installed};
|
||||
}
|
||||
|
||||
/* Identify freethreaded versions like, 3.13t, 3.13t-dev, 3.14.0a1t. Returns
|
||||
* the version without the `t` and the architectures suffix, if freethreaded */
|
||||
/* Desugar free threaded and dev versions */
|
||||
export function desugarVersion(versionSpec: string) {
|
||||
const [desugaredVersionSpec, freethreaded] =
|
||||
desugarFreeThreadedVersion(versionSpec);
|
||||
const desugaredVersionSpec2 = desugarDevVersion(desugaredVersionSpec);
|
||||
return [desugaredVersionSpec2, freethreaded];
|
||||
}
|
||||
|
||||
/* 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: string) {
|
||||
const prereleaseVersion = /(\d+\.\d+\.\d+)(t)((?:a|b|rc)\d*)/g;
|
||||
if (prereleaseVersion.test(versionSpec)) {
|
||||
return [versionSpec.replace(prereleaseVersion, '$1$3'), '-freethreaded'];
|
||||
}
|
||||
const majorMinor = /^(\d+\.\d+)(t)$/;
|
||||
const majorMinor = /^(\d+\.\d+(\.\d+)?)(t)$/;
|
||||
if (majorMinor.test(versionSpec)) {
|
||||
return [versionSpec.replace(majorMinor, '$1'), '-freethreaded'];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue