metadata_editable.py 1.1 KB

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