Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support free threaded Python versions like '3.13t' #973

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91038,9 +91038,15 @@ function useCpythonVersion(version, architecture, updateEnvironment, checkLatest
return __awaiter(this, void 0, void 0, function* () {
var _a;
let manifest = null;
const desugaredVersionSpec = desugarDevVersion(version);
let semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec, allowPreReleases);
const [desugaredVersionSpec, freethreaded] = desugarFreeThreadedVersion(version);
const desugaredVersionSpec2 = desugarDevVersion(desugaredVersionSpec);
let semanticVersionSpec = pythonVersionToSemantic(desugaredVersionSpec2, allowPreReleases);
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;
}
if (checkLatest) {
manifest = yield installer.getManifest();
const resolvedVersion = (_a = (yield installer.findReleaseFromManifest(semanticVersionSpec, architecture, manifest))) === null || _a === void 0 ? void 0 : _a.version;
Expand Down Expand Up @@ -91115,6 +91121,23 @@ 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 */
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)$/;
if (majorMinor.test(versionSpec)) {
return [versionSpec.replace(majorMinor, '$1'), '-freethreaded'];
}
const devVersion = /^(\d+\.\d+)(t)(-dev)$/;
if (devVersion.test(versionSpec)) {
return [versionSpec.replace(devVersion, '$1$3'), '-freethreaded'];
}
return [versionSpec, ''];
}
/** Convert versions like `3.8-dev` to a version like `~3.8.0-0`. */
function desugarDevVersion(versionSpec) {
const devVersion = /^(\d+)\.(\d+)-dev$/;
Expand Down
30 changes: 28 additions & 2 deletions src/find-python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,21 @@ export async function useCpythonVersion(
allowPreReleases: boolean
): Promise<InstalledVersion> {
let manifest: tc.IToolRelease[] | null = null;
const desugaredVersionSpec = desugarDevVersion(version);
const [desugaredVersionSpec, freethreaded] =
desugarFreeThreadedVersion(version);
const desugaredVersionSpec2 = desugarDevVersion(desugaredVersionSpec);
let semanticVersionSpec = pythonVersionToSemantic(
desugaredVersionSpec,
desugaredVersionSpec2,
allowPreReleases
);
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;
}

if (checkLatest) {
manifest = await installer.getManifest();
const resolvedVersion = (
Expand Down Expand Up @@ -159,6 +167,24 @@ 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 */
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)$/;
if (majorMinor.test(versionSpec)) {
return [versionSpec.replace(majorMinor, '$1'), '-freethreaded'];
}
const devVersion = /^(\d+\.\d+)(t)(-dev)$/;
if (devVersion.test(versionSpec)) {
return [versionSpec.replace(devVersion, '$1$3'), '-freethreaded'];
}
return [versionSpec, ''];
}

/** Convert versions like `3.8-dev` to a version like `~3.8.0-0`. */
function desugarDevVersion(versionSpec: string) {
const devVersion = /^(\d+)\.(\d+)-dev$/;
Expand Down