Skip to content

Commit

Permalink
CI: add a job for running tests under MSVC CPython with GCC as the de…
Browse files Browse the repository at this point in the history
…fault 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.
  • Loading branch information
lazka committed Jul 21, 2024
1 parent e1e9f61 commit 6a39d04
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,28 @@ jobs:
source /tmp/venv/bin/activate
pytest
test_msvc_python_mingw:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.12
- name: Install tox
run: python -m pip install tox
- name: Install GCC
uses: msys2/setup-msys2@v2
with:
msystem: ucrt64
install: mingw-w64-ucrt-x86_64-cc
- name: Run
run: |
$env:MSYS2_ROOT = msys2 -c 'cygpath -m /'
$env:PATH = "$env:MSYS2_ROOT/ucrt64/bin;$env:PATH"
$env:DISTUTILS_TEST_DEFAULT_COMPILER = "mingw32"
tox
ci_setuptools:
# Integration testing with setuptools
strategy:
Expand Down
23 changes: 23 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,26 @@ def disable_macos_customization(monkeypatch):
from distutils import sysconfig

monkeypatch.setattr(sysconfig, '_customize_macos', lambda: None)


@pytest.fixture(autouse=True, scope="session")
def monkey_patch_get_default_compiler():
"""
Monkey patch distutils get_default_compiler to allow overriding the
default compiler. Mainly to test mingw32 with a MSVC Python.
"""
from distutils import ccompiler

default_compiler = os.environ.get("DISTUTILS_TEST_DEFAULT_COMPILER")

if default_compiler is not None:

def patched_get_default_compiler(*args, **kwargs):
return default_compiler

original = ccompiler.get_default_compiler
ccompiler.get_default_compiler = patched_get_default_compiler
yield
ccompiler.get_default_compiler = original
else:
yield
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ setenv =
PYTHONWARNDEFAULTENCODING = 1
# pypa/distutils#99
VIRTUALENV_NO_SETUPTOOLS = 1
pass_env =
DISTUTILS_TEST_DEFAULT_COMPILER
commands =
pytest {posargs}
usedevelop = True
Expand Down

0 comments on commit 6a39d04

Please sign in to comment.