File indexing completed on 2024-11-24 05:05:58

0001 import logging
0002 import os
0003 from typing import Optional
0004 
0005 from pip._vendor.pep517.wrappers import HookMissing, Pep517HookCaller
0006 
0007 from pip._internal.utils.subprocess import runner_with_spinner_message
0008 
0009 logger = logging.getLogger(__name__)
0010 
0011 
0012 def build_wheel_editable(
0013     name: str,
0014     backend: Pep517HookCaller,
0015     metadata_directory: str,
0016     tempd: str,
0017 ) -> Optional[str]:
0018     """Build one InstallRequirement using the PEP 660 build process.
0019 
0020     Returns path to wheel if successfully built. Otherwise, returns None.
0021     """
0022     assert metadata_directory is not None
0023     try:
0024         logger.debug("Destination directory: %s", tempd)
0025 
0026         runner = runner_with_spinner_message(
0027             f"Building editable for {name} (pyproject.toml)"
0028         )
0029         with backend.subprocess_runner(runner):
0030             try:
0031                 wheel_name = backend.build_editable(
0032                     tempd,
0033                     metadata_directory=metadata_directory,
0034                 )
0035             except HookMissing as e:
0036                 logger.error(
0037                     "Cannot build editable %s because the build "
0038                     "backend does not have the %s hook",
0039                     name,
0040                     e,
0041                 )
0042                 return None
0043     except Exception:
0044         logger.error("Failed building editable for %s", name)
0045         return None
0046     return os.path.join(tempd, wheel_name)