fix comments

This commit is contained in:
Dmitry Shibanov 2022-02-22 11:55:20 +03:00
parent ee6a186a78
commit 44f86dea75
4 changed files with 8 additions and 99 deletions

View file

@ -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,14 +74,14 @@ 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;
}

43
dist/setup/index.js vendored
View file

@ -6656,7 +6656,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})`);
}
@ -57024,40 +57024,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);
@ -57107,6 +57073,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')) {
@ -57133,12 +57100,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* () {
return yield useCpythonVersion(version, architecture);
});
}
exports.findPythonVersion = findPythonVersion;
/***/ }),

View file

@ -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<InstalledVersion> {
@ -186,10 +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<InstalledVersion> {
return await useCpythonVersion(version, architecture);
}

View file

@ -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})`);
}