metadata_editable.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """Metadata generation logic for source distributions.
  2. """
  3. import os
  4. from pip._vendor.pyproject_hooks import BuildBackendHookCaller
  5. from pip._internal.build_env import BuildEnvironment
  6. from pip._internal.exceptions import (
  7. InstallationSubprocessError,
  8. MetadataGenerationFailed,
  9. )
  10. from pip._internal.utils.subprocess import runner_with_spinner_message
  11. from pip._internal.utils.temp_dir import TempDirectory
  12. def generate_editable_metadata(
  13. build_env: BuildEnvironment, backend: BuildBackendHookCaller, details: str
  14. ) -> str:
  15. """Generate metadata using mechanisms described in PEP 660.
  16. Returns the generated metadata directory.
  17. """
  18. metadata_tmpdir = TempDirectory(kind="modern-metadata", globally_managed=True)
  19. metadata_dir = metadata_tmpdir.path
  20. with build_env:
  21. # Note that BuildBackendHookCaller implements a fallback for
  22. # prepare_metadata_for_build_wheel/editable, so we don't have to
  23. # consider the possibility that this hook doesn't exist.
  24. runner = runner_with_spinner_message(
  25. "Preparing editable metadata (pyproject.toml)"
  26. )
  27. with backend.subprocess_runner(runner):
  28. try:
  29. distinfo_dir = backend.prepare_metadata_for_build_editable(metadata_dir)
  30. except InstallationSubprocessError as error:
  31. raise MetadataGenerationFailed(package_details=details) from error
  32. return os.path.join(metadata_dir, distinfo_dir)