mirror of
https://code.forgejo.org/actions/setup-python
synced 2025-06-08 04:18:19 +02:00
Enhance reading from .python-version (#787)
* Enhance reading from .python-version * Fix typos * Fix lint * Add built files * Don't use EOL versions in `utils.test.ts` * Fix Prettier * Don't use unreleased versions in `utils.test.ts` * Update versions in `utils.test.ts` again
This commit is contained in:
parent
a26af69be9
commit
5db1cf9a59
4 changed files with 98 additions and 40 deletions
|
@ -10,7 +10,7 @@ import {
|
|||
validatePythonVersionFormatForPyPy,
|
||||
isCacheFeatureAvailable,
|
||||
getVersionInputFromFile,
|
||||
getVersionInputFromPlainFile,
|
||||
getVersionsInputFromPlainFile,
|
||||
getVersionInputFromTomlFile,
|
||||
getNextPageUrl,
|
||||
isGhes,
|
||||
|
@ -24,10 +24,10 @@ jest.mock('@actions/core');
|
|||
|
||||
describe('validatePythonVersionFormatForPyPy', () => {
|
||||
it.each([
|
||||
['3.6', true],
|
||||
['3.7', true],
|
||||
['3.6.x', false],
|
||||
['3.7.x', false],
|
||||
['3.12', true],
|
||||
['3.13', true],
|
||||
['3.12.x', false],
|
||||
['3.13.x', false],
|
||||
['3.x', false],
|
||||
['3', false]
|
||||
])('%s -> %s', (input, expected) => {
|
||||
|
@ -95,24 +95,52 @@ const tempDir = path.join(
|
|||
);
|
||||
|
||||
describe('Version from file test', () => {
|
||||
it.each([getVersionInputFromPlainFile, getVersionInputFromFile])(
|
||||
it.each([getVersionsInputFromPlainFile, getVersionInputFromFile])(
|
||||
'Version from plain file test',
|
||||
async _fn => {
|
||||
await io.mkdirP(tempDir);
|
||||
const pythonVersionFileName = 'python-version.file';
|
||||
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
|
||||
const pythonVersionFileContent = '3.7';
|
||||
const pythonVersionFileContent = '3.13';
|
||||
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
|
||||
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersionFileContent]);
|
||||
}
|
||||
);
|
||||
it.each([getVersionsInputFromPlainFile, getVersionInputFromFile])(
|
||||
'Versions from multiline plain file test',
|
||||
async _fn => {
|
||||
await io.mkdirP(tempDir);
|
||||
const pythonVersionFileName = 'python-version.file';
|
||||
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
|
||||
const pythonVersionFileContent = '3.13\r\n3.12';
|
||||
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
|
||||
expect(_fn(pythonVersionFilePath)).toEqual(['3.13', '3.12']);
|
||||
}
|
||||
);
|
||||
it.each([getVersionsInputFromPlainFile, getVersionInputFromFile])(
|
||||
'Version from complex plain file test',
|
||||
async _fn => {
|
||||
await io.mkdirP(tempDir);
|
||||
const pythonVersionFileName = 'python-version.file';
|
||||
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
|
||||
const pythonVersionFileContent =
|
||||
'3.13/envs/virtualenv\r# 3.12\n3.11\r\n3.10\r\n 3.9 \r\n';
|
||||
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
|
||||
expect(_fn(pythonVersionFilePath)).toEqual([
|
||||
'3.13',
|
||||
'3.11',
|
||||
'3.10',
|
||||
'3.9'
|
||||
]);
|
||||
}
|
||||
);
|
||||
it.each([getVersionInputFromTomlFile, getVersionInputFromFile])(
|
||||
'Version from standard pyproject.toml test',
|
||||
async _fn => {
|
||||
await io.mkdirP(tempDir);
|
||||
const pythonVersionFileName = 'pyproject.toml';
|
||||
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
|
||||
const pythonVersion = '>=3.7.0';
|
||||
const pythonVersion = '>=3.13.0';
|
||||
const pythonVersionFileContent = `[project]\nrequires-python = "${pythonVersion}"`;
|
||||
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
|
||||
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);
|
||||
|
@ -124,7 +152,7 @@ describe('Version from file test', () => {
|
|||
await io.mkdirP(tempDir);
|
||||
const pythonVersionFileName = 'pyproject.toml';
|
||||
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
|
||||
const pythonVersion = '>=3.7.0';
|
||||
const pythonVersion = '>=3.13.0';
|
||||
const pythonVersionFileContent = `[tool.poetry.dependencies]\npython = "${pythonVersion}"`;
|
||||
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
|
||||
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);
|
||||
|
@ -145,9 +173,9 @@ describe('Version from file test', () => {
|
|||
async _fn => {
|
||||
const toolVersionFileName = '.tool-versions';
|
||||
const toolVersionFilePath = path.join(tempDir, toolVersionFileName);
|
||||
const toolVersionContent = 'python 3.9.10\nnodejs 16';
|
||||
const toolVersionContent = 'python 3.13.2\nnodejs 16';
|
||||
fs.writeFileSync(toolVersionFilePath, toolVersionContent);
|
||||
expect(_fn(toolVersionFilePath)).toEqual(['3.9.10']);
|
||||
expect(_fn(toolVersionFilePath)).toEqual(['3.13.2']);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -156,9 +184,9 @@ describe('Version from file test', () => {
|
|||
async _fn => {
|
||||
const toolVersionFileName = '.tool-versions';
|
||||
const toolVersionFilePath = path.join(tempDir, toolVersionFileName);
|
||||
const toolVersionContent = '# python 3.8\npython 3.9';
|
||||
const toolVersionContent = '# python 3.13\npython 3.12';
|
||||
fs.writeFileSync(toolVersionFilePath, toolVersionContent);
|
||||
expect(_fn(toolVersionFilePath)).toEqual(['3.9']);
|
||||
expect(_fn(toolVersionFilePath)).toEqual(['3.12']);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -167,9 +195,9 @@ describe('Version from file test', () => {
|
|||
async _fn => {
|
||||
const toolVersionFileName = '.tool-versions';
|
||||
const toolVersionFilePath = path.join(tempDir, toolVersionFileName);
|
||||
const toolVersionContent = ' python 3.10 ';
|
||||
const toolVersionContent = ' python 3.13 ';
|
||||
fs.writeFileSync(toolVersionFilePath, toolVersionContent);
|
||||
expect(_fn(toolVersionFilePath)).toEqual(['3.10']);
|
||||
expect(_fn(toolVersionFilePath)).toEqual(['3.13']);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -178,9 +206,9 @@ describe('Version from file test', () => {
|
|||
async _fn => {
|
||||
const toolVersionFileName = '.tool-versions';
|
||||
const toolVersionFilePath = path.join(tempDir, toolVersionFileName);
|
||||
const toolVersionContent = 'python v3.9.10';
|
||||
const toolVersionContent = 'python v3.13.2';
|
||||
fs.writeFileSync(toolVersionFilePath, toolVersionContent);
|
||||
expect(_fn(toolVersionFilePath)).toEqual(['3.9.10']);
|
||||
expect(_fn(toolVersionFilePath)).toEqual(['3.13.2']);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -189,9 +217,9 @@ describe('Version from file test', () => {
|
|||
async _fn => {
|
||||
const toolVersionFileName = '.tool-versions';
|
||||
const toolVersionFilePath = path.join(tempDir, toolVersionFileName);
|
||||
const toolVersionContent = 'python pypy3.10-7.3.14';
|
||||
const toolVersionContent = 'python pypy3.10-7.3.19';
|
||||
fs.writeFileSync(toolVersionFilePath, toolVersionContent);
|
||||
expect(_fn(toolVersionFilePath)).toEqual(['pypy3.10-7.3.14']);
|
||||
expect(_fn(toolVersionFilePath)).toEqual(['pypy3.10-7.3.19']);
|
||||
}
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue