metadata.py 1.2 KB

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