metadata.py 1.1 KB

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