metadata.py 1.1 KB

123456789101112131415161718192021222324252627282930
  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_metadata(build_env: BuildEnvironment, backend: Pep517HookCaller) -> str:
  9. """Generate metadata using mechanisms described in PEP 517.
  10. Returns the generated metadata directory.
  11. """
  12. metadata_tmpdir = TempDirectory(kind="modern-metadata", globally_managed=True)
  13. metadata_dir = metadata_tmpdir.path
  14. with build_env:
  15. # Note that Pep517HookCaller implements a fallback for
  16. # prepare_metadata_for_build_wheel, so we don't have to
  17. # consider the possibility that this hook doesn't exist.
  18. runner = runner_with_spinner_message("Preparing metadata (pyproject.toml)")
  19. with backend.subprocess_runner(runner):
  20. distinfo_dir = backend.prepare_metadata_for_build_wheel(metadata_dir)
  21. return os.path.join(metadata_dir, distinfo_dir)