Skip to content

Commit

Permalink
Fix macOS and Python 2.7 tests (#144)
Browse files Browse the repository at this point in the history
Also ensure we require the C extension to build when running CI.
  • Loading branch information
cielavenir authored Aug 29, 2023
1 parent 7ee0915 commit e33140f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
28 changes: 25 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down

0 comments on commit e33140f

Please sign in to comment.