codekingpro/portable-devtools
114k
1"""2Test suite for distutils.3 4Tests for the command classes in the distutils.command package are5included in distutils.tests as well, instead of using a separate6distutils.command.tests package, since command identification is done7by import rather than matching pre-defined names.8"""9 10import shutil11from collections.abc import Sequence12 13 14def missing_compiler_executable(cmd_names: Sequence[str] = []): # pragma: no cover15 """Check if the compiler components used to build the interpreter exist.16 17 Check for the existence of the compiler executables whose names are listed18 in 'cmd_names' or all the compiler executables when 'cmd_names' is empty19 and return the first missing executable or None when none is found20 missing.21 22 """23 from distutils import ccompiler, errors, sysconfig24 25 compiler = ccompiler.new_compiler()26 sysconfig.customize_compiler(compiler)27 if compiler.compiler_type == "msvc":28 # MSVC has no executables, so check whether initialization succeeds29 try:30 compiler.initialize()31 except errors.DistutilsPlatformError:32 return "msvc"33 for name in compiler.executables:34 if cmd_names and name not in cmd_names:35 continue36 cmd = getattr(compiler, name)37 if cmd_names:38 assert cmd is not None, f"the '{name}' executable is not configured"39 elif not cmd:40 continue41 if shutil.which(cmd[0]) is None:42 return cmd[0]43 