diff --git a/src/pybuild_deps/compile_build_dependencies.py b/src/pybuild_deps/compile_build_dependencies.py index f835c03..4c7cffa 100644 --- a/src/pybuild_deps/compile_build_dependencies.py +++ b/src/pybuild_deps/compile_build_dependencies.py @@ -51,14 +51,14 @@ def resolve( log.info("=" * 80) log.info(str(ireq)) log.info("-" * 80) - ireq_key = key_from_ireq(ireq) - if ireq_key in dependency_cache: - all_build_deps.extend(dependency_cache[ireq_key]) + req_str = str(ireq.req) + if req_str in dependency_cache: + all_build_deps.extend(dependency_cache[req_str]) log.debug(f"{ireq.req} was already solved, moving on...") continue build_ireqs = set(self._find_build_dependencies(ireq)) if not build_ireqs: - dependency_cache[ireq_key] = set() + dependency_cache[req_str] = set() continue try: # Attempt to resolve ireq's transitive dependencies using @@ -66,7 +66,7 @@ def resolve( # "constraint" that can be used with pip, like when running # "pip install -c constraints.txt some-package" build_dependencies = self._resolve_with_piptools( - package=ireq_key, + package=req_str, ireqs=build_ireqs, constraints=existing_constraints, ) @@ -80,7 +80,7 @@ def resolve( # If this step fails, the same exception will bubble up and explode # in an error. build_dependencies = self._resolve_with_piptools( - package=ireq_key, + package=req_str, ireqs=build_ireqs, ) @@ -94,8 +94,11 @@ def resolve( existing_constraints=existing_constraints, dependency_cache=dependency_cache, ) + build_dependencies = deduplicate_install_requirements( + build_dependencies + ) - dependency_cache[ireq_key] = build_dependencies + dependency_cache[req_str] = build_dependencies all_build_deps.extend(build_dependencies) @@ -105,7 +108,7 @@ def _resolve_with_piptools( self, package: str, ireqs: Iterable[InstallRequirement], - constraints: set[InstallRequirement], + constraints: dict[InstallRequirement] | None = None, ) -> set[InstallRequirement]: # backup unsafe data before overriding resolver, we will need it later # on piptools writer to export the file @@ -114,7 +117,7 @@ def _resolve_with_piptools( # override resolver - we don't want references from other self.resolver = BacktrackingResolver( constraints=ireqs, - existing_constraints=constraints, + existing_constraints=constraints or {}, repository=self.repository, allow_unsafe=True, ) @@ -148,15 +151,15 @@ def deduplicate_install_requirements(ireqs: Iterable[InstallRequirement]): """Deduplicate InstallRequirements.""" unique_ireqs = {} for ireq in ireqs: - ireq_key = key_from_ireq(ireq) - if ireq_key not in unique_ireqs: + req_tuple = ireq.name, get_version(ireq) + if req_tuple not in unique_ireqs: # NOTE: piptools hacks pip's InstallRequirement to allow support from # multiple sources. Let's use the same attr so piptools file writer can # use this information. # https://github.com/jazzband/pip-tools/blob/53309647980e2a4981db54c0033f98c61142de0b/piptools/resolver.py#L118-L122 # https://github.com/jazzband/pip-tools/blob/53309647980e2a4981db54c0033f98c61142de0b/piptools/writer.py#L309-L314 ireq._source_ireqs = getattr(ireq, "_source_ireqs", [ireq]) - unique_ireqs[ireq_key] = ireq + unique_ireqs[req_tuple] = ireq else: - unique_ireqs[ireq_key]._source_ireqs.append(ireq) + unique_ireqs[req_tuple]._source_ireqs.append(ireq) return set(unique_ireqs.values())