wheel_editable.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import logging
  2. import os
  3. from typing import Optional
  4. from pip._vendor.pep517.wrappers import HookMissing, Pep517HookCaller
  5. from pip._internal.utils.subprocess import runner_with_spinner_message
  6. logger = logging.getLogger(__name__)
  7. def build_wheel_editable(
  8. name: str,
  9. backend: Pep517HookCaller,
  10. metadata_directory: str,
  11. tempd: str,
  12. ) -> Optional[str]:
  13. """Build one InstallRequirement using the PEP 660 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 editable for {name} (pyproject.toml)"
  21. )
  22. with backend.subprocess_runner(runner):
  23. try:
  24. wheel_name = backend.build_editable(
  25. tempd,
  26. metadata_directory=metadata_directory,
  27. )
  28. except HookMissing as e:
  29. logger.error(
  30. "Cannot build editable %s because the build "
  31. "backend does not have the %s hook",
  32. name,
  33. e,
  34. )
  35. return None
  36. except Exception:
  37. logger.error("Failed building editable for %s", name)
  38. return None
  39. return os.path.join(tempd, wheel_name)