Skip to content

Commit

Permalink
Merge pull request #1 from colesbury/quansight
Browse files Browse the repository at this point in the history
Support free threaded Python versions like '3.13t'
  • Loading branch information
andfoy authored Nov 5, 2024
2 parents 55aad42 + 079f76b commit b9ab292
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
29 changes: 26 additions & 3 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 Expand Up @@ -91629,7 +91652,7 @@ const httpm = __importStar(__nccwpck_require__(6255));
const utils_1 = __nccwpck_require__(1314);
const TOKEN = core.getInput('token');
const AUTH = !TOKEN ? undefined : `token ${TOKEN}`;
const MANIFEST_REPO_OWNER = 'actions';
const MANIFEST_REPO_OWNER = 'Quansight-Labs';
const MANIFEST_REPO_NAME = 'python-versions';
const MANIFEST_REPO_BRANCH = 'main';
exports.MANIFEST_URL = `https://raw.githubusercontent.com/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/${MANIFEST_REPO_BRANCH}/versions-manifest.json`;
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
2 changes: 1 addition & 1 deletion src/install-python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {IS_WINDOWS, IS_LINUX, getDownloadFileName} from './utils';

const TOKEN = core.getInput('token');
const AUTH = !TOKEN ? undefined : `token ${TOKEN}`;
const MANIFEST_REPO_OWNER = 'actions';
const MANIFEST_REPO_OWNER = 'Quansight-Labs';
const MANIFEST_REPO_NAME = 'python-versions';
const MANIFEST_REPO_BRANCH = 'main';
export const MANIFEST_URL = `https://raw.githubusercontent.com/${MANIFEST_REPO_OWNER}/${MANIFEST_REPO_NAME}/${MANIFEST_REPO_BRANCH}/versions-manifest.json`;
Expand Down

0 comments on commit b9ab292

Please sign in to comment.