8000 GitHub - phonomenal/setup-python: Set up your GitHub Actions workflow with a specific version of python
[go: up one dir, main page]

Skip to content

phonomenal/setup-python

 
 

Repository files navigation

setup-python V2

GitHub Actions status

This action sets up a Python environment for use in actions by:

  • optionally installing and adding to PATH a version of Python that is already installed in the tools cache
  • downloading, installing and adding to PATH an available version of Python from GitHub Releases (actions/python-versions) if a specific version is not available in the tools cache
  • failing if a specific version of Python is not preinstalled or available for download
  • registering problem matchers for error output

What's new

  • Ability to download, install and set up Python packages from actions/python-versions that do not come preinstalled on runners
    • Allows for pinning to a specific patch version of Python without the worry of it ever being removed or changed
  • Automatic setup and download of Python packages if using a self-hosted runner
  • Support for pre-release versions of Python

Usage

See action.yml

Basic:

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
  with:
    python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax
    architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
- run: python my_script.py

Matrix Testing:

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [ '2.x', '3.x', 'pypy2', 'pypy3' ]
    name: Python ${{ matrix.python-version }} sample
    steps:
      - uses: actions/checkout@v2
      - name: Setup python
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
          architecture: x64
      - run: python my_script.py

Exclude a specific Python version:

jobs:
  build:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        python-version: [2.7, 3.6, 3.7, 3.8, pypy2, pypy3]
        exclude:
          - os: macos-latest
            python-version: 3.8
          - os: windows-latest
            python-version: 3.6
    steps:
      - uses: actions/checkout@v2
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - name: Display Python version
        run: python -c "import sys; print(sys.version)"

Download and set up a version of Python that does not come preinstalled on an image:

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
        # in this example, there is a newer version already installed, 3.7.7, so the older version will be downloaded
        python-version: [3.5, 3.6, 3.7.4, 3.8]
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - run: python my_script.py

Download and set up a accurate pre-release version of Python:

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
  with:
    python-version: '3.9.0-beta.4'
- run: python my_script.py

Download and set up the latest available version of Python (includes both pre-release and stable versions):

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
  with:
    python-version: '3.9.0-alpha - 3.9.0' # SemVer's version range syntax
- run: python my_script.py

Getting started with Python + Actions

Check out our detailed guide on using Python with GitHub Actions.

Available versions of Python