wheel.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import logging
  2. import os
  3. from typing import Optional
  4. from pip._vendor.pyproject_hooks import BuildBackendHookCaller
  5. from pip._internal.utils.subprocess import runner_with_spinner_message
  6. logger = logging.getLogger(__name__)
  7. def build_wheel_pep517(
  8. name: str,
  9. backend: BuildBackendHookCaller,
  10. metadata_directory: str,
  11. tempd: str,
  12. ) -> Optional[str]:
  13. """Build one InstallRequirement using the PEP 517 build process.
  14. Returns path to wheel if successfully built. Otherwise, returns None.
  15. """
  16. assert metadata_directory is not None
  17. try:
  18. logger.debug("Destination directory: %s", tempd)
  19. runner = runner_with_spinner_message(
  20. f"Building wheel for {name} (pyproject.toml)"
  21. )
  22. with backend.subprocess_runner(runner):
  23. wheel_name = backend.build_wheel(
  24. tempd,
  25. metadata_directory=metadata_directory,
  26. )
  27. except Exception:
  28. logger.error("Failed building wheel for %s", name)
  29. return None
  30. return os.path.join(tempd, wheel_name)