diff --git a/.github/workflows/test-pypy.yml b/.github/workflows/test-pypy.yml index 0eb06c393..c1ea47694 100644 --- a/.github/workflows/test-pypy.yml +++ b/.github/workflows/test-pypy.yml @@ -37,10 +37,22 @@ jobs: uses: actions/checkout@v2 - name: setup-python ${{ matrix.pypy }} + id: setup-python uses: ./ with: python-version: ${{ matrix.pypy }} - + + - name: Check python-path + run: | + PATH_PYTHON=$(python -c 'import sys; print(sys.executable)') + SETUP_PYTHON=$('${{ steps.setup-python.outputs.python-path }}' -c 'import sys; print(sys.executable)') + if [ "${SETUP_PYTHON}" != "${PATH_PYTHON}" ]; then + echo "Executable mismatch. python in PATH is ${PATH_PYTHON}; python-path (${{ steps.setup-python.outputs.python-path }}) is ${SETUP_PYTHON}" + exit 1 + fi + echo 'python-path: ${{ steps.setup-python.outputs.python-path }}' + shell: bash + - name: PyPy and Python version run: python --version diff --git a/.github/workflows/test-python.yml b/.github/workflows/test-python.yml index 8f2330152..539216d44 100644 --- a/.github/workflows/test-python.yml +++ b/.github/workflows/test-python.yml @@ -23,9 +23,21 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: setup default python + - name: setup default python + id: setup-python uses: ./ + - name: Check python-path + run: | + PATH_PYTHON=$(python -c 'import sys; print(sys.executable)') + SETUP_PYTHON=$('${{ steps.setup-python.outputs.python-path }}' -c 'import sys; print(sys.executable)') + if [ "${SETUP_PYTHON}" != "${PATH_PYTHON}" ]; then + echo "Executable mismatch. python in PATH is ${PATH_PYTHON}; python-path (${{ steps.setup-python.outputs.python-path }}) is ${SETUP_PYTHON}" + exit 1 + fi + echo 'python-path: ${{ steps.setup-python.outputs.python-path }}' + shell: bash + - name: Validate version run: python --version @@ -45,10 +57,22 @@ jobs: uses: actions/checkout@v2 - name: setup-python ${{ matrix.python }} + id: setup-python uses: ./ with: python-version: ${{ matrix.python }} + - name: Check python-path + run: | + PATH_PYTHON=$(python -c 'import sys; print(sys.executable)') + SETUP_PYTHON=$('${{ steps.setup-python.outputs.python-path }}' -c 'import sys; print(sys.executable)') + if [ "${SETUP_PYTHON}" != "${PATH_PYTHON}" ]; then + echo "Executable mismatch. python in PATH is ${PATH_PYTHON}; python-path (${{ steps.setup-python.outputs.python-path }}) is ${SETUP_PYTHON}" + exit 1 + fi + echo 'python-path: ${{ steps.setup-python.outputs.python-path }}' + shell: bash + - name: Validate version run: | $pythonVersion = (python --version) @@ -74,10 +98,22 @@ jobs: uses: actions/checkout@v2 - name: setup-python 3.9.0-beta.4 + id: setup-python uses: ./ with: python-version: '3.9.0-beta.4' + - name: Check python-path + run: | + PATH_PYTHON=$(python -c 'import sys; print(sys.executable)') + SETUP_PYTHON=$('${{ steps.setup-python.outputs.python-path }}' -c 'import sys; print(sys.executable)') + if [ "${SETUP_PYTHON}" != "${PATH_PYTHON}" ]; then + echo "Executable mismatch. python in PATH is ${PATH_PYTHON}; python-path (${{ steps.setup-python.outputs.python-path }}) is ${SETUP_PYTHON}" + exit 1 + fi + echo 'python-path: ${{ steps.setup-python.outputs.python-path }}' + shell: bash + - name: Validate version run: | $pythonVersion = (python --version) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index fee5ae793..171e20552 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -89,3 +89,13 @@ jobs: python-version: 3.8.1 - name: Verify 3.8.1 run: python __tests__/verify-python.py 3.8.1 + + - name: Run with setup-python 3.10 + id: cp310 + uses: ./ + with: + python-version: "3.10" + - name: Verify 3.10 + run: python __tests__/verify-python.py 3.10 + - name: Run python-path sample 3.10 + run: pipx run --python '${{ steps.cp310.outputs.python-path }}' nox --version diff --git a/README.md b/README.md index 2ace1f7f3..7508d353c 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,20 @@ jobs: ``` 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. +An output is available with the absolute path of the python interpreter executable if you need it: +```yaml +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + id: cp310 + with: + python-version: "3.10" + - run: pipx run --python '${{ steps.cp310.outputs.python-path }}' nox --version +``` + # Getting started with Python + Actions 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 --git a/action.yml b/action.yml index bda521dd1..4fd1d3a82 100644 --- a/action.yml +++ b/action.yml @@ -21,6 +21,8 @@ outputs: description: "The installed python version. Useful when given a version range as input." cache-hit: description: 'A boolean value to indicate a cache entry was found' + python-path: + description: "The absolute path to the python interpreter executable." runs: using: 'node16' main: 'dist/setup/index.js' diff --git a/dist/setup/index.js b/dist/setup/index.js index bf07395d5..6c83cfb1e 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -52375,12 +52375,15 @@ function findPyPyVersion(versionSpec, architecture) { } const pipDir = utils_1.IS_WINDOWS ? 'Scripts' : 'bin'; const _binDir = path.join(installDir, pipDir); + const binaryExtension = utils_1.IS_WINDOWS ? '.exe' : ''; + const pythonPath = path.join(utils_1.IS_WINDOWS ? installDir : _binDir, `python${binaryExtension}`); const pythonLocation = pypyInstall.getPyPyBinaryPath(installDir); core.exportVariable('pythonLocation', pythonLocation); core.exportVariable('PKG_CONFIG_PATH', pythonLocation + '/lib/pkgconfig'); core.addPath(pythonLocation); core.addPath(_binDir); core.setOutput('python-version', 'pypy' + resolvedPyPyVersion.trim()); + core.setOutput('python-path', pythonPath); return { resolvedPyPyVersion, resolvedPythonVersion }; }); } @@ -57027,8 +57030,11 @@ function useCpythonVersion(version, architecture) { core.exportVariable('LD_LIBRARY_PATH', pyLibPath + libPath); } } + const _binDir = binDir(installDir); + const binaryExtension = utils_1.IS_WINDOWS ? '.exe' : ''; + const pythonPath = path.join(utils_1.IS_WINDOWS ? installDir : _binDir, `python${binaryExtension}`); core.addPath(installDir); - core.addPath(binDir(installDir)); + core.addPath(_binDir); if (utils_1.IS_WINDOWS) { // Add --user directory // `installDir` from tool cache should look like $RUNNER_TOOL_CACHE/Python//x64/ @@ -57042,6 +57048,7 @@ function useCpythonVersion(version, architecture) { // On Linux and macOS, pip will create the --user directory and add it to PATH as needed. const installed = versionFromPath(installDir); core.setOutput('python-version', installed); + core.setOutput('python-path', pythonPath); return { impl: 'CPython', version: installed }; }); } diff --git a/src/find-pypy.ts b/src/find-pypy.ts index 5342c6498..1008ed6ea 100644 --- a/src/find-pypy.ts +++ b/src/find-pypy.ts @@ -48,12 +48,18 @@ export async function findPyPyVersion( const pipDir = IS_WINDOWS ? 'Scripts' : 'bin'; const _binDir = path.join(installDir, pipDir); + const binaryExtension = IS_WINDOWS ? '.exe' : ''; + const pythonPath = path.join( + IS_WINDOWS ? installDir : _binDir, + `python${binaryExtension}` + ); const pythonLocation = pypyInstall.getPyPyBinaryPath(installDir); core.exportVariable('pythonLocation', pythonLocation); core.exportVariable('PKG_CONFIG_PATH', pythonLocation + '/lib/pkgconfig'); core.addPath(pythonLocation); core.addPath(_binDir); core.setOutput('python-version', 'pypy' + resolvedPyPyVersion.trim()); + core.setOutput('python-path', pythonPath); return {resolvedPyPyVersion, resolvedPythonVersion}; } diff --git a/src/find-python.ts b/src/find-python.ts index 3959ecf14..0a3dde138 100644 --- a/src/find-python.ts +++ b/src/find-python.ts @@ -83,8 +83,14 @@ export async function useCpythonVersion( } } + const _binDir = binDir(installDir); + const binaryExtension = IS_WINDOWS ? '.exe' : ''; + const pythonPath = path.join( + IS_WINDOWS ? installDir : _binDir, + `python${binaryExtension}` + ); core.addPath(installDir); - core.addPath(binDir(installDir)); + core.addPath(_binDir); if (IS_WINDOWS) { // Add --user directory @@ -106,6 +112,7 @@ export async function useCpythonVersion( const installed = versionFromPath(installDir); core.setOutput('python-version', installed); + core.setOutput('python-path', pythonPath); return {impl: 'CPython', version: installed}; }