8000 Adding support for more PyPy versions and installing them on-flight by dmitry-shibanov · Pull Request #168 · actions/setup-python · GitHub
[go: up one dir, main page]

Skip to content

Adding support for more PyPy versions and installing them on-flight #168

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

Merged
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
add pypy tests and fix issue with pypy-3-nightly
  • Loading branch information
dmitry-shibanov committed Dec 17, 2020
commit 0c8eaf819ea8152306b5e6aa2e218db32b3f488f
27 changes: 8 additions & 19 deletions __tests__/find-pypy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,6 @@ describe('parsePyPyVersion', () => {
});
});

describe('validateVersion', () => {
it.each([
['v7.3.3', true],
['v7.3.x', true],
['v7.x', true],
['x', true],
['v7.3.3-rc.1', true],
['nightly', true],
['v7.3.b', false],
['3.6', true],
['3.b', false],
['3', true]
])('%s -> %s', (input, expected) => {
expect(validateVersion(input)).toEqual(expected);
});
});

describe('getPyPyVersionFromPath', () => {
it('/fake/toolcache/PyPy/3.6.5/x64 -> 3.6.5', () => {
expect(getPyPyVersionFromPath('/fake/toolcache/PyPy/3.6.5/x64')).toEqual(
Expand Down Expand Up @@ -223,6 +206,12 @@ describe('findPyPyVersion', () => {
).rejects.toThrow();
});

it('throw on invalid input format pypy3.7-7.3.x', async () => {
await expect(
finder.findPyPyVersion('pypy3.7-v7.3.x', architecture)
).rejects.toThrow();
});

it('found and install successfully', async () => {
spyCacheDir = jest.spyOn(tc, 'cacheDir');
spyCacheDir.mockImplementation(() =>
Expand All @@ -240,9 +229,9 @@ describe('findPyPyVersion', () => {

it('throw if release is not found', async () => {
await expect(
finder.findPyPyVersion('pypy3.7-v7.3.x', architecture)
finder.findPyPyVersion('pypy-3.7-v7.5.x', architecture)
).rejects.toThrowError(
"Invalid 'version' property for PyPy. PyPy version should be specified as 'pypy-<python-version>'. See README for examples and documentation."
`PyPy version 3.7 (v7.5.x) with arch ${architecture} not found`
);
});
});
34 changes: 34 additions & 0 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {
validateVersion,
validatePythonVersionFormatForPyPy
} from '../src/utils';

describe('validatePythonVersionFormatForPyPy', () => {
it.each([
['3.6', true],
['3.7', true],
['3.6.x', false],
['3.7.x', false],
['3.x', false],
['3', false]
])('%s -> %s', (input, expected) => {
expect(validatePythonVersionFormatForPyPy(input)).toEqual(expected);
});
});

describe('validateVersion', () => {
it.each([
['v7.3.3', true],
['v7.3.x', true],
['v7.x', true],
['x', true],
['v7.3.3-rc.1', true],
['nightly', true],
['v7.3.b', false],
['3.6', true],
['3.b', false],
['3', true]
])('%s -> %s', (input, expected) => {
expect(validateVersion(input)).toEqual(expected);
});
});
13 changes: 13 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,9 @@ function parsePyPyVersion(versionSpec) {
if (!utils_1.validateVersion(pythonVersion) || !utils_1.validateVersion(pypyVersion)) {
throw new Error("Invalid 'version' property for PyPy. Both Python version and PyPy versions should satisfy SemVer notation. See README for examples and documentation.");
}
if (!utils_1.validatePythonVersionFormatForPyPy(pythonVersion)) {
throw new Error("Invalid format of Python version for PyPy. Python version should be specified in format 'x.y'. See README for examples and documentation.");
}
return {
pypyVersion: pypyVersion,
pythonVersion: pythonVersion
Expand Down Expand Up @@ -2375,6 +2378,16 @@ function writeExactPyPyVersionFile(installDir, resolvedPyPyVersion) {
fs_1.default.writeFileSync(pypyFilePath, resolvedPyPyVersion);
}
exports.writeExactPyPyVersionFile = writeExactPyPyVersionFile;
/**
* Python version should be specified explicitly like "x.y" (2.7, 3.6, 3.7)
* "3.x" or "3" are not supported
* because it could cause ambiguity when both PyPy version and Python version are not precise
*/
function validatePythonVersionFormatForPyPy(version) {
const re = /^\d+\.\d+$/;
return re.test(version);
}
exports.validatePythonVersionFormatForPyPy = validatePythonVersionFormatForPyPy;


/***/ }),
Expand Down
9 changes: 8 additions & 1 deletion src/find-pypy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
IS_WINDOWS,
validateVersion,
getPyPyVersionFromPath,
readExactPyPyVersionFile
readExactPyPyVersionFile,
validatePythonVersionFormatForPyPy
} from './utils';

import * as semver from 'semver';
Expand Down Expand Up @@ -117,6 +118,12 @@ export function parsePyPyVersion(versionSpec: string): IPyPyVersionSpec {
);
}

if (!validatePythonVersionFormatForPyPy(pythonVersion)) {
throw new Error(
"Invalid format of Python version for PyPy. Python version should be specified in format 'x.y'. See README for examples and documentation."
);
}

return {
pypyVersion: pypyVersion,
pythonVersion: pythonVersion
Expand Down
10 changes: 10 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,13 @@ export function writeExactPyPyVersionFile(
const pypyFilePath = path.join(installDir, PYPY_VERSION_FILE);
fs.writeFileSync(pypyFilePath, resolvedPyPyVersion);
}

/**
* Python version should be specified explicitly like "x.y" (2.7, 3.6, 3.7)
* "3.x" or "3" are not supported
* because it could cause ambiguity when both PyPy version and Python version are not precise
*/
export function validatePythonVersionFormatForPyPy(version: string) {
const re = /^\d+\.\d+$/;
return re.test(version);
}
0