Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Commit e33140f

Browse files
authored
Fix macOS and Python 2.7 tests (#144)
Also ensure we require the C extension to build when running CI.
1 parent 7ee0915 commit e33140f

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

.github/workflows/tests.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,40 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
os: [ubuntu-latest, macos-latest, windows-latest]
16-
python-version: ['2.7', 'pypy-2.7', '3.9', '3.10', '3.11']
16+
python-version: ['pypy-2.7', '3.9', '3.10', '3.11']
1717
exclude:
1818
- os: macos-latest
1919
python-version: 'pypy-2.7'
20+
- os: windows-latest
21+
python-version: 'pypy-2.7'
2022
steps:
2123
- uses: actions/checkout@v2
2224
- name: Set up Python
2325
uses: actions/setup-python@v2
2426
with:
2527
python-version: ${{ matrix.python-version }}
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install wheel
31+
- name: Install
32+
shell: bash
33+
run: |
34+
SCANDIR_REQUIRE_C_EXTENSION=1 python -m pip -v install .
35+
- name: Run tests
36+
run: |
37+
python test/run_tests.py
38+
build27:
39+
runs-on: ubuntu-latest
40+
container:
41+
image: python:2.7.18-buster
42+
steps:
43+
- uses: actions/checkout@v2
44+
- name: Install dependencies
45+
run: |
46+
python -m pip install wheel
47+
- name: Install
48+
run: |
49+
SCANDIR_REQUIRE_C_EXTENSION=1 python -m pip -v install .
2650
- name: Run tests
2751
run: |
28-
python --version
29-
python setup.py install
3052
python test/run_tests.py

setup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import sys
1818
import logging
1919

20+
require_c_extension = bool(os.environ.get('SCANDIR_REQUIRE_C_EXTENSION'))
21+
2022
# Get version without importing scandir because that will lock the
2123
# .pyd file (if scandir is already installed) so it can't be
2224
# overwritten during the install process
@@ -42,10 +44,13 @@ def build_extension(self, ext):
4244
try:
4345
base_build_ext.build_extension(self, ext)
4446
except Exception:
47+
if require_c_extension:
48+
logging.error('SCANDIR_REQUIRE_C_EXTENSION is set, not falling back to Python implementation')
49+
raise
4550
info = sys.exc_info()
4651
logging.warn("building %s failed with %s: %s", ext.name, info[0], info[1])
4752

48-
extension = Extension('_scandir', ['_scandir.c'], optional=True)
53+
extension = Extension('_scandir', ['_scandir.c'], optional=not require_c_extension)
4954

5055

5156
setup(

0 commit comments

Comments
 (0)