install_headers.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. """distutils.command.install_headers
  2. Implements the Distutils 'install_headers' command, to install C/C++ header
  3. files to the Python include directory."""
  4. from typing import ClassVar
  5. from ..core import Command
  6. # XXX force is never used
  7. class install_headers(Command):
  8. description = "install C/C++ header files"
  9. user_options: ClassVar[list[tuple[str, str, str]]] = [
  10. ('install-dir=', 'd', "directory to install header files to"),
  11. ('force', 'f', "force installation (overwrite existing files)"),
  12. ]
  13. boolean_options: ClassVar[list[str]] = ['force']
  14. def initialize_options(self):
  15. self.install_dir = None
  16. self.force = False
  17. self.outfiles = []
  18. def finalize_options(self):
  19. self.set_undefined_options(
  20. 'install', ('install_headers', 'install_dir'), ('force', 'force')
  21. )
  22. def run(self):
  23. headers = self.distribution.headers
  24. if not headers:
  25. return
  26. self.mkpath(self.install_dir)
  27. for header in headers:
  28. (out, _) = self.copy_file(header, self.install_dir)
  29. self.outfiles.append(out)
  30. def get_inputs(self):
  31. return self.distribution.headers or []
  32. def get_outputs(self):
  33. return self.outfiles