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

Add GraalPy support #694

Merged
merged 18 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Extract common getBinaryDirectory function for PyPy and GraalPy
  • Loading branch information
msimacek committed Aug 29, 2023
commit 08f6b9181b8faf4b1eb3da89b907d18c59c53e2c
9 changes: 7 additions & 2 deletions src/find-graalpy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import * as path from 'path';
import * as graalpyInstall from './install-graalpy';
import {IS_WINDOWS, validateVersion, IGraalPyManifestRelease} from './utils';
import {
IS_WINDOWS,
validateVersion,
IGraalPyManifestRelease,
getBinaryDirectory
} from './utils';

import * as semver from 'semver';
import * as core from '@actions/core';
Expand Down Expand Up @@ -61,7 +66,7 @@ export async function findGraalPyVersion(
IS_WINDOWS ? installDir : _binDir,
`python${binaryExtension}`
);
const pythonLocation = graalpyInstall.getGraalPyBinaryPath(installDir);
const pythonLocation = getBinaryDirectory(installDir);
if (updateEnvironment) {
core.exportVariable('pythonLocation', installDir);
// https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython
Expand Down
5 changes: 3 additions & 2 deletions src/find-pypy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
getPyPyVersionFromPath,
readExactPyPyVersionFile,
validatePythonVersionFormatForPyPy,
IPyPyManifestRelease
IPyPyManifestRelease,
getBinaryDirectory
} from './utils';

import * as semver from 'semver';
Expand Down Expand Up @@ -82,7 +83,7 @@ export async function findPyPyVersion(
IS_WINDOWS ? installDir : _binDir,
`python${binaryExtension}`
);
const pythonLocation = pypyInstall.getPyPyBinaryPath(installDir);
const pythonLocation = getBinaryDirectory(installDir);
if (updateEnvironment) {
core.exportVariable('pythonLocation', installDir);
// https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython
Expand Down
20 changes: 6 additions & 14 deletions src/install-graalpy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
IGraalPyManifestAsset,
IGraalPyManifestRelease,
createSymlinkInFolder,
isNightlyKeyword
isNightlyKeyword,
getBinaryDirectory
} from './utils';

export async function installGraalPy(
Expand All @@ -25,7 +26,7 @@ export async function installGraalPy(

releases = releases ?? (await getAvailableGraalPyVersions());

if (!releases || releases.length === 0) {
if (!releases || !releases.length) {
throw new Error('No release was found in GraalPy version.json');
}

Expand Down Expand Up @@ -74,7 +75,7 @@ export async function installGraalPy(
);
}

const binaryPath = getGraalPyBinaryPath(installDir);
const binaryPath = getBinaryDirectory(installDir);
await createGraalPySymlink(binaryPath, resolvedGraalPyVersion);
await installPip(binaryPath);

Expand Down Expand Up @@ -183,7 +184,7 @@ export function findRelease(
);
});

if (filterReleases.length === 0) {
if (!filterReleases.length) {
return null;
}

Expand All @@ -209,15 +210,6 @@ export function findRelease(
};
}

/** Get GraalPy binary location from the tool of installation directory
* - On Linux and macOS, the Python interpreter is in 'bin'.
* - On Windows, it is in the installation root.
*/
export function getGraalPyBinaryPath(installDir: string) {
const _binDir = path.join(installDir, 'bin');
return IS_WINDOWS ? installDir : _binDir;
}

export function findAsset(
item: IGraalPyManifestRelease,
architecture: string,
Expand All @@ -235,7 +227,7 @@ export function findAsset(
: platform === 'darwin'
? 'macos'
: platform;
if (item.assets) {
if (item.assets.length) {
return item.assets.find((file: IGraalPyManifestAsset) => {
const match_data = file.name.match(
'.*(macos|linux|windows)-(amd64|aarch64).tar.gz$'
Expand Down
14 changes: 3 additions & 11 deletions src/install-pypy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
IPyPyManifestRelease,
createSymlinkInFolder,
isNightlyKeyword,
writeExactPyPyVersionFile
writeExactPyPyVersionFile,
getBinaryDirectory
} from './utils';

export async function installPyPy(
Expand Down Expand Up @@ -94,7 +95,7 @@ export async function installPyPy(

writeExactPyPyVersionFile(installDir, resolvedPyPyVersion);

const binaryPath = getPyPyBinaryPath(installDir);
const binaryPath = getBinaryDirectory(installDir);
await createPyPySymlink(binaryPath, resolvedPythonVersion);
await installPip(binaryPath);

Expand Down Expand Up @@ -237,15 +238,6 @@ export function findRelease(
};
}

/** Get PyPy binary location from the tool of installation directory
* - On Linux and macOS, the Python interpreter is in 'bin'.
* - On Windows, it is in the installation root.
*/
export function getPyPyBinaryPath(installDir: string) {
const _binDir = path.join(installDir, 'bin');
return IS_WINDOWS ? installDir : _binDir;
}

export function pypyVersionToSemantic(versionSpec: string) {
const prereleaseVersion = /(\d+\.\d+\.\d+)((?:a|b|rc))(\d*)/g;
return versionSpec.replace(prereleaseVersion, '$1-$2.$3');
Expand Down
9 changes: 9 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,12 @@ export function getVersionInputFromFile(versionFile: string): string[] {
return getVersionInputFromPlainFile(versionFile);
}
}

/**
* Get the directory containing interpreter binary from installation directory of PyPy or GraalPy
* - On Linux and macOS, the Python interpreter is in 'bin'.
* - On Windows, it is in the installation root.
*/
export function getBinaryDirectory(installDir: string) {
return IS_WINDOWS ? installDir : path.join(installDir, 'bin');
}