MCPcopy
hub / github.com/pex-tool/pex / prepare

Method prepare

pex/resolver.py:684–727  ·  view source on GitHub ↗
(self, ensure_extracted=False)

Source from the content-addressed store, hash-verified

682 return self.download_target.target
683
684 def prepare(self, ensure_extracted=False):
685 # type: (bool) -> Tuple[str, bool]
686
687 if not ensure_extracted and not self.subdirectory:
688 return self.source_path, self.editable
689
690 if os.path.isdir(self.source_path):
691 project = self.source_path
692 if self.subdirectory:
693 project = os.path.join(project, self.subdirectory)
694 return project, self.editable
695
696 # We use `pip wheel ...` to build sdsists but there is no way to pass a subdirectory to
697 # that; so we hand-prepare a loose source subdirectory here that `pip wheel` can handle.
698 extracted_sdist = CacheDir.EXTRACTED_SDISTS.path(
699 self.fingerprint or _fingerprint_file(self.source_path)
700 )
701 with atomic_directory(extracted_sdist) as atomic_dir:
702 if not atomic_dir.is_finalized():
703 if is_zip_sdist(self.source_path):
704 with open_zip(self.source_path) as zf:
705 zf.extractall(atomic_dir.work_dir)
706 elif is_tar_sdist(self.source_path):
707 sdist.extract_tarball(self.source_path, dest_dir=atomic_dir.work_dir)
708 else:
709 raise BuildError(
710 "Unexpected archive type for sdist {project}".format(
711 project=self.source_path
712 )
713 )
714 listing = os.listdir(atomic_dir.work_dir)
715 if len(listing) != 1:
716 raise BuildError(
717 "Expected one top-level project directory to be extracted from {project}, "
718 "found {count}: {listing}".format(
719 project=self.source_path, count=len(listing), listing=", ".join(listing)
720 )
721 )
722
723 listing = os.listdir(extracted_sdist)
724 project = os.path.join(extracted_sdist, listing[0])
725 if self.subdirectory:
726 project = os.path.join(project, self.subdirectory)
727 return project, False
728
729 def result(
730 self,

Callers 4

_spawn_wheel_buildMethod · 0.80
test_gitFunction · 0.80
test_git_prep_commandFunction · 0.80

Calls 10

atomic_directoryFunction · 0.90
is_zip_sdistFunction · 0.90
open_zipFunction · 0.90
is_tar_sdistFunction · 0.90
_fingerprint_fileFunction · 0.85
is_finalizedMethod · 0.80
extractallMethod · 0.80
BuildErrorClass · 0.70
joinMethod · 0.45
pathMethod · 0.45

Tested by 2

test_gitFunction · 0.64
test_git_prep_commandFunction · 0.64