metadata.py 1.3 KB

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