| 29 | |
| 30 | @attr.s |
| 31 | class DependencyManager(object): |
| 32 | _requirements = attr.ib(factory=OrderedSet) # type: OrderedSet[Requirement] |
| 33 | _distributions = attr.ib(factory=OrderedSet) # type: OrderedSet[FingerprintedDistribution] |
| 34 | |
| 35 | def add_requirement(self, requirement): |
| 36 | # type: (Requirement) -> None |
| 37 | self._requirements.add(requirement) |
| 38 | |
| 39 | def add_distribution(self, fingerprinted_distribution): |
| 40 | # type: (FingerprintedDistribution) -> None |
| 41 | self._distributions.add(fingerprinted_distribution) |
| 42 | |
| 43 | def add_from_pex( |
| 44 | self, |
| 45 | pex, # type: str |
| 46 | result_type_wheel_file=False, # type: bool |
| 47 | ): |
| 48 | # type: (...) -> PexInfo |
| 49 | |
| 50 | pex_info = PexInfo.from_pex(pex) |
| 51 | for req in pex_info.requirements: |
| 52 | self.add_requirement(Requirement.parse(req)) |
| 53 | |
| 54 | pex_environment = PEXEnvironment.mount(pex, pex_info=pex_info) |
| 55 | for dist in pex_environment.iter_distributions( |
| 56 | result_type_wheel_file=result_type_wheel_file |
| 57 | ): |
| 58 | self.add_distribution(dist) |
| 59 | |
| 60 | return pex_info |
| 61 | |
| 62 | def add_from_resolved(self, resolved): |
| 63 | # type: (ResolveResult) -> None |
| 64 | |
| 65 | for resolved_dist in resolved.distributions: |
| 66 | for req in resolved_dist.direct_requirements: |
| 67 | self.add_requirement(req) |
| 68 | self.add_distribution(resolved_dist.fingerprinted_distribution) |
| 69 | |
| 70 | def configure( |
| 71 | self, |
| 72 | pex_builder, # type: PEXBuilder |
| 73 | dependency_configuration=DependencyConfiguration(), # type: DependencyConfiguration |
| 74 | ): |
| 75 | # type: (...) -> None |
| 76 | |
| 77 | dependency_configuration.configure(pex_builder.info) |
| 78 | |
| 79 | root_requirements_by_project_name = defaultdict( |
| 80 | OrderedSet |
| 81 | ) # type: DefaultDict[ProjectName, OrderedSet[Requirement]] |
| 82 | for root_req in self._requirements: |
| 83 | root_requirements_by_project_name[root_req.project_name].add(root_req) |
| 84 | |
| 85 | for fingerprinted_dist in self._distributions: |
| 86 | excluded_by = dependency_configuration.excluded_by(fingerprinted_dist.distribution) |
| 87 | if excluded_by: |
| 88 | excludes = " and ".join(map(str, excluded_by)) |
no outgoing calls