mirror of
https://github.com/actions/setup-python.git
synced 2025-04-24 23:42:13 +00:00
Extract common getBinaryDirectory function for PyPy and GraalPy
This commit is contained in:
parent
fb2947352f
commit
08f6b9181b
5 changed files with 28 additions and 29 deletions
|
@ -1,6 +1,11 @@
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as graalpyInstall from './install-graalpy';
|
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 semver from 'semver';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
|
@ -61,7 +66,7 @@ export async function findGraalPyVersion(
|
||||||
IS_WINDOWS ? installDir : _binDir,
|
IS_WINDOWS ? installDir : _binDir,
|
||||||
`python${binaryExtension}`
|
`python${binaryExtension}`
|
||||||
);
|
);
|
||||||
const pythonLocation = graalpyInstall.getGraalPyBinaryPath(installDir);
|
const pythonLocation = getBinaryDirectory(installDir);
|
||||||
if (updateEnvironment) {
|
if (updateEnvironment) {
|
||||||
core.exportVariable('pythonLocation', installDir);
|
core.exportVariable('pythonLocation', installDir);
|
||||||
// https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython
|
// https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython
|
||||||
|
|
|
@ -7,7 +7,8 @@ import {
|
||||||
getPyPyVersionFromPath,
|
getPyPyVersionFromPath,
|
||||||
readExactPyPyVersionFile,
|
readExactPyPyVersionFile,
|
||||||
validatePythonVersionFormatForPyPy,
|
validatePythonVersionFormatForPyPy,
|
||||||
IPyPyManifestRelease
|
IPyPyManifestRelease,
|
||||||
|
getBinaryDirectory
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
|
@ -82,7 +83,7 @@ export async function findPyPyVersion(
|
||||||
IS_WINDOWS ? installDir : _binDir,
|
IS_WINDOWS ? installDir : _binDir,
|
||||||
`python${binaryExtension}`
|
`python${binaryExtension}`
|
||||||
);
|
);
|
||||||
const pythonLocation = pypyInstall.getPyPyBinaryPath(installDir);
|
const pythonLocation = getBinaryDirectory(installDir);
|
||||||
if (updateEnvironment) {
|
if (updateEnvironment) {
|
||||||
core.exportVariable('pythonLocation', installDir);
|
core.exportVariable('pythonLocation', installDir);
|
||||||
// https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython
|
// https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython
|
||||||
|
|
|
@ -12,7 +12,8 @@ import {
|
||||||
IGraalPyManifestAsset,
|
IGraalPyManifestAsset,
|
||||||
IGraalPyManifestRelease,
|
IGraalPyManifestRelease,
|
||||||
createSymlinkInFolder,
|
createSymlinkInFolder,
|
||||||
isNightlyKeyword
|
isNightlyKeyword,
|
||||||
|
getBinaryDirectory
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
export async function installGraalPy(
|
export async function installGraalPy(
|
||||||
|
@ -25,7 +26,7 @@ export async function installGraalPy(
|
||||||
|
|
||||||
releases = releases ?? (await getAvailableGraalPyVersions());
|
releases = releases ?? (await getAvailableGraalPyVersions());
|
||||||
|
|
||||||
if (!releases || releases.length === 0) {
|
if (!releases || !releases.length) {
|
||||||
throw new Error('No release was found in GraalPy version.json');
|
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 createGraalPySymlink(binaryPath, resolvedGraalPyVersion);
|
||||||
await installPip(binaryPath);
|
await installPip(binaryPath);
|
||||||
|
|
||||||
|
@ -183,7 +184,7 @@ export function findRelease(
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (filterReleases.length === 0) {
|
if (!filterReleases.length) {
|
||||||
return null;
|
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(
|
export function findAsset(
|
||||||
item: IGraalPyManifestRelease,
|
item: IGraalPyManifestRelease,
|
||||||
architecture: string,
|
architecture: string,
|
||||||
|
@ -235,7 +227,7 @@ export function findAsset(
|
||||||
: platform === 'darwin'
|
: platform === 'darwin'
|
||||||
? 'macos'
|
? 'macos'
|
||||||
: platform;
|
: platform;
|
||||||
if (item.assets) {
|
if (item.assets.length) {
|
||||||
return item.assets.find((file: IGraalPyManifestAsset) => {
|
return item.assets.find((file: IGraalPyManifestAsset) => {
|
||||||
const match_data = file.name.match(
|
const match_data = file.name.match(
|
||||||
'.*(macos|linux|windows)-(amd64|aarch64).tar.gz$'
|
'.*(macos|linux|windows)-(amd64|aarch64).tar.gz$'
|
||||||
|
|
|
@ -13,7 +13,8 @@ import {
|
||||||
IPyPyManifestRelease,
|
IPyPyManifestRelease,
|
||||||
createSymlinkInFolder,
|
createSymlinkInFolder,
|
||||||
isNightlyKeyword,
|
isNightlyKeyword,
|
||||||
writeExactPyPyVersionFile
|
writeExactPyPyVersionFile,
|
||||||
|
getBinaryDirectory
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
export async function installPyPy(
|
export async function installPyPy(
|
||||||
|
@ -94,7 +95,7 @@ export async function installPyPy(
|
||||||
|
|
||||||
writeExactPyPyVersionFile(installDir, resolvedPyPyVersion);
|
writeExactPyPyVersionFile(installDir, resolvedPyPyVersion);
|
||||||
|
|
||||||
const binaryPath = getPyPyBinaryPath(installDir);
|
const binaryPath = getBinaryDirectory(installDir);
|
||||||
await createPyPySymlink(binaryPath, resolvedPythonVersion);
|
await createPyPySymlink(binaryPath, resolvedPythonVersion);
|
||||||
await installPip(binaryPath);
|
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) {
|
export function pypyVersionToSemantic(versionSpec: string) {
|
||||||
const prereleaseVersion = /(\d+\.\d+\.\d+)((?:a|b|rc))(\d*)/g;
|
const prereleaseVersion = /(\d+\.\d+\.\d+)((?:a|b|rc))(\d*)/g;
|
||||||
return versionSpec.replace(prereleaseVersion, '$1-$2.$3');
|
return versionSpec.replace(prereleaseVersion, '$1-$2.$3');
|
||||||
|
|
|
@ -262,3 +262,12 @@ export function getVersionInputFromFile(versionFile: string): string[] {
|
||||||
return getVersionInputFromPlainFile(versionFile);
|
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…
Add table
Reference in a new issue