简体   繁体   中英

GitHub Workflow on Windows with Python 2 and 3

I'm trying to create a GitHub workflow to trigger tests of my repository for which I need both Python 2 and Python 3.

The solution I'm trying to implement looks like this:

Job1:
    name: Running Unittests
    runs-on: windows-latest
    strategy:
      matrix:
        python-version: [3.8]
    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v4
      with:
        python-version: ${{ matrix.python-version }}
    - name: Set up Python2.7
      uses: actions/setup-python@v4
      id: setup-python2
      with:
        python-version: 2.7
        update-environment: false
    - name: Add Python2.7 to path
      run: |
        python2_path=${{ steps.setup-python2.outputs.python-path }}
        echo "Python2.7 path: $python2_path / ${{ steps.setup-python2.outputs.python-path }}"
        
        python2_dir="$(dirname "$python2_path")"
        new_python2_path=${python2_dir}/python2.7.exe
        
        mv "${python2_path}" "${new_python2_path}"
        export "$new_python2_path" >> $GITHUB_PATH
        echo "GITHUB_PATH: $GITHUB_PATH"
      shell: bash
    - name: Install dependencies and setup
      run: |
        curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
        python2.7 get-pip.py
        python2.7 -m pip install numpy
        pip install .
    - ... (other steps including unittests in Python 3)

Unfortunately, I'm getting 2 issues here for which I'd like some help:

  1. I've found the keyword 'update-environment' in actions/setup-python@v4 ( https://github.com/actions/setup-python/blob/c4e89fac7e8767b327bbad6cb4d859eda999cf08/action.yml#L20 ), but I get a warning when using it in my workflow:
Warning: Unexpected input(s) 'update-environment', valid inputs are ['python-version', 'python-version-file', 'cache', 'architecture', 'token', 'cache-dependency-path']
  1. In the step "Add Python2.7 to path", the separators "\" are removed in the variable python2_path I've set, making the mv command fail. Here's the output of that step:
Run python2_path=C:\hostedtoolcache\windows\Python\2.7.18\x64\python.exe
  
mv: cannot stat 'C:hostedtoolcachewindowsPython2.7.18x64python.exe': No such file or directory
Python2.7 path: C:hostedtoolcachewindowsPython2.7.18x64python.exe / C:\hostedtoolcache\windows\Python\2.7.18\x64\python.exe
Error: Process completed with exit code 1.

Do you have ideas for how to install Python 2 and 3 in a GitHub workflow, and then call both versions independently ?

You should look into using "tox" for your testing. It will set up environments for multiple versions os python and run your unit tests on each.

See: https://tox.wiki/en/latest/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM