Using setup-python on Windows

Hello,

I am trying to add actions on Windows to one of my repos that has existing support for Linux and MacOS. Window’s is failing in a none obvious way to me. My job description looks like -

test:
 strategy:
 matrix:
 os: [windows-latest] runs-on: ${{ matrix.os }} steps:
 -uses: actions/checkout@v1 -uses: actions-rs/toolchain@v1 with:
 toolchain: nightly default: true -name: Unit tests run: cargo test -uses: actions/setup-python@v1 with:
 python-version: '3.7'-name: Test ${{ matrix.os }} binding run: |  
 python3 -m venv venv3 venv3\Scripts\Activate.ps1 python3 -m pip install maturin numpy maturin develop python3 -m unittest discover tests

Here is the resulting log from the build failing (and here is the [actual job).](http://%20 https://github.com/nanoporetech/fast-ctc-decode/runs/638666087)

2020-05-02T11:26:46.8753138Z##[group]Run actions/setup-python@v12020-05-02T11:26:46.8753394Zwith:2020-05-02T11:26:46.8753556Z python-version:3.72020-05-02T11:26:46.8753701Z architecture: x642020-05-02T11:26:46.8753843Z##[endgroup]2020-05-02T11:26:46.9972224ZSuccessfully setup CPython(3.7.6)2020-05-02T11:26:47.0429209Z##[group]Run python3 -m venv venv32020-05-02T11:26:47.0429485Z python3 -m venv venv3  
2020-05-02T11:26:47.0429617Z venv3\Scripts\Activate.ps1  
2020-05-02T11:26:47.0429746Z python3 -m pip install maturin numpy  
2020-05-02T11:26:47.0429871Z maturin develop  
2020-05-02T11:26:47.0430000Z python3 -m unittest discover tests  
2020-05-02T11:26:47.0470479Z shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"2020-05-02T11:26:47.0470607Z env:2020-05-02T11:26:47.0470733Z pythonLocation: C:\hostedtoolcache\windows\Python\3.7.6\x642020-05-02T11:26:47.0470858Z##[endgroup]2020-05-02T11:26:57.7836092Z##[error]Process completed with exit code 1.2020-05-02T11:26:57.7855441ZCleaning up orphan processes

I’m not sure which step it’s even failing on, any ideas?

@iiseymour ,

On Windows the normal name for the python executable is python.exe (console program) or pythonw.exe (for GUI programs).

The python executable is sometimes called python3 on some platforms, where the default ( python ) is the old python 2. On many UNIX-based (inc. Linux and OS X) systems, python 2 is used by system utilities, changing it could have bad consequences on those platforms, hence the name " python3".

On Windows you should be fine - there are other issues on Windows but you won’t get those unless you try to use more than one python version.

So, the following scripts can work on Windows (reference here):

- name: Test ${{ matrix.os }} binding
        run: |
          python -m venv venv3
          venv3/Scripts/Activate.ps1
          python -m pip install maturin numpy
          maturin develop
          python -m unittest discover tests
2 Likes

Thank you @brightran! I’m not a Windows user so I was not aware of the difference in how it’s handled. 

I have it working now albeit by copying the job definition completely. What would be a more elegant way to handle the difference in how the virtual environment needs to be activated? 

jobs:

  test:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v1
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly
          default: true
      - name: Rust unit tests
        run: cargo test
      - uses: actions/setup-python@v2
        with:
          python-version: '3.7'
      - name: Python unit tests
        run: |
          python3 -m venv venv3
          source venv3/bin/activate
          python3 -m pip install maturin numpy
          maturin develop
          python3 tests/test_decode.py

  test-windows:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly
          default: true
      - name: Rust unit tests
        run: cargo test
      - uses: actions/setup-python@v2
        with:
          python-version: '3.7'
      - name: Python unit tests
        run: |
          python -m venv venv3
          venv3\Scripts\Activate.ps1
          python -m pip install maturin numpy
          maturin develop
          python tests/test_decode.py
1 Like

@brightran I somehow kept getting the wrong codes when UK knew i was putting the right one in.

@iiseymour ,

If you want to integrate the jobs on different OSs into a same matrix, you can try like as below:

jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [windows-latest, ubuntu-latest, macos-latest]
    steps:
      - name: Checkout code
        uses: actions/checkout@v1

      - name: Installs Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: nightly
          default: true

      - name: Unit tests
        run: cargo test

      - name: Setup Python
        uses: actions/setup-python@v2
        with:
          python-version: '3.7'

      - name: Test Windows binding
        if: matrix.os == 'windows-latest'
        run: |
          python -m venv venv3
          venv3/Scripts/Activate.ps1
          python -m pip install maturin numpy
          maturin develop
          python -m unittest discover tests
      - name: Test Linux/macOS binding
        if: matrix.os != 'windows-latest'
        run: |
          python3 -m venv venv3
          source venv3/bin/activate
          python3 -m pip install maturin numpy
          maturin develop
          python3 tests/test_decode.py