diff --git a/__tests__/find-python.test.ts b/__tests__/find-python.test.ts new file mode 100644 index 00000000..e779a7a2 --- /dev/null +++ b/__tests__/find-python.test.ts @@ -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); + }); +}); diff --git a/dist/setup/index.js b/dist/setup/index.js index 97b5e5ce..a0bed3bf 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -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']; } diff --git a/src/find-python.ts b/src/find-python.ts index 3c2b8b13..6685d060 100644 --- a/src/find-python.ts +++ b/src/find-python.ts @@ -38,11 +38,9 @@ export async function useCpythonVersion( allowPreReleases: boolean ): Promise { 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']; }