mirror of
https://github.com/actions/setup-python.git
synced 2025-04-21 17:23:52 +00:00
Extract common getBinaryDirectory function for PyPy and GraalPy
This commit is contained in:
parent
fb2947352f
commit
08f6b9181b
@ -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';
|
||||
@ -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
|
||||
|
@ -7,7 +7,8 @@ import {
|
||||
getPyPyVersionFromPath,
|
||||
readExactPyPyVersionFile,
|
||||
validatePythonVersionFormatForPyPy,
|
||||
IPyPyManifestRelease
|
||||
IPyPyManifestRelease,
|
||||
getBinaryDirectory
|
||||
} from './utils';
|
||||
|
||||
import * as semver from 'semver';
|
||||
@ -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
|
||||
|
@ -12,7 +12,8 @@ import {
|
||||
IGraalPyManifestAsset,
|
||||
IGraalPyManifestRelease,
|
||||
createSymlinkInFolder,
|
||||
isNightlyKeyword
|
||||
isNightlyKeyword,
|
||||
getBinaryDirectory
|
||||
} from './utils';
|
||||
|
||||
export async function installGraalPy(
|
||||
@ -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');
|
||||
}
|
||||
|
||||
@ -74,7 +75,7 @@ export async function installGraalPy(
|
||||
);
|
||||
}
|
||||
|
||||
const binaryPath = getGraalPyBinaryPath(installDir);
|
||||
const binaryPath = getBinaryDirectory(installDir);
|
||||
await createGraalPySymlink(binaryPath, resolvedGraalPyVersion);
|
||||
await installPip(binaryPath);
|
||||
|
||||
@ -183,7 +184,7 @@ export function findRelease(
|
||||
);
|
||||
});
|
||||
|
||||
if (filterReleases.length === 0) {
|
||||
if (!filterReleases.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -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,
|
||||
@ -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$'
|
||||
|
@ -13,7 +13,8 @@ import {
|
||||
IPyPyManifestRelease,
|
||||
createSymlinkInFolder,
|
||||
isNightlyKeyword,
|
||||
writeExactPyPyVersionFile
|
||||
writeExactPyPyVersionFile,
|
||||
getBinaryDirectory
|
||||
} from './utils';
|
||||
|
||||
export async function installPyPy(
|
||||
@ -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);
|
||||
|
||||
@ -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');
|
||||
|
@ -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');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user