wheel.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import logging
  2. import os
  3. from pip._internal.utils.subprocess import runner_with_spinner_message
  4. from pip._internal.utils.typing import MYPY_CHECK_RUNNING
  5. if MYPY_CHECK_RUNNING:
  6. from typing import List, Optional
  7. from pip._vendor.pep517.wrappers import Pep517HookCaller
  8. logger = logging.getLogger(__name__)
  9. def build_wheel_pep517(
  10. name, # type: str
  11. backend, # type: Pep517HookCaller
  12. metadata_directory, # type: str
  13. build_options, # type: List[str]
  14. tempd, # type: str
  15. ):
  16. # type: (...) -> Optional[str]
  17. """Build one InstallRequirement using the PEP 517 build process.
  18. Returns path to wheel if successfully built. Otherwise, returns None.
  19. """
  20. assert metadata_directory is not None
  21. if build_options:
  22. # PEP 517 does not support --build-options
  23. logger.error('Cannot build wheel for %s using PEP 517 when '
  24. '--build-option is present' % (name,))
  25. return None
  26. try:
  27. logger.debug('Destination directory: %s', tempd)
  28. runner = runner_with_spinner_message(
  29. 'Building wheel for {} (PEP 517)'.format(name)
  30. )
  31. with backend.subprocess_runner(runner):
  32. wheel_name = backend.build_wheel(
  33. tempd,
  34. metadata_directory=metadata_directory,
  35. )
  36. except Exception:
  37. logger.error('Failed building wheel for %s', name)
  38. return None
  39. return os.path.join(tempd, wheel_name)