Skip to content

Commit 52dad74

Browse files
committed
Rename classes and add compatibility shims.
1 parent 42b1c4c commit 52dad74

File tree

11 files changed

+115
-52
lines changed

11 files changed

+115
-52
lines changed

distutils/_msvccompiler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .compilers.C import msvc
2+
3+
MSVCCompiler = msvc.Compiler

distutils/ccompiler.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from .compilers.C import base
2+
from .compilers.C.base import (
3+
CompileError,
4+
gen_lib_options,
5+
gen_preprocess_options,
6+
get_default_compiler,
7+
new_compiler,
8+
show_compilers,
9+
)
10+
11+
__all__ = [
12+
'CompileError',
13+
'gen_lib_options',
14+
'gen_preprocess_options',
15+
'get_default_compiler',
16+
'new_compiler',
17+
'show_compilers',
18+
]
19+
20+
21+
CCompiler = base.Compiler

distutils/compilers/C/base.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""distutils.ccompiler
22
3-
Contains CCompiler, an abstract base class that defines the interface
3+
Contains Compiler, an abstract base class that defines the interface
44
for the Distutils compiler abstraction model."""
55

66
import os
@@ -12,22 +12,22 @@
1212

1313
from more_itertools import always_iterable
1414

15-
from ._log import log
16-
from ._modified import newer_group
17-
from .dir_util import mkpath
18-
from .errors import (
15+
from ..._log import log
16+
from ..._modified import newer_group
17+
from ...dir_util import mkpath
18+
from ...errors import (
1919
CompileError,
2020
DistutilsModuleError,
2121
DistutilsPlatformError,
2222
LinkError,
2323
UnknownFileError,
2424
)
25-
from .file_util import move_file
26-
from .spawn import spawn
27-
from .util import execute, is_mingw, split_quoted
25+
from ...file_util import move_file
26+
from ...spawn import spawn
27+
from ...util import execute, is_mingw, split_quoted
2828

2929

30-
class CCompiler:
30+
class Compiler:
3131
"""Abstract base class to define the interface that must be implemented
3232
by real compiler classes. Also has some utility methods used by
3333
several compiler classes.
@@ -726,7 +726,7 @@ def link_shared_lib(
726726
target_lang=None,
727727
):
728728
self.link(
729-
CCompiler.SHARED_LIBRARY,
729+
Compiler.SHARED_LIBRARY,
730730
objects,
731731
self.library_filename(output_libname, lib_type='shared'),
732732
output_dir,
@@ -757,7 +757,7 @@ def link_shared_object(
757757
target_lang=None,
758758
):
759759
self.link(
760-
CCompiler.SHARED_OBJECT,
760+
Compiler.SHARED_OBJECT,
761761
objects,
762762
output_filename,
763763
output_dir,
@@ -786,7 +786,7 @@ def link_executable(
786786
target_lang=None,
787787
):
788788
self.link(
789-
CCompiler.EXECUTABLE,
789+
Compiler.EXECUTABLE,
790790
objects,
791791
self.executable_filename(output_progname),
792792
output_dir,
@@ -978,9 +978,9 @@ def _make_out_path(self, output_dir, strip_dir, src_name):
978978
def _make_out_path_exts(cls, output_dir, strip_dir, src_name, extensions):
979979
r"""
980980
>>> exts = {'.c': '.o'}
981-
>>> CCompiler._make_out_path_exts('.', False, '/foo/bar.c', exts).replace('\\', '/')
981+
>>> Compiler._make_out_path_exts('.', False, '/foo/bar.c', exts).replace('\\', '/')
982982
'./foo/bar.o'
983-
>>> CCompiler._make_out_path_exts('.', True, '/foo/bar.c', exts).replace('\\', '/')
983+
>>> Compiler._make_out_path_exts('.', True, '/foo/bar.c', exts).replace('\\', '/')
984984
'./bar.o'
985985
"""
986986
src = pathlib.PurePath(src_name)

distutils/compilers/C/cygwin.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
import warnings
1515
from subprocess import check_output
1616

17-
from .errors import (
17+
from ...errors import (
1818
CCompilerError,
1919
CompileError,
2020
DistutilsExecError,
2121
DistutilsPlatformError,
2222
)
23-
from .file_util import write_file
24-
from .sysconfig import get_config_vars
25-
from .unixccompiler import UnixCCompiler
26-
from .version import LooseVersion, suppress_known_deprecation
23+
from ...file_util import write_file
24+
from ...sysconfig import get_config_vars
25+
from ...version import LooseVersion, suppress_known_deprecation
26+
from . import unix
2727

2828

2929
def get_msvcr():
@@ -37,7 +37,7 @@ def get_msvcr():
3737
)
3838

3939

40-
class CygwinCCompiler(UnixCCompiler):
40+
class Compiler(unix.Compiler):
4141
"""Handles the Cygwin port of the GNU C compiler to Windows."""
4242

4343
compiler_type = 'cygwin'
@@ -197,8 +197,7 @@ def link(
197197
if not debug:
198198
extra_preargs.append("-s")
199199

200-
UnixCCompiler.link(
201-
self,
200+
super().link(
202201
target_desc,
203202
objects,
204203
output_filename,
@@ -240,7 +239,7 @@ def out_extensions(self):
240239

241240

242241
# the same as cygwin plus some additional parameters
243-
class Mingw32CCompiler(CygwinCCompiler):
242+
class MinGW32Compiler(Compiler):
244243
"""Handles the Mingw32 port of the GNU C compiler to Windows."""
245244

246245
compiler_type = 'mingw32'

distutils/compilers/C/msvc.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@
2323

2424
from itertools import count
2525

26-
from ._log import log
27-
from .ccompiler import CCompiler, gen_lib_options
28-
from .errors import (
26+
from ..._log import log
27+
from ...errors import (
2928
CompileError,
3029
DistutilsExecError,
3130
DistutilsPlatformError,
3231
LibError,
3332
LinkError,
3433
)
35-
from .util import get_host_platform, get_platform
34+
from ...util import get_host_platform, get_platform
35+
from . import base
36+
from .base import gen_lib_options
3637

3738

3839
def _find_vc2015():
@@ -226,7 +227,7 @@ def _get_vcvars_spec(host_platform, platform):
226227
return vc_hp if vc_hp == vc_plat else f'{vc_hp}_{vc_plat}'
227228

228229

229-
class MSVCCompiler(CCompiler):
230+
class Compiler(base.Compiler):
230231
"""Concrete class that implements an interface to Microsoft Visual C++,
231232
as defined by the CCompiler abstract class."""
232233

@@ -339,15 +340,15 @@ def initialize(self, plat_name=None):
339340
self.ldflags_static_debug = [*ldflags_debug]
340341

341342
self._ldflags = {
342-
(CCompiler.EXECUTABLE, None): self.ldflags_exe,
343-
(CCompiler.EXECUTABLE, False): self.ldflags_exe,
344-
(CCompiler.EXECUTABLE, True): self.ldflags_exe_debug,
345-
(CCompiler.SHARED_OBJECT, None): self.ldflags_shared,
346-
(CCompiler.SHARED_OBJECT, False): self.ldflags_shared,
347-
(CCompiler.SHARED_OBJECT, True): self.ldflags_shared_debug,
348-
(CCompiler.SHARED_LIBRARY, None): self.ldflags_static,
349-
(CCompiler.SHARED_LIBRARY, False): self.ldflags_static,
350-
(CCompiler.SHARED_LIBRARY, True): self.ldflags_static_debug,
343+
(base.Compiler.EXECUTABLE, None): self.ldflags_exe,
344+
(base.Compiler.EXECUTABLE, False): self.ldflags_exe,
345+
(base.Compiler.EXECUTABLE, True): self.ldflags_exe_debug,
346+
(base.Compiler.SHARED_OBJECT, None): self.ldflags_shared,
347+
(base.Compiler.SHARED_OBJECT, False): self.ldflags_shared,
348+
(base.Compiler.SHARED_OBJECT, True): self.ldflags_shared_debug,
349+
(base.Compiler.SHARED_LIBRARY, None): self.ldflags_static,
350+
(base.Compiler.SHARED_LIBRARY, False): self.ldflags_static,
351+
(base.Compiler.SHARED_LIBRARY, True): self.ldflags_static_debug,
351352
}
352353

353354
self.initialized = True

distutils/compilers/C/unix.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
import shlex
2222
import sys
2323

24-
from . import sysconfig
25-
from ._log import log
26-
from ._macos_compat import compiler_fixup
27-
from ._modified import newer
28-
from .ccompiler import CCompiler, gen_lib_options, gen_preprocess_options
29-
from .compat import consolidate_linker_args
30-
from .errors import CompileError, DistutilsExecError, LibError, LinkError
24+
from ... import sysconfig
25+
from ..._log import log
26+
from ..._macos_compat import compiler_fixup
27+
from ..._modified import newer
28+
from ...compat import consolidate_linker_args
29+
from ...errors import CompileError, DistutilsExecError, LibError, LinkError
30+
from . import base
31+
from .base import gen_lib_options, gen_preprocess_options
3132

3233
# XXX Things not currently handled:
3334
# * optimization/debug/warning flags; we just use whatever's in Python's
@@ -105,7 +106,7 @@ def _linker_params(linker_cmd, compiler_cmd):
105106
return linker_cmd[pivot:]
106107

107108

108-
class UnixCCompiler(CCompiler):
109+
class Compiler(base.Compiler):
109110
compiler_type = 'unix'
110111

111112
# These are used by CCompiler in two places: the constructor sets
@@ -264,7 +265,7 @@ def link(
264265
# Select a linker based on context: linker_exe when
265266
# building an executable or linker_so (with shared options)
266267
# when building a shared library.
267-
building_exe = target_desc == CCompiler.EXECUTABLE
268+
building_exe = target_desc == base.Compiler.EXECUTABLE
268269
linker = (
269270
self.linker_exe
270271
if building_exe

distutils/compilers/C/zos.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
import os
1515

16-
from . import sysconfig
17-
from .errors import CompileError, DistutilsExecError
18-
from .unixccompiler import UnixCCompiler
16+
from ... import sysconfig
17+
from ...errors import CompileError, DistutilsExecError
18+
from . import unix
1919

2020
_cc_args = {
2121
'ibm-openxl': [
@@ -101,7 +101,7 @@
101101
# Python on z/OS is built with no compiler specific options in it's CFLAGS.
102102
# But each compiler requires it's own specific options to build successfully,
103103
# though some of the options are common between them
104-
class zOSCCompiler(UnixCCompiler):
104+
class Compiler(unix.Compiler):
105105
src_extensions = ['.c', '.C', '.cc', '.cxx', '.cpp', '.m', '.s']
106106
_cpp_extensions = ['.cc', '.cpp', '.cxx', '.C']
107107
_asm_extensions = ['.s']

distutils/cygwinccompiler.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from .compilers.C import cygwin
2+
from .compilers.C.cygwin import (
3+
CONFIG_H_NOTOK,
4+
CONFIG_H_OK,
5+
CONFIG_H_UNCERTAIN,
6+
check_config_h,
7+
get_msvcr,
8+
is_cygwincc,
9+
)
10+
11+
__all__ = [
12+
'CONFIG_H_NOTOK',
13+
'CONFIG_H_OK',
14+
'CONFIG_H_UNCERTAIN',
15+
'CygwinCCompiler',
16+
'Mingw32CCompiler',
17+
'check_config_h',
18+
'get_msvcr',
19+
'is_cygwincc',
20+
]
21+
22+
23+
CygwinCCompiler = cygwin.Compiler
24+
Mingw32CCompiler = cygwin.MinGW32Compiler
25+
26+
27+
get_versions = None
28+
"""
29+
A stand-in for the previous get_versions() function to prevent failures
30+
when monkeypatched. See pypa/setuptools#2969.
31+
"""

distutils/tests/test_msvccompiler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import threading
77
import unittest.mock as mock
88
from distutils import _msvccompiler
9+
from distutils.compilers.C import msvc
910
from distutils.errors import DistutilsPlatformError
1011
from distutils.tests import support
1112
from distutils.util import get_platform
@@ -23,10 +24,10 @@ def test_no_compiler(self, monkeypatch):
2324
def _find_vcvarsall(plat_spec):
2425
return None, None
2526

26-
monkeypatch.setattr(_msvccompiler, '_find_vcvarsall', _find_vcvarsall)
27+
monkeypatch.setattr(msvc, '_find_vcvarsall', _find_vcvarsall)
2728

2829
with pytest.raises(DistutilsPlatformError):
29-
_msvccompiler._get_vc_env(
30+
msvc._get_vc_env(
3031
'wont find this version',
3132
)
3233

distutils/unixccompiler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .compilers.C import unix
2+
3+
UnixCCompiler = unix.Compiler

0 commit comments

Comments
 (0)