Skip to content

Commit d13da58

Browse files
lazkajaraco
authored andcommitted
CI: add a job for running tests under MSVC CPython with GCC as the default compiler
The tests currently assume everywhere that there is only one compiler per platform, and while it would be possible to parametrize all the tests it would make things more complex and we'd also have to decide which compiler is required for running the tests and which one is optional etc. To avoid all this introduce a DISTUTILS_TEST_DEFAULT_COMPILER env var which can be used to override the default compiler type for the whole test run. This keeps the tests as is and makes sure all tests run against the alternative compiler. Also add it to pass_env for tox, so it gets passed to pytest, if set. The added CI job installs an ucrt targeting GCC via MSYS2, and forces the MSVC CPython to use it via DISTUTILS_TEST_DEFAULT_COMPILER=mingw32.
1 parent 127371a commit d13da58

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

.github/workflows/main.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,28 @@ jobs:
163163
source /tmp/venv/bin/activate
164164
pytest
165165
166+
test_msvc_python_mingw:
167+
runs-on: windows-latest
168+
steps:
169+
- uses: actions/checkout@v4
170+
- name: Setup Python
171+
uses: actions/setup-python@v4
172+
with:
173+
python-version: 3.12
174+
- name: Install tox
175+
run: python -m pip install tox
176+
- name: Install GCC
177+
uses: msys2/setup-msys2@v2
178+
with:
179+
msystem: ucrt64
180+
install: mingw-w64-ucrt-x86_64-cc
181+
- name: Run
182+
run: |
183+
$env:MSYS2_ROOT = msys2 -c 'cygpath -m /'
184+
$env:PATH = "$env:MSYS2_ROOT/ucrt64/bin;$env:PATH"
185+
$env:DISTUTILS_TEST_DEFAULT_COMPILER = "mingw32"
186+
tox
187+
166188
ci_setuptools:
167189
# Integration testing with setuptools
168190
strategy:

conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,26 @@ def disable_macos_customization(monkeypatch):
162162
from distutils import sysconfig
163163

164164
monkeypatch.setattr(sysconfig, '_customize_macos', lambda: None)
165+
166+
167+
@pytest.fixture(autouse=True, scope="session")
168+
def monkey_patch_get_default_compiler():
169+
"""
170+
Monkey patch distutils get_default_compiler to allow overriding the
171+
default compiler. Mainly to test mingw32 with a MSVC Python.
172+
"""
173+
from distutils import ccompiler
174+
175+
default_compiler = os.environ.get("DISTUTILS_TEST_DEFAULT_COMPILER")
176+
177+
if default_compiler is not None:
178+
179+
def patched_get_default_compiler(*args, **kwargs):
180+
return default_compiler
181+
182+
original = ccompiler.get_default_compiler
183+
ccompiler.get_default_compiler = patched_get_default_compiler
184+
yield
185+
ccompiler.get_default_compiler = original
186+
else:
187+
yield

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ setenv =
55
PYTHONWARNDEFAULTENCODING = 1
66
# pypa/distutils#99
77
VIRTUALENV_NO_SETUPTOOLS = 1
8+
pass_env =
9+
DISTUTILS_TEST_DEFAULT_COMPILER
810
commands =
911
pytest {posargs}
1012
usedevelop = True

0 commit comments

Comments
 (0)