diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 51e9cff..37bba23 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,18 +13,40 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ['2.7', 'pypy-2.7', '3.9', '3.10', '3.11'] + python-version: ['pypy-2.7', '3.9', '3.10', '3.11'] exclude: - os: macos-latest python-version: 'pypy-2.7' + - os: windows-latest + python-version: 'pypy-2.7' steps: - uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install wheel + - name: Install + shell: bash + run: | + SCANDIR_REQUIRE_C_EXTENSION=1 python -m pip -v install . + - name: Run tests + run: | + python test/run_tests.py + build27: + runs-on: ubuntu-latest + container: + image: python:2.7.18-buster + steps: + - uses: actions/checkout@v2 + - name: Install dependencies + run: | + python -m pip install wheel + - name: Install + run: | + SCANDIR_REQUIRE_C_EXTENSION=1 python -m pip -v install . - name: Run tests run: | - python --version - python setup.py install python test/run_tests.py diff --git a/setup.py b/setup.py index fded786..e90c8c6 100644 --- a/setup.py +++ b/setup.py @@ -17,6 +17,8 @@ import sys import logging +require_c_extension = bool(os.environ.get('SCANDIR_REQUIRE_C_EXTENSION')) + # Get version without importing scandir because that will lock the # .pyd file (if scandir is already installed) so it can't be # overwritten during the install process @@ -42,10 +44,13 @@ def build_extension(self, ext): try: base_build_ext.build_extension(self, ext) except Exception: + if require_c_extension: + logging.error('SCANDIR_REQUIRE_C_EXTENSION is set, not falling back to Python implementation') + raise info = sys.exc_info() logging.warn("building %s failed with %s: %s", ext.name, info[0], info[1]) -extension = Extension('_scandir', ['_scandir.c'], optional=True) +extension = Extension('_scandir', ['_scandir.c'], optional=not require_c_extension) setup(