GeospatialPython / pyshp

This library reads and writes ESRI Shapefiles in pure Python.
MIT License
1.09k stars 259 forks source link

Build marked as failing. Tests are not running in CI. Github /actions/setup-python no longer supports Python 2.7. #262

Closed JamesParrott closed 7 months ago

JamesParrott commented 8 months ago

PyShp Version

All

Python Version

CI

Your code

The issue already occurs, due to PyShps's own CI code/config/setup. In particular the Github action file below: https://github.com/GeospatialPython/pyshp/blob/master/.github/workflows/build.yml


# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: build

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9"]

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        python -m pip install pytest
        if [ -f requirements.test.txt ]; then pip install -r requirements.test.txt; fi
    - name: Test with doctest
      run: |
        python shapefile.py
    - name: Test with pytest
      run: |
        pytest

Full stacktrace

https://github.com/GeospatialPython/pyshp/actions

Other notes

In June 2023, Python 2 was dropped by /actions/setup-python https://github.com/actions/setup-python/issues/672

A work around to run the action in a container, is suggested in the comments by tzortzispanagiotis (the proviso about localhost is not relevant to PyShp as it does not do any networking): https://github.com/actions/setup-python/issues/672#issuecomment-1589120020

I'll investigate using that with the actions matrix. Python 2 is no longer pre-installed in current Actions Runner Ubuntu images (19.04 having been dropped?).

https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2004-Readme.md

JamesParrott commented 8 months ago

The suggestion from tzortzispanagiotis works great with a matrix strategy, for PyShp.

Using this, the CI can be fixed, simply by replacing all the lines in the above file between:

jobs:
  build:

and

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip

(exclusive) with:

    strategy:
      fail-fast: false
      matrix:
        python-version: ["2.7.18", "3.6.15", "3.7.17", "3.8.18", "3.9.18", "3.10.13", "3.11.7", "3.12.1", "3.13.0a2"]

    runs-on: ubuntu-20.04
    container:
      image: python:${{ matrix.python-version }}-slim

    steps:
    - uses: actions/checkout@v3

I have tested this on my fork, but could only get a green tick for Python 2.7 as well, by disabling __geo_interface__, and all the tests for it, and for Pythons 3.10 upwards by relaxing the pinned version of Pytest, allowing Pip to pick the latest (and possibly by making other changes that don't spring to mine right now):

image

https://github.com/JamesParrott/IronPyShp/actions/runs/7534760731