ni/python-actions
is a Git repository containing reusable GitHub Actions for NI Python projects.
The setup-python
action installs Python and adds it to the PATH.
It is a thin wrapper for https://github.com/actions/setup-python which is intended to single-source the default Python version for multiple NI Python projects.
By default, this action installs Python 3.11.9.
steps:
- uses: ni/python-actions/[email protected]
You can specify the python-version
input for testing with multiple versions of Python:
strategy:
matrix:
python-version: [3.9, '3.10', 3.11, 3.12, 3.13]
steps:
- uses: ni/python-actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
You can use the python-version
output to get the actual version of Python, which is useful for caching:
steps:
- uses: ni/python-actions/[email protected]
id: setup-python
- uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}
actions/setup-python
sets the pythonLocation
environment variable to the directory
containing the Python installation.
You can also use the python-path
output to get the path to the Python interpreter:
steps:
- uses: ni/python-actions/[email protected]
id: setup-python
- run: pipx install <package> --python ${{ steps.setup-python.outputs.python-version }}
The setup-poetry
action installs Poetry, adds it to the PATH, and caches it to speed up
workflows.
This action installs Poetry using the Python version that was selected by the setup-python
action, so you must call setup-python
first.
By default, this action installs Poetry 1.8.2.
steps:
- uses: ni/python-actions/[email protected]
- uses: ni/python-actions/[email protected]
- run: poetry install -v
steps:
- uses: ni/python-actions/[email protected]
- uses: ni/python-actions/[email protected]
with:
poetry-version: 2.1.3
- run: poetry install -v