Skip to content

Commit fff15a2

Browse files
authored
Use pypyX.Y for PyPy python-version input (#349)
This versioning scheme is consistent with other tools in the python ecosystem so it feels more natural and allows better interaction with other tools. fixes #346
1 parent c57f793 commit fff15a2

File tree

6 files changed

+54
-25
lines changed

6 files changed

+54
-25
lines changed

.github/workflows/test-pypy.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ jobs:
2222
pypy:
2323
- 'pypy-2.7'
2424
- 'pypy-3.7'
25+
- 'pypy3.9'
2526
- 'pypy-2.7-v7.3.4'
2627
- 'pypy-3.7-v7.3.5'
2728
- 'pypy-3.7-v7.3.4'
2829
- 'pypy-3.7-v7.3.x'
2930
- 'pypy-3.7-v7.x'
3031
- 'pypy-2.7-v7.3.4rc1'
3132
- 'pypy-3.7-nightly'
33+
- 'pypy3.8-v7.3.7'
3234

3335
steps:
3436
- name: Checkout
@@ -54,7 +56,7 @@ jobs:
5456
- name: Assert expected binaries (or symlinks) are present
5557
run: |
5658
EXECUTABLE=${{ matrix.pypy }}
57-
EXECUTABLE=${EXECUTABLE/-/} # remove the first '-' in "pypy-X.Y" -> "pypyX.Y" to match executable name
59+
EXECUTABLE=${EXECUTABLE/pypy-/pypy} # remove the first '-' in "pypy-X.Y" -> "pypyX.Y" to match executable name
5860
EXECUTABLE=${EXECUTABLE%%-*} # remove any -* suffixe
5961
${EXECUTABLE} --version
6062
shell: bash

README.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
runs-on: ubuntu-latest
4444
strategy:
4545
matrix:
46-
python-version: [ '2.x', '3.x', 'pypy-2.7', 'pypy-3.7', 'pypy-3.8' ]
46+
python-version: [ '2.x', '3.x', 'pypy2.7', 'pypy3.7', 'pypy3.8' ]
4747
name: Python ${{ matrix.python-version }} sample
4848
steps:
4949
- uses: actions/checkout@v3
@@ -63,7 +63,7 @@ jobs:
6363
strategy:
6464
matrix:
6565
os: [ubuntu-latest, macos-latest, windows-latest]
66-
python-version: ['2.7', '3.7', '3.8', '3.9', '3.10', 'pypy-2.7', 'pypy-3.8']
66+
python-version: ['2.7', '3.7', '3.8', '3.9', '3.10', 'pypy2.7', 'pypy3.8']
6767
exclude:
6868
- os: macos-latest
6969
python-version: '3.8'
@@ -125,9 +125,9 @@ jobs:
125125
strategy:
126126
matrix:
127127
python-version:
128-
- 'pypy-3.7' # the latest available version of PyPy that supports Python 3.7
129-
- 'pypy-3.7-v7.3.3' # Python 3.7 and PyPy 7.3.3
130-
- 'pypy-3.8' # the latest available version of PyPy that supports Python 3.8
128+
- 'pypy3.7' # the latest available version of PyPy that supports Python 3.7
129+
- 'pypy3.7-v7.3.3' # Python 3.7 and PyPy 7.3.3
130+
- 'pypy3.8' # the latest available version of PyPy that supports Python 3.8
131131
steps:
132132
- uses: actions/checkout@v3
133133
- uses: actions/setup-python@v3
@@ -164,7 +164,7 @@ Check out our detailed guide on using [Python with GitHub Actions](https://help.
164164
- Preinstalled versions of PyPy in the tools cache on GitHub-hosted runners
165165
- For detailed information regarding the available versions of PyPy that are installed, see [Supported software](https://docs.github.com/en/actions/reference/specifications-for-github-hosted-runners#supported-software).
166166
- For the latest PyPy release, all versions of Python are cached.
167-
- Cache is updated with a 1-2 week delay. If you specify the PyPy version as `pypy-3.7`, the cached version will be used although a newer version is available. If you need to start using the recently released version right after release, you should specify the exact PyPy version using `pypy-3.7-v7.3.3`.
167+
- Cache is updated with a 1-2 week delay. If you specify the PyPy version as `pypy3.7` or `pypy-3.7`, the cached version will be used although a newer version is available. If you need to start using the recently released version right after release, you should specify the exact PyPy version using `pypy3.7-v7.3.3` or `pypy-3.7-v7.3.3`.
168168

169169
- Downloadable PyPy versions from the [official PyPy site](https://downloads.python.org/pypy/).
170170
- All available versions that we can download are listed in [versions.json](https://downloads.python.org/pypy/versions.json) file.
@@ -197,17 +197,17 @@ You should specify only a major and minor version if you are okay with the most
197197
- Using the most recent patch version will result in a very quick setup since no downloads will be required since a locally installed version Python on the runner will be used.
198198

199199
# Specifying a PyPy version
200-
The version of PyPy should be specified in the format `pypy-<python_version>[-v<pypy_version>]`.
200+
The version of PyPy should be specified in the format `pypy<python_version>[-v<pypy_version>]` or `pypy-<python_version>[-v<pypy_version>]`.
201201
The `<pypy_version>` parameter is optional and can be skipped. The latest version will be used in this case.
202202

203203
```
204-
pypy-3.7 # the latest available version of PyPy that supports Python 3.7
205-
pypy-3.8 # the latest available version of PyPy that supports Python 3.8
206-
pypy-2.7 # the latest available version of PyPy that supports Python 2.7
207-
pypy-3.7-v7.3.3 # Python 3.7 and PyPy 7.3.3
208-
pypy-3.7-v7.x # Python 3.7 and the latest available PyPy 7.x
209-
pypy-3.7-v7.3.3rc1 # Python 3.7 and preview version of PyPy
210-
pypy-3.7-nightly # Python 3.7 and nightly PyPy
204+
pypy3.7 or pypy-3.7 # the latest available version of PyPy that supports Python 3.7
205+
pypy3.8 or pypy-3.8 # the latest available version of PyPy that supports Python 3.8
206+
pypy2.7 or pypy-2.7 # the latest available version of PyPy that supports Python 2.7
207+
pypy3.7-v7.3.3 or pypy-3.7-v7.3.3 # Python 3.7 and PyPy 7.3.3
208+
pypy3.7-v7.x or pypy-3.7-v7.x # Python 3.7 and the latest available PyPy 7.x
209+
pypy3.7-v7.3.3rc1 or pypy-3.7-v7.3.3rc1 # Python 3.7 and preview version of PyPy
210+
pypy3.7-nightly or pypy-3.7-nightly # Python 3.7 and nightly PyPy
211211
```
212212
213213
# Caching packages dependencies

__tests__/find-pypy.test.ts

+24-6
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,34 @@ describe('parsePyPyVersion', () => {
3737
['pypy-3.6-v7.x', {pythonVersion: '3.6', pypyVersion: 'v7.x'}],
3838
['pypy-3.6', {pythonVersion: '3.6', pypyVersion: 'x'}],
3939
['pypy-3.6-nightly', {pythonVersion: '3.6', pypyVersion: 'nightly'}],
40-
['pypy-3.6-v7.3.3rc1', {pythonVersion: '3.6', pypyVersion: 'v7.3.3-rc.1'}]
40+
['pypy-3.6-v7.3.3rc1', {pythonVersion: '3.6', pypyVersion: 'v7.3.3-rc.1'}],
41+
['pypy3.8-v7.3.7', {pythonVersion: '3.8', pypyVersion: 'v7.3.7'}],
42+
['pypy3.8-v7.3.x', {pythonVersion: '3.8', pypyVersion: 'v7.3.x'}],
43+
['pypy3.8-v7.x', {pythonVersion: '3.8', pypyVersion: 'v7.x'}],
44+
['pypy3.8', {pythonVersion: '3.8', pypyVersion: 'x'}],
45+
['pypy3.9-nightly', {pythonVersion: '3.9', pypyVersion: 'nightly'}],
46+
['pypy3.9-v7.3.8rc1', {pythonVersion: '3.9', pypyVersion: 'v7.3.8-rc.1'}]
4147
])('%s -> %s', (input, expected) => {
4248
expect(finder.parsePyPyVersion(input)).toEqual(expected);
4349
});
4450

45-
it('throw on invalid input', () => {
46-
expect(() => finder.parsePyPyVersion('pypy-')).toThrowError(
47-
"Invalid 'version' property for PyPy. PyPy version should be specified as 'pypy-<python-version>'. See README for examples and documentation."
48-
);
49-
});
51+
it.each(['', 'pypy-', 'pypy', 'p', 'notpypy-'])(
52+
'throw on invalid input "%s"',
53+
input => {
54+
expect(() => finder.parsePyPyVersion(input)).toThrowError(
55+
"Invalid 'version' property for PyPy. PyPy version should be specified as 'pypy<python-version>' or 'pypy-<python-version>'. See README for examples and documentation."
56+
);
57+
}
58+
);
59+
60+
it.each(['pypy-2', 'pypy-3', 'pypy2', 'pypy3', 'pypy3.x', 'pypy3.8.10'])(
61+
'throw on invalid input "%s"',
62+
input => {
63+
expect(() => finder.parsePyPyVersion(input)).toThrowError(
64+
"Invalid format of Python version for PyPy. Python version should be specified in format 'x.y'. See README for examples and documentation."
65+
);
66+
}
67+
);
5068
});
5169

5270
describe('getPyPyVersionFromPath', () => {

dist/setup/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -6073,7 +6073,7 @@ const os = __importStar(__webpack_require__(87));
60736073
const cache_factory_1 = __webpack_require__(633);
60746074
const utils_1 = __webpack_require__(163);
60756075
function isPyPyVersion(versionSpec) {
6076-
return versionSpec.startsWith('pypy-');
6076+
return versionSpec.startsWith('pypy');
60776077
}
60786078
function cacheDependencies(cache, pythonVersion) {
60796079
return __awaiter(this, void 0, void 0, function* () {
@@ -52411,8 +52411,12 @@ function findPyPyToolCache(pythonVersion, pypyVersion, architecture) {
5241152411
exports.findPyPyToolCache = findPyPyToolCache;
5241252412
function parsePyPyVersion(versionSpec) {
5241352413
const versions = versionSpec.split('-').filter(item => !!item);
52414+
if (/^(pypy)(.+)/.test(versions[0])) {
52415+
let pythonVersion = versions[0].replace('pypy', '');
52416+
versions.splice(0, 1, 'pypy', pythonVersion);
52417+
}
5241452418
if (versions.length < 2 || versions[0] != 'pypy') {
52415-
throw new Error("Invalid 'version' property for PyPy. PyPy version should be specified as 'pypy-<python-version>'. See README for examples and documentation.");
52419+
throw new Error("Invalid 'version' property for PyPy. PyPy version should be specified as 'pypy<python-version>' or 'pypy-<python-version>'. See README for examples and documentation.");
5241652420
}
5241752421
const pythonVersion = versions[1];
5241852422
let pypyVersion;

src/find-pypy.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,14 @@ export function findPyPyToolCache(
9898
export function parsePyPyVersion(versionSpec: string): IPyPyVersionSpec {
9999
const versions = versionSpec.split('-').filter(item => !!item);
100100

101+
if (/^(pypy)(.+)/.test(versions[0])) {
102+
let pythonVersion = versions[0].replace('pypy', '');
103+
versions.splice(0, 1, 'pypy', pythonVersion);
104+
}
105+
101106
if (versions.length < 2 || versions[0] != 'pypy') {
102107
throw new Error(
103-
"Invalid 'version' property for PyPy. PyPy version should be specified as 'pypy-<python-version>'. See README for examples and documentation."
108+
"Invalid 'version' property for PyPy. PyPy version should be specified as 'pypy<python-version>' or 'pypy-<python-version>'. See README for examples and documentation."
104109
);
105110
}
106111

src/setup-python.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {getCacheDistributor} from './cache-distributions/cache-factory';
77
import {isCacheFeatureAvailable} from './utils';
88

99
function isPyPyVersion(versionSpec: string) {
10-
return versionSpec.startsWith('pypy-');
10+
return versionSpec.startsWith('pypy');
1111
}
1212

1313
async function cacheDependencies(cache: string, pythonVersion: string) {

0 commit comments

Comments
 (0)