From 0ebf233433c08fb9061af664d501c3f3ff0e9e20 Mon Sep 17 00:00:00 2001 From: Dmitry Shibanov Date: Mon, 28 Feb 2022 10:19:48 +0300 Subject: [PATCH] Remove legacy PyPy input (#342) --- .github/workflows/test-python.yml | 20 ---------- .github/workflows/workflow.yml | 4 +- __tests__/finder.test.ts | 16 ++------ dist/setup/index.js | 53 ++------------------------ src/find-python.ts | 62 +------------------------------ src/setup-python.ts | 2 +- 6 files changed, 11 insertions(+), 146 deletions(-) diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 191db1411..8f2330152 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -91,23 +91,3 @@ jobs: - name: Run simple code run: python -c 'import math; print(math.factorial(5))' - setup-pypy-legacy: - name: Setup PyPy ${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: [macos-10.15, windows-2019, ubuntu-18.04, ubuntu-20.04] - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: setup-python pypy3 - uses: ./ - with: - python-version: 'pypy3' - - - name: setup-python pypy2 - uses: ./ - with: - python-version: 'pypy2' diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index b5db2f45a..5c8d54032 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -24,8 +24,8 @@ jobs: with: node-version: 16.x - - name: npm install - run: npm install + - name: npm ci + run: npm ci - name: Lint run: npm run format-check diff --git a/__tests__/finder.test.ts b/__tests__/finder.test.ts index 54bf3cf8c..d48056964 100644 --- a/__tests__/finder.test.ts +++ b/__tests__/finder.test.ts @@ -35,7 +35,7 @@ describe('Finder tests', () => { await io.mkdirP(pythonDir); fs.writeFileSync(`${pythonDir}.complete`, 'hello'); // This will throw if it doesn't find it in the cache and in the manifest (because no such version exists) - await finder.findPythonVersion('3.x', 'x64'); + await finder.useCpythonVersion('3.x', 'x64'); }); it('Finds stable Python version if it is not installed, but exists in the manifest', async () => { @@ -52,7 +52,7 @@ describe('Finder tests', () => { fs.writeFileSync(`${pythonDir}.complete`, 'hello'); }); // This will throw if it doesn't find it in the cache and in the manifest (because no such version exists) - await finder.findPythonVersion('1.2.3', 'x64'); + await finder.useCpythonVersion('1.2.3', 'x64'); }); it('Finds pre-release Python version in the manifest', async () => { @@ -74,25 +74,17 @@ describe('Finder tests', () => { fs.writeFileSync(`${pythonDir}.complete`, 'hello'); }); // This will throw if it doesn't find it in the manifest (because no such version exists) - await finder.findPythonVersion('1.2.3-beta.2', 'x64'); + await finder.useCpythonVersion('1.2.3-beta.2', 'x64'); }); it('Errors if Python is not installed', async () => { // This will throw if it doesn't find it in the cache and in the manifest (because no such version exists) let thrown = false; try { - await finder.findPythonVersion('3.300000', 'x64'); + await finder.useCpythonVersion('3.300000', 'x64'); } catch { thrown = true; } expect(thrown).toBeTruthy(); }); - - it('Finds PyPy if it is installed', async () => { - const pythonDir: string = path.join(toolDir, 'PyPy', '2.0.0', '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'); - }); }); diff --git a/dist/setup/index.js b/dist/setup/index.js index 5cc90e8eb..ae0ab4045 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -6694,7 +6694,7 @@ function run() { core.info(`Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})`); } else { - const installed = yield finder.findPythonVersion(version, arch); + const installed = yield finder.useCpythonVersion(version, arch); pythonVersion = installed.version; core.info(`Successfully setup ${installed.impl} (${pythonVersion})`); } @@ -57111,7 +57111,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.findPythonVersion = exports.pythonVersionToSemantic = void 0; +exports.pythonVersionToSemantic = exports.useCpythonVersion = void 0; const os = __importStar(__webpack_require__(87)); const path = __importStar(__webpack_require__(622)); const utils_1 = __webpack_require__(163); @@ -57139,40 +57139,6 @@ function binDir(installDir) { return path.join(installDir, 'bin'); } } -// Note on the tool cache layout for PyPy: -// PyPy has its own versioning scheme that doesn't follow the Python versioning scheme. -// 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. -// 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); - let installDir = findPyPy(architecture); - if (!installDir && utils_1.IS_WINDOWS) { - // PyPy only precompiles binaries for x86, but the architecture parameter defaults to x64. - // On our Windows virtual environments, we only install an x86 version. - // Fall back to x86. - installDir = findPyPy('x86'); - } - if (!installDir) { - // PyPy not installed in $(Agent.ToolsDirectory) - throw new Error(`PyPy ${majorVersion} not found`); - } - // For PyPy, Windows uses 'bin', not 'Scripts'. - const _binDir = path.join(installDir, 'bin'); - // On Linux and macOS, the Python interpreter is in 'bin'. - // On Windows, it is in the installation root. - const pythonLocation = utils_1.IS_WINDOWS ? installDir : _binDir; - core.exportVariable('pythonLocation', pythonLocation); - core.addPath(installDir); - core.addPath(_binDir); - // Starting from PyPy 7.3.1, the folder that is used for pip and anything that pip installs should be "Scripts" on Windows. - if (utils_1.IS_WINDOWS) { - core.addPath(path.join(installDir, 'Scripts')); - } - const impl = 'pypy' + majorVersion.toString(); - core.setOutput('python-version', impl); - return { impl: impl, version: versionFromPath(installDir) }; -} function useCpythonVersion(version, architecture) { return __awaiter(this, void 0, void 0, function* () { const desugaredVersionSpec = desugarDevVersion(version); @@ -57222,6 +57188,7 @@ function useCpythonVersion(version, architecture) { return { impl: 'CPython', version: installed }; }); } +exports.useCpythonVersion = useCpythonVersion; /** Convert versions like `3.8-dev` to a version like `>= 3.8.0-a0`. */ function desugarDevVersion(versionSpec) { if (versionSpec.endsWith('-dev')) { @@ -57248,20 +57215,6 @@ function pythonVersionToSemantic(versionSpec) { return versionSpec.replace(prereleaseVersion, '$1-$2'); } exports.pythonVersionToSemantic = pythonVersionToSemantic; -function findPythonVersion(version, architecture) { - return __awaiter(this, void 0, void 0, function* () { - switch (version.toUpperCase()) { - case 'PYPY2': - return usePyPy('2', architecture); - case 'PYPY3': - // keep pypy3 pointing to 3.6 for backward compatibility - return usePyPy('3.6', architecture); - default: - return yield useCpythonVersion(version, architecture); - } - }); -} -exports.findPythonVersion = findPythonVersion; /***/ }), diff --git a/src/find-python.ts b/src/find-python.ts index ff2a20d8d..b8175a436 100644 --- a/src/find-python.ts +++ b/src/find-python.ts @@ -30,52 +30,7 @@ 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. -// 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. -// We only care about the Python version, so we don't use the PyPy version for the tool cache. -function usePyPy( - majorVersion: '2' | '3.6', - architecture: string -): InstalledVersion { - const findPyPy = tc.find.bind(undefined, 'PyPy', majorVersion); - let installDir: string | null = findPyPy(architecture); - - if (!installDir && IS_WINDOWS) { - // PyPy only precompiles binaries for x86, but the architecture parameter defaults to x64. - // On our Windows virtual environments, we only install an x86 version. - // Fall back to x86. - installDir = findPyPy('x86'); - } - - if (!installDir) { - // PyPy not installed in $(Agent.ToolsDirectory) - throw new Error(`PyPy ${majorVersion} not found`); - } - - // For PyPy, Windows uses 'bin', not 'Scripts'. - const _binDir = path.join(installDir, 'bin'); - - // On Linux and macOS, the Python interpreter is in 'bin'. - // On Windows, it is in the installation root. - const pythonLocation = IS_WINDOWS ? installDir : _binDir; - core.exportVariable('pythonLocation', pythonLocation); - - core.addPath(installDir); - core.addPath(_binDir); - // Starting from PyPy 7.3.1, the folder that is used for pip and anything that pip installs should be "Scripts" on Windows. - if (IS_WINDOWS) { - core.addPath(path.join(installDir, 'Scripts')); - } - - const impl = 'pypy' + majorVersion.toString(); - core.setOutput('python-version', impl); - - return {impl: impl, version: versionFromPath(installDir)}; -} - -async function useCpythonVersion( +export async function useCpythonVersion( version: string, architecture: string ): Promise { @@ -186,18 +141,3 @@ export function pythonVersionToSemantic(versionSpec: string) { const prereleaseVersion = /(\d+\.\d+\.\d+)((?:a|b|rc)\d*)/g; return versionSpec.replace(prereleaseVersion, '$1-$2'); } - -export async function findPythonVersion( - version: string, - architecture: string -): Promise { - switch (version.toUpperCase()) { - case 'PYPY2': - return usePyPy('2', architecture); - case 'PYPY3': - // keep pypy3 pointing to 3.6 for backward compatibility - return usePyPy('3.6', architecture); - default: - return await useCpythonVersion(version, architecture); - } -} diff --git a/src/setup-python.ts b/src/setup-python.ts index 3a19efe13..b37d58356 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -37,7 +37,7 @@ async function run() { `Successfully setup PyPy ${installed.resolvedPyPyVersion} with Python (${installed.resolvedPythonVersion})` ); } else { - const installed = await finder.findPythonVersion(version, arch); + const installed = await finder.useCpythonVersion(version, arch); pythonVersion = installed.version; core.info(`Successfully setup ${installed.impl} (${pythonVersion})`); }