Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lazka committed Jul 21, 2024
1 parent e1e9f61 commit fa7e35b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 19 additions & 3 deletions distutils/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
10 changes: 7 additions & 3 deletions distutils/tests/test_build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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])
Expand All @@ -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:
Expand Down

0 comments on commit fa7e35b

Please sign in to comment.