Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
4eb7dbc
Bump braces from 3.0.2 to 3.0.3 (#893)
dependabot[bot] Jun 26, 2024
a0d74c0
fix(ci): update all failing workflows (#863)
mayeut Jun 27, 2024
39cd149
Documentation update for cache (#873)
gowridurgad Jul 10, 2024
cb68456
Updated @iarna/toml version to 3.0.0 (#912)
priya-kinthali Jul 22, 2024
04c1311
Fix display of emojis in contributors doc (#899)
sciencewhiz Jul 23, 2024
036a523
Fix: Add `.zip` extension to Windows package downloads for `Expand-Ar…
priyagupta108 Aug 5, 2024
80b49d3
fix: add arch to cache key (#896)
Zxilly Aug 7, 2024
2bd53f9
Documentation update for caching poetry dependencies (#908)
gowridurgad Aug 8, 2024
f677139
Bump pyinstaller from 3.6 to 5.13.1 in /__tests__/data (#923)
aparnajyothi-y Aug 13, 2024
29a37be
initial commit (#938)
priya-kinthali Sep 6, 2024
65b48c7
Create publish-immutable-actions.yml
Jcambass Sep 10, 2024
70dcb22
Merge pull request #941 from actions/Jcambass-patch-1
Jcambass Sep 10, 2024
3226af6
Upgrade IA publish
Jcambass Sep 16, 2024
e9675cc
Merge pull request #943 from actions/Jcambass-patch-1
Jcambass Sep 26, 2024
19dfb7b
Bump default versions to latest (#905)
jeffwidman Oct 4, 2024
f4c5a11
Revise `isGhes` logic (#963)
jww3 Oct 21, 2024
9c76e71
Bump pillow from 7.2 to 10.2.0 in /__tests__/data (#956)
aparnajyothi-y Oct 21, 2024
0b93645
Enhance workflows: Add macOS 13 support, upgrade publish-action, and …
priya-kinthali Oct 24, 2024
55aad42
Update error message for no dependencies to cache (#968)
aparnajyothi-y Nov 5, 2024
3fddbee
Enhance Workflows: Add Ubuntu-24, Remove Python 3.8 (#985)
priya-kinthali Dec 19, 2024
1928ae6
Update README.md (#1009)
Jan 16, 2025
b8cf3eb
Use the new cache service: upgrade `@actions/cache` to `^4.0.0` (#1007)
priyagupta108 Jan 21, 2025
e3dfaac
Configure Dependabot settings (#1008)
HarithaVattikuti Jan 22, 2025
d0b4fc4
Bump undici from 5.28.4 to 5.28.5 (#1012)
dependabot[bot] Jan 22, 2025
feb9c6e
Bump urllib3 from 1.25.9 to 1.26.19 in /__tests__/data (#895)
dependabot[bot] Jan 27, 2025
0dc2d2c
Bump actions/publish-immutable-action from 0.0.3 to 0.0.4 (#1014)
dependabot[bot] Jan 27, 2025
ceb20b2
Bump @actions/http-client from 2.2.1 to 2.2.3 (#1020)
dependabot[bot] Jan 27, 2025
709bfa5
Bump requests from 2.24.0 to 2.32.2 in /__tests__/data (#1019)
dependabot[bot] Jan 27, 2025
4237552
Improve Advanced Usage examples (#645)
lrq3000 Jan 27, 2025
8039c45
fix: install PyPy on Linux ARM64 (#1011)
mayeut Feb 5, 2025
6ca8e85
Bump @vercel/ncc from 0.38.1 to 0.38.3 (#1016)
dependabot[bot] Feb 18, 2025
9e62be8
Support free threaded Python versions like '3.13t' (#973)
colesbury Mar 4, 2025
6fd11e1
Bump @actions/glob from 0.4.0 to 0.5.0 (#1015)
dependabot[bot] Mar 12, 2025
19e4675
Add support for .tool-versions file in setup-python (#1043)
mahabaleshwars Mar 13, 2025
8d9ed9a
Add e2e Testing for free threaded and Bump @action/cache from 4.0.0 t…
priya-kinthali Mar 24, 2025
e348410
Remove Ubuntu 20.04 from workflows due to deprecation from 2025-04-15…
aparnajyothi-y Apr 11, 2025
6ed2c67
Fix for Candidate Not Iterable Error (#1082)
aparnajyothi-y Apr 17, 2025
5d95bc1
Bump semver and @types/semver (#1091)
dependabot[bot] Apr 22, 2025
30eafe9
Bump prettier from 2.8.8 to 3.5.3 (#1046)
dependabot[bot] Apr 22, 2025
a26af69
Bump ts-jest from 29.1.2 to 29.3.2 (#1081)
dependabot[bot] Apr 24, 2025
5db1cf9
Enhance reading from .python-version (#787)
krystof-k May 21, 2025
5fa0ee6
Bump @actions/tool-cache from 2.0.1 to 2.0.2 (#1095)
dependabot[bot] Jun 18, 2025
e9c40fb
Add support for `pip-version` (#1129)
priyagupta108 Jun 20, 2025
1264885
Enhance cache-dependency-path handling to support files outside the w…
aparnajyothi-y Jun 25, 2025
532b046
Add Architecture-Specific PATH Management for Python with --user Flag…
aparnajyothi-y Jul 3, 2025
88ffd4d
Include python version in PyPy python-version output (#1110)
cdce8p Jul 21, 2025
3c6f142
update documentation (#1156)
priya-kinthali Jul 23, 2025
677a682
Merge remote-tracking branch 'upstream/main'
mmatl Jul 23, 2025
dfdaf8d
fix: fix
mmatl Jul 23, 2025
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
Prev Previous commit
Next Next commit
Enhance reading from .python-version (actions#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
  • Loading branch information
krystof-k authored May 21, 2025
commit 5db1cf9a59fb97c40a68accab29236f0da7e94db
66 changes: 47 additions & 19 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
validatePythonVersionFormatForPyPy,
isCacheFeatureAvailable,
getVersionInputFromFile,
getVersionInputFromPlainFile,
getVersionsInputFromPlainFile,
getVersionInputFromTomlFile,
getNextPageUrl,
isGhes,
Expand All @@ -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) => {
Expand Down Expand Up @@ -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]);
Expand All @@ -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]);
Expand All @@ -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']);
}
);

Expand All @@ -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']);
}
);

Expand All @@ -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']);
}
);

Expand All @@ -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']);
}
);

Expand All @@ -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']);
}
);

Expand Down
39 changes: 27 additions & 12 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96929,7 +96929,7 @@ function cacheDependencies(cache, pythonVersion) {
}
function resolveVersionInputFromDefaultFile() {
const couples = [
['.python-version', utils_1.getVersionInputFromPlainFile]
['.python-version', utils_1.getVersionsInputFromPlainFile]
];
for (const [versionFile, _fn] of couples) {
(0, utils_1.logWarning)(`Neither 'python-version' nor 'python-version-file' inputs were supplied. Attempting to find '${versionFile}' file.`);
Expand Down Expand Up @@ -97066,7 +97066,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getDownloadFileName = exports.getNextPageUrl = exports.getBinaryDirectory = exports.getVersionInputFromFile = exports.getVersionInputFromToolVersions = exports.getVersionInputFromPlainFile = exports.getVersionInputFromTomlFile = exports.getOSInfo = exports.getLinuxInfo = exports.logWarning = exports.isCacheFeatureAvailable = exports.isGhes = exports.validatePythonVersionFormatForPyPy = exports.writeExactPyPyVersionFile = exports.readExactPyPyVersionFile = exports.getPyPyVersionFromPath = exports.isNightlyKeyword = exports.validateVersion = exports.createSymlinkInFolder = exports.WINDOWS_PLATFORMS = exports.WINDOWS_ARCHS = exports.IS_MAC = exports.IS_LINUX = exports.IS_WINDOWS = void 0;
exports.getDownloadFileName = exports.getNextPageUrl = exports.getBinaryDirectory = exports.getVersionInputFromFile = exports.getVersionInputFromToolVersions = exports.getVersionsInputFromPlainFile = exports.getVersionInputFromTomlFile = exports.getOSInfo = exports.getLinuxInfo = exports.logWarning = exports.isCacheFeatureAvailable = exports.isGhes = exports.validatePythonVersionFormatForPyPy = exports.writeExactPyPyVersionFile = exports.readExactPyPyVersionFile = exports.getPyPyVersionFromPath = exports.isNightlyKeyword = exports.validateVersion = exports.createSymlinkInFolder = exports.WINDOWS_PLATFORMS = exports.WINDOWS_ARCHS = exports.IS_MAC = exports.IS_LINUX = exports.IS_WINDOWS = void 0;
/* eslint no-unsafe-finally: "off" */
const cache = __importStar(__nccwpck_require__(5116));
const core = __importStar(__nccwpck_require__(7484));
Expand Down Expand Up @@ -97247,7 +97247,7 @@ function extractValue(obj, keys) {
* If none is present, returns an empty list.
*/
function getVersionInputFromTomlFile(versionFile) {
core.debug(`Trying to resolve version form ${versionFile}`);
core.debug(`Trying to resolve version from ${versionFile}`);
let pyprojectFile = fs_1.default.readFileSync(versionFile, 'utf8');
// Normalize the line endings in the pyprojectFile
pyprojectFile = pyprojectFile.replace(/\r\n/g, '\n');
Expand Down Expand Up @@ -97280,15 +97280,30 @@ function getVersionInputFromTomlFile(versionFile) {
}
exports.getVersionInputFromTomlFile = getVersionInputFromTomlFile;
/**
* Python version extracted from a plain text file.
*/
function getVersionInputFromPlainFile(versionFile) {
core.debug(`Trying to resolve version form ${versionFile}`);
const version = fs_1.default.readFileSync(versionFile, 'utf8').trim();
core.info(`Resolved ${versionFile} as ${version}`);
return [version];
* Python versions extracted from a plain text file.
* - Resolves multiple versions from multiple lines.
* - Handles pyenv-virtualenv pointers (e.g. `3.10/envs/virtualenv`).
* - Ignores empty lines and lines starting with `#`
* - Trims whitespace.
*/
function getVersionsInputFromPlainFile(versionFile) {
core.debug(`Trying to resolve versions from ${versionFile}`);
const content = fs_1.default.readFileSync(versionFile, 'utf8').trim();
const lines = content.split(/\r\n|\r|\n/);
const versions = lines
.map(line => {
if (line.startsWith('#') || line.trim() === '') {
return undefined;
}
let version = line.trim();
version = version.split('/')[0];
return version;
})
.filter(version => version !== undefined);
core.info(`Resolved ${versionFile} as ${versions.join(', ')}`);
return versions;
}
exports.getVersionInputFromPlainFile = getVersionInputFromPlainFile;
exports.getVersionsInputFromPlainFile = getVersionsInputFromPlainFile;
/**
* Python version extracted from a .tool-versions file.
*/
Expand Down Expand Up @@ -97331,7 +97346,7 @@ function getVersionInputFromFile(versionFile) {
return getVersionInputFromToolVersions(versionFile);
}
else {
return getVersionInputFromPlainFile(versionFile);
return getVersionsInputFromPlainFile(versionFile);
}
}
exports.getVersionInputFromFile = getVersionInputFromFile;
Expand Down
4 changes: 2 additions & 2 deletions src/setup-python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
logWarning,
IS_MAC,
getVersionInputFromFile,
getVersionInputFromPlainFile
getVersionsInputFromPlainFile
} from './utils';

function isPyPyVersion(versionSpec: string) {
Expand All @@ -35,7 +35,7 @@ async function cacheDependencies(cache: string, pythonVersion: string) {

function resolveVersionInputFromDefaultFile(): string[] {
const couples: [string, (versionFile: string) => string[]][] = [
['.python-version', getVersionInputFromPlainFile]
['.python-version', getVersionsInputFromPlainFile]
];
for (const [versionFile, _fn] of couples) {
logWarning(
Expand Down
31 changes: 23 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function extractValue(obj: any, keys: string[]): string | undefined {
* If none is present, returns an empty list.
*/
export function getVersionInputFromTomlFile(versionFile: string): string[] {
core.debug(`Trying to resolve version form ${versionFile}`);
core.debug(`Trying to resolve version from ${versionFile}`);

let pyprojectFile = fs.readFileSync(versionFile, 'utf8');
// Normalize the line endings in the pyprojectFile
Expand Down Expand Up @@ -269,13 +269,28 @@ export function getVersionInputFromTomlFile(versionFile: string): string[] {
}

/**
* Python version extracted from a plain text file.
* Python versions extracted from a plain text file.
* - Resolves multiple versions from multiple lines.
* - Handles pyenv-virtualenv pointers (e.g. `3.10/envs/virtualenv`).
* - Ignores empty lines and lines starting with `#`
* - Trims whitespace.
*/
export function getVersionInputFromPlainFile(versionFile: string): string[] {
core.debug(`Trying to resolve version form ${versionFile}`);
const version = fs.readFileSync(versionFile, 'utf8').trim();
core.info(`Resolved ${versionFile} as ${version}`);
return [version];
export function getVersionsInputFromPlainFile(versionFile: string): string[] {
core.debug(`Trying to resolve versions from ${versionFile}`);
const content = fs.readFileSync(versionFile, 'utf8').trim();
const lines = content.split(/\r\n|\r|\n/);
const versions = lines
.map(line => {
if (line.startsWith('#') || line.trim() === '') {
return undefined;
}
let version: string = line.trim();
version = version.split('/')[0];
return version;
})
.filter(version => version !== undefined) as string[];
core.info(`Resolved ${versionFile} as ${versions.join(', ')}`);
return versions;
}

/**
Expand Down Expand Up @@ -319,7 +334,7 @@ export function getVersionInputFromFile(versionFile: string): string[] {
} else if (versionFile.match('.tool-versions')) {
return getVersionInputFromToolVersions(versionFile);
} else {
return getVersionInputFromPlainFile(versionFile);
return getVersionsInputFromPlainFile(versionFile);
}
}

Expand Down