Fix desugaring of 3.13.1t and add test case.

This commit is contained in:
Sam Gross 2025-01-22 20:22:49 +00:00
parent c70f76ebc5
commit d653c0b66e
3 changed files with 44 additions and 14 deletions

View 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
View file

@ -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'];
}

View file

@ -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'];
}