mirror of
https://code.forgejo.org/actions/setup-python
synced 2025-06-12 22:14:11 +02:00
Fix PyPy installation on Windows to adopt new parameters format (#201)
* test for pypy new version notation * formatting * uncommented condition * test * added pypy to test matrix * test * test * restored all tests * removed logs, added multiarch support for toolcache * reduced test matrix * removed extra condition about arch
This commit is contained in:
parent
a1121449a2
commit
dc73133d4d
6 changed files with 137 additions and 21 deletions
|
@ -2,6 +2,7 @@ import * as path from 'path';
|
|||
import * as pypyInstall from './install-pypy';
|
||||
import {
|
||||
IS_WINDOWS,
|
||||
WINDOWS_ARCHS,
|
||||
validateVersion,
|
||||
getPyPyVersionFromPath,
|
||||
readExactPyPyVersionFile,
|
||||
|
@ -27,11 +28,6 @@ export async function findPyPyVersion(
|
|||
|
||||
const pypyVersionSpec = parsePyPyVersion(versionSpec);
|
||||
|
||||
// PyPy only precompiles binaries for x86, but the architecture parameter defaults to x64.
|
||||
if (IS_WINDOWS && architecture === 'x64') {
|
||||
architecture = 'x86';
|
||||
}
|
||||
|
||||
({installDir, resolvedPythonVersion, resolvedPyPyVersion} = findPyPyToolCache(
|
||||
pypyVersionSpec.pythonVersion,
|
||||
pypyVersionSpec.pypyVersion,
|
||||
|
@ -67,7 +63,9 @@ export function findPyPyToolCache(
|
|||
) {
|
||||
let resolvedPyPyVersion = '';
|
||||
let resolvedPythonVersion = '';
|
||||
let installDir: string | null = tc.find('PyPy', pythonVersion, architecture);
|
||||
let installDir: string | null = IS_WINDOWS
|
||||
? findPyPyInstallDirForWindows(pythonVersion)
|
||||
: tc.find('PyPy', pythonVersion, architecture);
|
||||
|
||||
if (installDir) {
|
||||
// 'tc.find' finds tool based on Python version but we also need to check
|
||||
|
@ -129,3 +127,14 @@ export function parsePyPyVersion(versionSpec: string): IPyPyVersionSpec {
|
|||
pythonVersion: pythonVersion
|
||||
};
|
||||
}
|
||||
|
||||
export function findPyPyInstallDirForWindows(pythonVersion: string): string {
|
||||
let installDir = '';
|
||||
|
||||
WINDOWS_ARCHS.forEach(
|
||||
architecture =>
|
||||
(installDir = installDir || tc.find('PyPy', pythonVersion, architecture))
|
||||
);
|
||||
|
||||
return installDir;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ import fs from 'fs';
|
|||
|
||||
import {
|
||||
IS_WINDOWS,
|
||||
WINDOWS_ARCHS,
|
||||
WINDOWS_PLATFORMS,
|
||||
IPyPyManifestRelease,
|
||||
createSymlinkInFolder,
|
||||
isNightlyKeyword,
|
||||
|
@ -143,9 +145,9 @@ export function findRelease(
|
|||
semver.satisfies(pypyVersionToSemantic(item.pypy_version), pypyVersion);
|
||||
const isArchPresent =
|
||||
item.files &&
|
||||
item.files.some(
|
||||
file => file.arch === architecture && file.platform === process.platform
|
||||
);
|
||||
(IS_WINDOWS
|
||||
? isArchPresentForWindows(item)
|
||||
: isArchPresentForMacOrLinux(item, architecture, process.platform));
|
||||
return isPythonVersionSatisfied && isPyPyVersionSatisfied && isArchPresent;
|
||||
});
|
||||
|
||||
|
@ -167,9 +169,9 @@ export function findRelease(
|
|||
});
|
||||
|
||||
const foundRelease = sortedReleases[0];
|
||||
const foundAsset = foundRelease.files.find(
|
||||
item => item.arch === architecture && item.platform === process.platform
|
||||
);
|
||||
const foundAsset = IS_WINDOWS
|
||||
? findAssetForWindows(foundRelease)
|
||||
: findAssetForMacOrLinux(foundRelease, architecture, process.platform);
|
||||
|
||||
return {
|
||||
foundAsset,
|
||||
|
@ -191,3 +193,39 @@ export function pypyVersionToSemantic(versionSpec: string) {
|
|||
const prereleaseVersion = /(\d+\.\d+\.\d+)((?:a|b|rc))(\d*)/g;
|
||||
return versionSpec.replace(prereleaseVersion, '$1-$2.$3');
|
||||
}
|
||||
|
||||
export function isArchPresentForWindows(item: any) {
|
||||
return item.files.some(
|
||||
(file: any) =>
|
||||
WINDOWS_ARCHS.includes(file.arch) &&
|
||||
WINDOWS_PLATFORMS.includes(file.platform)
|
||||
);
|
||||
}
|
||||
|
||||
export function isArchPresentForMacOrLinux(
|
||||
item: any,
|
||||
architecture: string,
|
||||
platform: string
|
||||
) {
|
||||
return item.files.some(
|
||||
(file: any) => file.arch === architecture && file.platform === platform
|
||||
);
|
||||
}
|
||||
|
||||
export function findAssetForWindows(releases: any) {
|
||||
return releases.files.find(
|
||||
(item: any) =>
|
||||
WINDOWS_ARCHS.includes(item.arch) &&
|
||||
WINDOWS_PLATFORMS.includes(item.platform)
|
||||
);
|
||||
}
|
||||
|
||||
export function findAssetForMacOrLinux(
|
||||
releases: any,
|
||||
architecture: string,
|
||||
platform: string
|
||||
) {
|
||||
return releases.files.find(
|
||||
(item: any) => item.arch === architecture && item.platform === platform
|
||||
);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import * as semver from 'semver';
|
|||
|
||||
export const IS_WINDOWS = process.platform === 'win32';
|
||||
export const IS_LINUX = process.platform === 'linux';
|
||||
export const WINDOWS_ARCHS = ['x86', 'x64'];
|
||||
export const WINDOWS_PLATFORMS = ['win32', 'win64'];
|
||||
const PYPY_VERSION_FILE = 'PYPY_VERSION';
|
||||
|
||||
export interface IPyPyManifestAsset {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue