From fa7e35b063318d6909825ba678aedeb672a17219 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sun, 21 Jul 2024 14:37:10 +0200 Subject: [PATCH] wip --- .github/workflows/main.yml | 21 +++++++++++++++++++++ distutils/tests/__init__.py | 22 +++++++++++++++++++--- distutils/tests/test_build_ext.py | 10 +++++++--- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 70d70bc6..5246952e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -163,6 +163,27 @@ 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.x + - 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" + tox + ci_setuptools: # Integration testing with setuptools strategy: diff --git a/distutils/tests/__init__.py b/distutils/tests/__init__.py index 93fbf490..5f9c2175 100644 --- a/distutils/tests/__init__.py +++ b/distutils/tests/__init__.py @@ -8,10 +8,12 @@ """ import shutil -from typing import Sequence +from typing import Sequence, Optional -def missing_compiler_executable(cmd_names: Sequence[str] = []): # pragma: no cover +def missing_compiler_executable( + cmd_names: Sequence[str] = [], compiler_type: Optional[str] = None +): # pragma: no cover """Check if the compiler components used to build the interpreter exist. Check for the existence of the compiler executables whose names are listed @@ -22,7 +24,7 @@ def missing_compiler_executable(cmd_names: Sequence[str] = []): # pragma: no co """ from distutils import ccompiler, errors, sysconfig - compiler = ccompiler.new_compiler() + compiler = ccompiler.new_compiler(compiler=compiler_type) sysconfig.customize_compiler(compiler) if compiler.compiler_type == "msvc": # MSVC has no executables, so check whether initialization succeeds @@ -40,3 +42,17 @@ def missing_compiler_executable(cmd_names: Sequence[str] = []): # pragma: no co continue if shutil.which(cmd[0]) is None: return cmd[0] + + +def get_possible_compiler_types() -> Sequence[str]: + """Returns a list of compiler types that could be used to build extensions + for the current interpreter. + """ + from distutils import ccompiler + + compiler_types = [] + default_compiler_type = ccompiler.get_default_compiler() + compiler_types.append(default_compiler_type) + if default_compiler_type == "msvc": + compiler_types.append("mingw32") + return compiler_types diff --git a/distutils/tests/test_build_ext.py b/distutils/tests/test_build_ext.py index 6c4c4ba8..707de393 100644 --- a/distutils/tests/test_build_ext.py +++ b/distutils/tests/test_build_ext.py @@ -18,7 +18,7 @@ UnknownFileError, ) from distutils.extension import Extension -from distutils.tests import missing_compiler_executable +from distutils.tests import missing_compiler_executable, get_possible_compiler_types from distutils.tests.support import ( TempdirManager, copy_xxmodule_c, @@ -90,8 +90,11 @@ class TestBuildExt(TempdirManager): def build_ext(self, *args, **kwargs): return build_ext(*args, **kwargs) - def test_build_ext(self): - missing_compiler_executable() + @pytest.mark.parametrize('compiler', get_possible_compiler_types()) + def test_build_ext(self, compiler): + cmd = missing_compiler_executable(compiler_type=compiler) + if cmd is not None: + pytest.skip(f'The {cmd!r} command is not found') copy_xxmodule_c(self.tmp_dir) xx_c = os.path.join(self.tmp_dir, 'xxmodule.c') xx_ext = Extension('xx', [xx_c]) @@ -101,6 +104,7 @@ def test_build_ext(self): fixup_build_ext(cmd) cmd.build_lib = self.tmp_dir cmd.build_temp = self.tmp_dir + cmd.compiler = compiler old_stdout = sys.stdout if not support.verbose: