__init__.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """
  2. Test suite for distutils.
  3. Tests for the command classes in the distutils.command package are
  4. included in distutils.tests as well, instead of using a separate
  5. distutils.command.tests package, since command identification is done
  6. by import rather than matching pre-defined names.
  7. """
  8. import shutil
  9. from collections.abc import Sequence
  10. def missing_compiler_executable(cmd_names: Sequence[str] = []): # pragma: no cover
  11. """Check if the compiler components used to build the interpreter exist.
  12. Check for the existence of the compiler executables whose names are listed
  13. in 'cmd_names' or all the compiler executables when 'cmd_names' is empty
  14. and return the first missing executable or None when none is found
  15. missing.
  16. """
  17. from distutils import ccompiler, errors, sysconfig
  18. compiler = ccompiler.new_compiler()
  19. sysconfig.customize_compiler(compiler)
  20. if compiler.compiler_type == "msvc":
  21. # MSVC has no executables, so check whether initialization succeeds
  22. try:
  23. compiler.initialize()
  24. except errors.DistutilsPlatformError:
  25. return "msvc"
  26. for name in compiler.executables:
  27. if cmd_names and name not in cmd_names:
  28. continue
  29. cmd = getattr(compiler, name)
  30. if cmd_names:
  31. assert cmd is not None, f"the '{name}' executable is not configured"
  32. elif not cmd:
  33. continue
  34. if shutil.which(cmd[0]) is None:
  35. return cmd[0]