Skip to content

Update UsePythonVersion to allow versions other than (pypy2 or pypy3.6) #15553

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
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
20 changes: 10 additions & 10 deletions Tasks/UsePythonVersionV0/usepythonversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function binDir(installDir: string, platform: Platform): string {
}
}

function pypyNotFoundError(versionSpec: '2' | '3.6') {
function pypyNotFoundError(versionSpec: string) {
Copy link
Author

@scbedd scbedd Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from pypy3 -> pypy3.6 being NECESSARY is what I'd consider the breaking change in this PR. It probably should be bumped to version @1. How is that normally done? Just copy/paste the source into an UsePythonVersion@1 directory under /Tasks?

throw new Error([
task.loc('PyPyNotFound', versionSpec),
// 'Python' is intentional here
Expand All @@ -52,7 +52,7 @@ function pypyNotFoundError(versionSpec: '2' | '3.6') {
// For example, PyPy 7.0 contains Python 2.7, 3.5, and 3.6-alpha.
// We only care about the Python version, so we don't use the PyPy version for the tool cache.

function usePyPy(versionSpec: '2' | '3.6', parameters: TaskParameters, platform: Platform): void {
function usePyPy(versionSpec: string, parameters: TaskParameters, platform: Platform): void {
const findPyPy = tool.findLocalTool.bind(undefined, 'PyPy', versionSpec);
let installDir: string | null = findPyPy(parameters.architecture);

Expand Down Expand Up @@ -136,13 +136,13 @@ async function useCpythonVersion(parameters: Readonly<TaskParameters>, platform:
}

export async function usePythonVersion(parameters: Readonly<TaskParameters>, platform: Platform): Promise<void> {
switch (parameters.versionSpec.toUpperCase()) {
case 'PYPY2':
return usePyPy('2', parameters, platform);
case 'PYPY3':
// keep pypy3 pointing to 3.6 for backward compatibility
return usePyPy('3.6', parameters, platform);
default:
return await useCpythonVersion(parameters, platform);
let fullSpec: string = parameters.versionSpec.toUpperCase();

if (fullSpec.startsWith("PYPY")) {
// trim off the beginning pypy and look for it by version
return await usePyPy(fullSpec.substr(4), parameters, platform);
}
else {
return await useCpythonVersion(parameters, platform);
}
}