Skip to content

Commit 081a3cf

Browse files
Merge pull request #405 from mayeut/interpreter-path
feature: add a `python-path` output
2 parents fff15a2 + ff70656 commit 081a3cf

File tree

9 files changed

+84
-4
lines changed

9 files changed

+84
-4
lines changed

Diff for: .github/workflows/test-pypy.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ jobs:
3737
uses: actions/checkout@v2
3838

3939
- name: setup-python ${{ matrix.pypy }}
40+
id: setup-python
4041
uses: ./
4142
with:
4243
python-version: ${{ matrix.pypy }}
43-
44+
45+
- name: Check python-path
46+
run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
47+
shell: bash
48+
4449
- name: PyPy and Python version
4550
run: python --version
4651

Diff for: .github/workflows/test-python.yml

+16-1
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ jobs:
2323
- name: Checkout
2424
uses: actions/checkout@v2
2525

26-
- name: setup default python
26+
- name: setup default python
27+
id: setup-python
2728
uses: ./
2829

30+
- name: Check python-path
31+
run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
32+
shell: bash
33+
2934
- name: Validate version
3035
run: python --version
3136

@@ -45,10 +50,15 @@ jobs:
4550
uses: actions/checkout@v2
4651

4752
- name: setup-python ${{ matrix.python }}
53+
id: setup-python
4854
uses: ./
4955
with:
5056
python-version: ${{ matrix.python }}
5157

58+
- name: Check python-path
59+
run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
60+
shell: bash
61+
5262
- name: Validate version
5363
run: |
5464
$pythonVersion = (python --version)
@@ -74,10 +84,15 @@ jobs:
7484
uses: actions/checkout@v2
7585

7686
- name: setup-python 3.9.0-beta.4
87+
id: setup-python
7788
uses: ./
7889
with:
7990
python-version: '3.9.0-beta.4'
8091

92+
- name: Check python-path
93+
run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
94+
shell: bash
95+
8196
- name: Validate version
8297
run: |
8398
$pythonVersion = (python --version)

Diff for: .github/workflows/workflow.yml

+10
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,13 @@ jobs:
8989
python-version: 3.8.1
9090
- name: Verify 3.8.1
9191
run: python __tests__/verify-python.py 3.8.1
92+
93+
- name: Run with setup-python 3.10
94+
id: cp310
95+
uses: ./
96+
with:
97+
python-version: "3.10"
98+
- name: Verify 3.10
99+
run: python __tests__/verify-python.py 3.10
100+
- name: Run python-path sample 3.10
101+
run: pipx run --python '${{ steps.cp310.outputs.python-path }}' nox --version

Diff for: README.md

+14
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,20 @@ jobs:
137137
```
138138
More details on PyPy syntax and examples of using preview / nightly versions of PyPy can be found in the [Available versions of PyPy](#available-versions-of-pypy) section.
139139
140+
An output is available with the absolute path of the python interpreter executable if you need it:
141+
```yaml
142+
jobs:
143+
build:
144+
runs-on: ubuntu-latest
145+
steps:
146+
- uses: actions/checkout@v3
147+
- uses: actions/setup-python@v3
148+
id: cp310
149+
with:
150+
python-version: "3.10"
151+
- run: pipx run --python '${{ steps.cp310.outputs.python-path }}' nox --version
152+
```
153+
140154
# Getting started with Python + Actions
141155
142156
Check out our detailed guide on using [Python with GitHub Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-python-with-github-actions).

Diff for: __tests__/check-python-path.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
PYTHON_PATH="$1"
6+
PATH_EXECUTABLE=$(python -c 'import sys; print(sys.executable)')
7+
PYTHON_PATH_EXECUTABLE=$("${PYTHON_PATH}" -c 'import sys; print(sys.executable)')
8+
if [ "${PATH_EXECUTABLE}" != "${PYTHON_PATH_EXECUTABLE}" ]; then
9+
echo "Executable mismatch."
10+
echo "python in PATH is: ${PATH_EXECUTABLE}"
11+
echo "python-path (${PYTHON_PATH}) is: ${PYTHON_PATH_EXECUTABLE}"
12+
exit 1
13+
fi
14+
echo "python-path: ${PYTHON_PATH}"

Diff for: action.yml

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ outputs:
2121
description: "The installed python version. Useful when given a version range as input."
2222
cache-hit:
2323
description: 'A boolean value to indicate a cache entry was found'
24+
python-path:
25+
description: "The absolute path to the Python executable."
2426
runs:
2527
using: 'node16'
2628
main: 'dist/setup/index.js'

Diff for: dist/setup/index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -52375,12 +52375,15 @@ function findPyPyVersion(versionSpec, architecture) {
5237552375
}
5237652376
const pipDir = utils_1.IS_WINDOWS ? 'Scripts' : 'bin';
5237752377
const _binDir = path.join(installDir, pipDir);
52378+
const binaryExtension = utils_1.IS_WINDOWS ? '.exe' : '';
52379+
const pythonPath = path.join(utils_1.IS_WINDOWS ? installDir : _binDir, `python${binaryExtension}`);
5237852380
const pythonLocation = pypyInstall.getPyPyBinaryPath(installDir);
5237952381
core.exportVariable('pythonLocation', pythonLocation);
5238052382
core.exportVariable('PKG_CONFIG_PATH', pythonLocation + '/lib/pkgconfig');
5238152383
core.addPath(pythonLocation);
5238252384
core.addPath(_binDir);
5238352385
core.setOutput('python-version', 'pypy' + resolvedPyPyVersion.trim());
52386+
core.setOutput('python-path', pythonPath);
5238452387
return { resolvedPyPyVersion, resolvedPythonVersion };
5238552388
});
5238652389
}
@@ -57027,8 +57030,11 @@ function useCpythonVersion(version, architecture) {
5702757030
core.exportVariable('LD_LIBRARY_PATH', pyLibPath + libPath);
5702857031
}
5702957032
}
57033+
const _binDir = binDir(installDir);
57034+
const binaryExtension = utils_1.IS_WINDOWS ? '.exe' : '';
57035+
const pythonPath = path.join(utils_1.IS_WINDOWS ? installDir : _binDir, `python${binaryExtension}`);
5703057036
core.addPath(installDir);
57031-
core.addPath(binDir(installDir));
57037+
core.addPath(_binDir);
5703257038
if (utils_1.IS_WINDOWS) {
5703357039
// Add --user directory
5703457040
// `installDir` from tool cache should look like $RUNNER_TOOL_CACHE/Python/<semantic version>/x64/
@@ -57042,6 +57048,7 @@ function useCpythonVersion(version, architecture) {
5704257048
// On Linux and macOS, pip will create the --user directory and add it to PATH as needed.
5704357049
const installed = versionFromPath(installDir);
5704457050
core.setOutput('python-version', installed);
57051+
core.setOutput('python-path', pythonPath);
5704557052
return { impl: 'CPython', version: installed };
5704657053
});
5704757054
}

Diff for: src/find-pypy.ts

+6
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,18 @@ export async function findPyPyVersion(
4848

4949
const pipDir = IS_WINDOWS ? 'Scripts' : 'bin';
5050
const _binDir = path.join(installDir, pipDir);
51+
const binaryExtension = IS_WINDOWS ? '.exe' : '';
52+
const pythonPath = path.join(
53+
IS_WINDOWS ? installDir : _binDir,
54+
`python${binaryExtension}`
55+
);
5156
const pythonLocation = pypyInstall.getPyPyBinaryPath(installDir);
5257
core.exportVariable('pythonLocation', pythonLocation);
5358
core.exportVariable('PKG_CONFIG_PATH', pythonLocation + '/lib/pkgconfig');
5459
core.addPath(pythonLocation);
5560
core.addPath(_binDir);
5661
core.setOutput('python-version', 'pypy' + resolvedPyPyVersion.trim());
62+
core.setOutput('python-path', pythonPath);
5763

5864
return {resolvedPyPyVersion, resolvedPythonVersion};
5965
}

Diff for: src/find-python.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,14 @@ export async function useCpythonVersion(
8383
}
8484
}
8585

86+
const _binDir = binDir(installDir);
87+
const binaryExtension = IS_WINDOWS ? '.exe' : '';
88+
const pythonPath = path.join(
89+
IS_WINDOWS ? installDir : _binDir,
90+
`python${binaryExtension}`
91+
);
8692
core.addPath(installDir);
87-
core.addPath(binDir(installDir));
93+
core.addPath(_binDir);
8894

8995
if (IS_WINDOWS) {
9096
// Add --user directory
@@ -106,6 +112,7 @@ export async function useCpythonVersion(
106112

107113
const installed = versionFromPath(installDir);
108114
core.setOutput('python-version', installed);
115+
core.setOutput('python-path', pythonPath);
109116

110117
return {impl: 'CPython', version: installed};
111118
}

0 commit comments

Comments
 (0)