Skip to content

Commit f9527ef

Browse files
Merge branch 'actions:main' into main
2 parents 4052b4d + fbeb884 commit f9527ef

File tree

10 files changed

+317
-7
lines changed

10 files changed

+317
-7
lines changed

.github/workflows/test-python-freethreaded.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,86 @@ jobs:
242242
with:
243243
python-version-file: .tool-versions
244244

245+
setup-versions-from-pipfile-with-python_version:
246+
name: Setup ${{ matrix.python }} ${{ matrix.os }} Pipfile
247+
runs-on: ${{ matrix.os }}
248+
strategy:
249+
fail-fast: false
250+
matrix:
251+
os:
252+
[
253+
macos-latest,
254+
windows-latest,
255+
ubuntu-22.04,
256+
ubuntu-22.04-arm,
257+
macos-13,
258+
ubuntu-latest,
259+
ubuntu-24.04-arm
260+
]
261+
python: [3.13t, 3.14t-dev]
262+
steps:
263+
- name: Checkout
264+
uses: actions/checkout@v4
265+
266+
- name: build-version-file ${{ matrix.python }}
267+
run: |
268+
echo '[requires]
269+
python_version = "${{ matrix.python }}"
270+
' > Pipfile
271+
272+
- name: setup-python ${{ matrix.python }}
273+
id: setup-python
274+
uses: ./
275+
with:
276+
python-version-file: Pipfile
277+
278+
- name: Check python-path
279+
run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
280+
shell: bash
281+
282+
- name: Run simple code
283+
run: python -c 'import math; print(math.factorial(5))'
284+
285+
setup-versions-from-pipfile-with-python_full_version:
286+
name: Setup ${{ matrix.python }} ${{ matrix.os }} .tool-versions file
287+
runs-on: ${{ matrix.os }}
288+
strategy:
289+
fail-fast: false
290+
matrix:
291+
os:
292+
[
293+
macos-latest,
294+
windows-latest,
295+
ubuntu-22.04,
296+
ubuntu-22.04-arm,
297+
macos-13,
298+
ubuntu-latest,
299+
ubuntu-24.04-arm
300+
]
301+
python: [3.13.0t, 3.13.1t, 3.13.2t, 3.14t-dev]
302+
steps:
303+
- name: Checkout
304+
uses: actions/checkout@v4
305+
306+
- name: build-version-file ${{ matrix.python }}
307+
run: |
308+
echo '[requires]
309+
python_full_version = "${{ matrix.python }}"
310+
' > Pipfile
311+
312+
- name: setup-python ${{ matrix.python }}
313+
id: setup-python
314+
uses: ./
315+
with:
316+
python-version-file: Pipfile
317+
318+
- name: Check python-path
319+
run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
320+
shell: bash
321+
322+
- name: Run simple code
323+
run: python -c 'import math; print(math.factorial(5))'
324+
245325
setup-pre-release-version-from-manifest:
246326
name: Setup 3.14.0-alpha.6 ${{ matrix.os }}
247327
runs-on: ${{ matrix.os }}

.github/workflows/test-python.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,106 @@ jobs:
284284
with:
285285
python-version-file: .tool-versions
286286

287+
setup-versions-from-pipfile-with-python_version:
288+
name: Setup ${{ matrix.python }} ${{ matrix.os }} Pipfile with python_version
289+
runs-on: ${{ matrix.os }}
290+
strategy:
291+
fail-fast: false
292+
matrix:
293+
os:
294+
[
295+
macos-latest,
296+
windows-latest,
297+
ubuntu-22.04,
298+
ubuntu-22.04-arm,
299+
macos-13,
300+
ubuntu-latest,
301+
ubuntu-24.04-arm
302+
]
303+
python: [3.9.13, 3.10.11, 3.11.9, 3.13.2]
304+
steps:
305+
- name: Checkout
306+
uses: actions/checkout@v4
307+
308+
- name: build-version-file ${{ matrix.python }}
309+
run: |
310+
echo '[requires]
311+
python_version = "${{ matrix.python }}"
312+
' > Pipfile
313+
314+
- name: setup-python ${{ matrix.python }}
315+
id: setup-python
316+
uses: ./
317+
with:
318+
python-version-file: Pipfile
319+
320+
- name: Check python-path
321+
run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
322+
shell: bash
323+
324+
- name: Validate version
325+
run: |
326+
$pythonVersion = (python --version)
327+
if ("Python ${{ matrix.python }}".replace("==", "") -ne "$pythonVersion"){
328+
Write-Host "The current version is $pythonVersion; expected version is ${{ matrix.python }}"
329+
exit 1
330+
}
331+
$pythonVersion
332+
shell: pwsh
333+
334+
- name: Run simple code
335+
run: python -c 'import math; print(math.factorial(5))'
336+
337+
setup-versions-from-pipfile-with-python_full_version:
338+
name: Setup ${{ matrix.python }} ${{ matrix.os }} Pipfile with python_full_version
339+
runs-on: ${{ matrix.os }}
340+
strategy:
341+
fail-fast: false
342+
matrix:
343+
os:
344+
[
345+
macos-latest,
346+
windows-latest,
347+
ubuntu-22.04,
348+
ubuntu-22.04-arm,
349+
macos-13,
350+
ubuntu-latest,
351+
ubuntu-24.04-arm
352+
]
353+
python: [3.9.13, 3.10.11, 3.11.9, 3.13.2]
354+
steps:
355+
- name: Checkout
356+
uses: actions/checkout@v4
357+
358+
- name: build-version-file ${{ matrix.python }}
359+
run: |
360+
echo '[requires]
361+
python_full_version = "${{ matrix.python }}"
362+
' > Pipfile
363+
364+
- name: setup-python ${{ matrix.python }}
365+
id: setup-python
366+
uses: ./
367+
with:
368+
python-version-file: Pipfile
369+
370+
- name: Check python-path
371+
run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
372+
shell: bash
373+
374+
- name: Validate version
375+
run: |
376+
$pythonVersion = (python --version)
377+
if ("Python ${{ matrix.python }}".replace("==", "") -ne "$pythonVersion"){
378+
Write-Host "The current version is $pythonVersion; expected version is ${{ matrix.python }}"
379+
exit 1
380+
}
381+
$pythonVersion
382+
shell: pwsh
383+
384+
- name: Run simple code
385+
run: python -c 'import math; print(math.factorial(5))'
386+
287387
setup-pre-release-version-from-manifest:
288388
name: Setup 3.14.0-alpha.6 ${{ matrix.os }}
289389
runs-on: ${{ matrix.os }}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ steps:
9494

9595
>The requirements file format allows for specifying dependency versions using logical operators (for example chardet>=3.0.4) or specifying dependencies without any versions. In this case the pip install -r requirements.txt command will always try to install the latest available package version. To be sure that the cache will be used, please stick to a specific dependency version and update it manually if necessary.
9696

97+
>The `setup-python` action does not handle authentication for pip when installing packages from private repositories. For help, refer [pip’s VCS support documentation](https://pip.pypa.io/en/stable/topics/vcs-support/) or visit the [pip repository](https://github.com/pypa/pip).
98+
9799
See examples of using `cache` and `cache-dependency-path` for `pipenv` and `poetry` in the section: [Caching packages](docs/advanced-usage.md#caching-packages) of the [Advanced usage](docs/advanced-usage.md) guide.
98100

99101
## Advanced usage

__tests__/data/requirements-linux.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
certifi==2020.6.20
22
chardet==3.0.4
33
docutils==0.16
4-
idna==2.10
4+
idna==3.7
55
Kivy==2.0.0rc3
66
Kivy-Garden==0.1.4
77
packaging==20.7

__tests__/data/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ docutils==0.16
88

99
future==0.18.2; python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2'
1010

11-
idna==2.9
11+
idna==3.7
1212

1313
itsdangerous==1.1.0
1414

__tests__/utils.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
getVersionInputFromFile,
1313
getVersionsInputFromPlainFile,
1414
getVersionInputFromTomlFile,
15+
getVersionInputFromPipfileFile,
1516
getNextPageUrl,
1617
isGhes,
1718
IS_WINDOWS,
@@ -244,6 +245,44 @@ describe('Version from file test', () => {
244245
expect(_fn(toolVersionFilePath)).toEqual(['3.14t-dev']);
245246
}
246247
);
248+
249+
it.each([getVersionInputFromPipfileFile, getVersionInputFromFile])(
250+
'Version from python_version in Pipfile',
251+
async _fn => {
252+
await io.mkdirP(tempDir);
253+
const pythonVersionFileName = 'Pipfile';
254+
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
255+
const pythonVersion = '3.13';
256+
const pythonVersionFileContent = `[requires]\npython_version = "${pythonVersion}"`;
257+
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
258+
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);
259+
}
260+
);
261+
262+
it.each([getVersionInputFromPipfileFile, getVersionInputFromFile])(
263+
'Version from python_full_version in Pipfile',
264+
async _fn => {
265+
await io.mkdirP(tempDir);
266+
const pythonVersionFileName = 'Pipfile';
267+
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
268+
const pythonVersion = '3.13.0';
269+
const pythonVersionFileContent = `[requires]\npython_full_version = "${pythonVersion}"`;
270+
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
271+
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);
272+
}
273+
);
274+
275+
it.each([getVersionInputFromPipfileFile, getVersionInputFromFile])(
276+
'Pipfile undefined version',
277+
async _fn => {
278+
await io.mkdirP(tempDir);
279+
const pythonVersionFileName = 'Pipfile';
280+
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
281+
const pythonVersionFileContent = ``;
282+
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
283+
expect(_fn(pythonVersionFilePath)).toEqual([]);
284+
}
285+
);
247286
});
248287

249288
describe('getNextPageUrl', () => {

dist/setup/index.js

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96945,7 +96945,7 @@ function findPyPyVersion(versionSpec, architecture, updateEnvironment, checkLate
9694596945
core.addPath(pythonLocation);
9694696946
core.addPath(_binDir);
9694796947
}
96948-
core.setOutput('python-version', 'pypy' + resolvedPyPyVersion);
96948+
core.setOutput('python-version', `pypy${resolvedPythonVersion}-${resolvedPyPyVersion}`);
9694996949
core.setOutput('python-path', pythonPath);
9695096950
return { resolvedPyPyVersion, resolvedPythonVersion };
9695196951
});
@@ -98137,7 +98137,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
9813798137
return (mod && mod.__esModule) ? mod : { "default": mod };
9813898138
};
9813998139
Object.defineProperty(exports, "__esModule", ({ value: true }));
98140-
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;
98140+
exports.getDownloadFileName = exports.getNextPageUrl = exports.getBinaryDirectory = exports.getVersionInputFromFile = exports.getVersionInputFromPipfileFile = 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;
9814198141
/* eslint no-unsafe-finally: "off" */
9814298142
const cache = __importStar(__nccwpck_require__(5116));
9814398143
const core = __importStar(__nccwpck_require__(7484));
@@ -98407,7 +98407,41 @@ function getVersionInputFromToolVersions(versionFile) {
9840798407
}
9840898408
exports.getVersionInputFromToolVersions = getVersionInputFromToolVersions;
9840998409
/**
98410-
* Python version extracted from a plain, .tool-versions or TOML file.
98410+
* Python version extracted from the Pipfile file.
98411+
*/
98412+
function getVersionInputFromPipfileFile(versionFile) {
98413+
core.debug(`Trying to resolve version from ${versionFile}`);
98414+
if (!fs_1.default.existsSync(versionFile)) {
98415+
core.warning(`File ${versionFile} does not exist.`);
98416+
return [];
98417+
}
98418+
let pipfileFile = fs_1.default.readFileSync(versionFile, 'utf8');
98419+
// Normalize the line endings in the pipfileFile
98420+
pipfileFile = pipfileFile.replace(/\r\n/g, '\n');
98421+
const pipfileConfig = toml.parse(pipfileFile);
98422+
const keys = ['requires'];
98423+
if (!('requires' in pipfileConfig)) {
98424+
core.warning(`No Python version found in ${versionFile}`);
98425+
return [];
98426+
}
98427+
if ('python_full_version' in pipfileConfig['requires']) {
98428+
// specifies a full python version
98429+
keys.push('python_full_version');
98430+
}
98431+
else {
98432+
keys.push('python_version');
98433+
}
98434+
const versions = [];
98435+
const version = extractValue(pipfileConfig, keys);
98436+
if (version !== undefined) {
98437+
versions.push(version);
98438+
}
98439+
core.info(`Extracted ${versions} from ${versionFile}`);
98440+
return versions;
98441+
}
98442+
exports.getVersionInputFromPipfileFile = getVersionInputFromPipfileFile;
98443+
/**
98444+
* Python version extracted from a plain, .tool-versions, Pipfile or TOML file.
9841198445
*/
9841298446
function getVersionInputFromFile(versionFile) {
9841398447
if (versionFile.endsWith('.toml')) {
@@ -98416,6 +98450,9 @@ function getVersionInputFromFile(versionFile) {
9841698450
else if (versionFile.match('.tool-versions')) {
9841798451
return getVersionInputFromToolVersions(versionFile);
9841898452
}
98453+
else if (versionFile.match('Pipfile')) {
98454+
return getVersionInputFromPipfileFile(versionFile);
98455+
}
9841998456
else {
9842098457
return getVersionsInputFromPlainFile(versionFile);
9842198458
}

docs/advanced-usage.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,15 @@ steps:
310310
- run: python my_script.py
311311
```
312312

313+
```yaml
314+
steps:
315+
- uses: actions/checkout@v4
316+
- uses: actions/setup-python@v5
317+
with:
318+
python-version-file: 'Pipfile' # Read python version from a file Pipfile
319+
- run: python my_script.py
320+
```
321+
313322
## Check latest version
314323

315324
The `check-latest` flag defaults to `false`. Use the default or set `check-latest` to `false` if you prefer stability and if you want to ensure a specific `Python or PyPy` version is always used.

src/find-pypy.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ export async function findPyPyVersion(
9696
core.addPath(pythonLocation);
9797
core.addPath(_binDir);
9898
}
99-
core.setOutput('python-version', 'pypy' + resolvedPyPyVersion);
99+
core.setOutput(
100+
'python-version',
101+
`pypy${resolvedPythonVersion}-${resolvedPyPyVersion}`
102+
);
100103
core.setOutput('python-path', pythonPath);
101104

102105
return {resolvedPyPyVersion, resolvedPythonVersion};

0 commit comments

Comments
 (0)