8000 Allow pypy3, pypy3.6 or pypy3.7 syntax by mattip · Pull Request #161 · actions/setup-python · GitHub
[go: up one dir, main page]

Skip to content

Allow pypy3, pypy3.6 or pypy3.7 syntax #161

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '2.x', '3.x', 'pypy2', 'pypy3' ]
python-version: [ '2.x', '3.x', 'pypy2', 'pypy3.7' ]
name: Python ${{ matrix.python-version }} sample
steps:
- uses: actions/checkout@v2
Expand All @@ -60,7 +60,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [2.7, 3.6, 3.7, 3.8, pypy2, pypy3]
python-version: [2.7, 3.6, 3.7, 3.8, pypy2, pypy3.7]
exclude:
- os: macos-latest
python-version: 3.8
Expand Down
4 changes: 2 additions & 2 deletions __tests__/finder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ describe('Finder tests', () => {
});

it('Finds PyPy if it is installed', async () => {
const pythonDir: string = path.join(toolDir, 'PyPy', '2.0.0', 'x64');
const pythonDir: string = path.join(toolDir, 'PyPy', '3.7.4', 'x64');
await io.mkdirP(pythonDir);
fs.writeFileSync(`${pythonDir}.complete`, 'hello');
// This will throw if it doesn't find it in the cache (because no such version exists)
await finder.findPythonVersion('pypy2', 'x64');
await finder.findPythonVersion('pypy3', 'x64');
});
});
24 changes: 15 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6713,12 +6713,12 @@ function binDir(installDir) {
}
}
// Note on the tool cache layout for PyPy:
// PyPy has its own versioning scheme that doesn't follow the Python versioning scheme.
// PyPy has a versioning scheme that uses both an internal version and the python version.
// A particular version of PyPy may contain one or more versions of the Python interpreter.
// For example, PyPy 7.0 contains Python 2.7, 3.5, and 3.6-alpha.
// For example, PyPy 7.3.2 contains Python 2.7, 3.6, and 3.7-alpha.
// We only care about the Python version, so we don't use the PyPy version for the tool cache.
function usePyPy(majorVersion, architecture) {
const findPyPy = tc.find.bind(undefined, 'PyPy', majorVersion.toString());
function usePyPy(version, architecture) {
const findPyPy = tc.find.bind(undefined, 'PyPy', version);
let installDir = findPyPy(architecture);
if (!installDir && IS_WINDOWS) {
// PyPy only precompiles binaries for x86, but the architecture parameter defaults to x64.
Expand All @@ -6728,7 +6728,7 @@ function usePyPy(majorVersion, architecture) {
}
if (!installDir) {
// PyPy not installed in $(Agent.ToolsDirectory)
throw new Error(`PyPy ${majorVersion} not found`);
throw new Error(`PyPy ${version} not found`);
}
// For PyPy, Windows uses 'bin', not 'Scripts'.
const _binDir = path.join(installDir, 'bin');
Expand All @@ -6738,7 +6738,7 @@ function usePyPy(majorVersion, architecture) {
core.exportVariable('pythonLocation', pythonLocation);
core.addPath(installDir);
core.addPath(_binDir);
const impl = 'pypy' + majorVersion.toString();
const impl = 'pypy' + version.toString();
core.setOutput('python-version', impl);
return { impl: impl, version: versionFromPath(installDir) };
}
Expand Down Expand Up @@ -6818,10 +6818,16 @@ exports.pythonVersionToSemantic = pythonVersionToSemantic;
function findPythonVersion(version, architecture) {
return __awaiter(this, void 0, void 0, function* () {
switch (version.toUpperCase()) {
/* TODO: abstract this out to be more like CPython */
case 'PYPY2':
return usePyPy(2, architecture);
return usePyPy('2', architecture);
case 'PYPY3':
return usePyPy(3, architecture);
case 'PYPY37':
case 'PYPY3.7':
return usePyPy('3.7', architecture);
case 'PYPY36':
case 'PYPY3.6':
return usePyPy('3.6', architecture);
default:
return yield useCpythonVersion(version, architecture);
}
Expand Down Expand Up @@ -7247,4 +7253,4 @@ exports.exec = exec;

/***/ })

/******/ });
/******/ });
20 changes: 12 additions & 8 deletions src/find-python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ function binDir(installDir: string): string {
}

// Note on the tool cache layout for PyPy:
// PyPy has its own versioning scheme that doesn't follow the Python versioning scheme.
// PyPy has a versioning scheme that uses both an internal version and the python version.
// A particular version of PyPy may contain one or more versions of the Python interpreter.
// For example, PyPy 7.0 contains Python 2.7, 3.5, and 3.6-alpha.
// For example, PyPy 7.3.2 contains Python 2.7, 3.6, and 3.7-alpha.
// We only care about the Python version, so we don't use the PyPy version for the tool cache.
function usePyPy(majorVersion: 2 | 3, architecture: string): InstalledVersion {
const findPyPy = tc.find.bind(undefined, 'PyPy', majorVersion.toString());
function usePyPy(version: string, architecture: string): InstalledVersion {
const findPyPy = tc.find.bind(undefined, 'PyPy', version);
let installDir: string | null = findPyPy(architecture);

if (!installDir && IS_WINDOWS) {
Expand All @@ -50,7 +50,7 @@ function usePyPy(majorVersion: 2 | 3, architecture: string): InstalledVersion {

if (!installDir) {
// PyPy not installed in $(Agent.ToolsDirectory)
throw new Error(`PyPy ${majorVersion} not found`);
throw new Error(`PyPy ${version} not found`);
}

// For PyPy, Windows uses 'bin', not 'Scripts'.
Expand All @@ -64,7 +64,7 @@ function usePyPy(majorVersion: 2 | 3, architecture: string): InstalledVersion {
core.addPath(installDir);
core.addPath(_binDir);

const impl = 'pypy' + majorVersion.toString();
const impl = 'pypy' + version.toString();
core.setOutput('python-version', impl);

return {impl: impl, version: versionFromPath(installDir)};
Expand Down Expand Up @@ -187,10 +187,14 @@ export async function findPythonVersion(
architecture: string
): Promise<InstalledVersion> {
switch (version.toUpperCase()) {
/* TODO: extract this into a function */
case 'PYPY2':
return usePyPy(2, architecture);
return usePyPy('2', architecture);
case 'PYPY3.6':
return usePyPy('3.6', architecture);
case 'PYPY3':
return usePyPy(3, architecture);
case 'PYPY3.7':
return usePyPy('3.7', architecture);
default:
return await useCpythonVersion(version, architecture);
}
Expand Down
0