Skip to content

Commit

Permalink
remove package.package stutter
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby authored and neersighted committed Jul 25, 2022
1 parent a7fef27 commit bf0dbc0
Showing 1 changed file with 53 additions and 41 deletions.
94 changes: 53 additions & 41 deletions src/poetry/puzzle/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,42 +491,47 @@ def incompatibilities_for(
for dep in dependencies
]

def complete_package(self, package: DependencyPackage) -> DependencyPackage:
if package.package.is_root():
package = package.clone()
requires = package.package.all_requires
elif not package.package.is_root() and package.package.source_type not in {
def complete_package(
self, dependency_package: DependencyPackage
) -> DependencyPackage:
package = dependency_package.package
dependency = dependency_package.dependency

if package.is_root():
dependency_package = dependency_package.clone()
package = dependency_package.package
dependency = dependency_package.dependency
requires = package.all_requires
elif package.source_type not in {
"directory",
"file",
"url",
"git",
}:
try:
package = DependencyPackage(
package.dependency,
dependency_package = DependencyPackage(
dependency,
self._pool.package(
package.package.name,
package.package.version.text,
extras=list(package.dependency.extras),
repository=package.dependency.source_name,
package.name,
package.version.text,
extras=list(dependency.extras),
repository=dependency.source_name,
),
)
except PackageNotFound as e:
try:
package = next(
DependencyPackage(
package.dependency,
pkg,
)
for pkg in self.search_for_installed_packages(
package.dependency
)
dependency_package = next(
DependencyPackage(dependency, pkg)
for pkg in self.search_for_installed_packages(dependency)
)
except StopIteration:
raise e from e
requires = package.package.requires

package = dependency_package.package
dependency = dependency_package.dependency
requires = package.requires
else:
requires = package.package.requires
requires = package.requires

if self._load_deferred:
# Retrieving constraints for deferred dependencies
Expand All @@ -540,16 +545,20 @@ def complete_package(self, package: DependencyPackage) -> DependencyPackage:
# If some extras/features were required, we need to
# add a special dependency representing the base package
# to the current package
if package.dependency.extras:
for extra in package.dependency.extras:
if dependency.extras:
for extra in dependency.extras:
extra = safe_extra(extra)
if extra not in package.package.extras:
if extra not in package.extras:
continue

optional_dependencies += [d.name for d in package.package.extras[extra]]
optional_dependencies += [d.name for d in package.extras[extra]]

package = package.with_features(list(package.dependency.extras))
_dependencies.append(package.package.without_features().to_dependency())
dependency_package = dependency_package.with_features(
list(dependency.extras)
)
package = dependency_package.package
dependency = dependency_package.dependency
_dependencies.append(package.without_features().to_dependency())

for dep in requires:
if not self._python_constraint.allows_any(dep.python_constraint):
Expand All @@ -561,20 +570,22 @@ def complete_package(self, package: DependencyPackage) -> DependencyPackage:
if self._env and not dep.marker.validate(self._env.marker_env):
continue

if not package.package.is_root() and (
if not package.is_root() and (
(dep.is_optional() and dep.name not in optional_dependencies)
or (
dep.in_extras
and not set(dep.in_extras).intersection(
{safe_extra(extra) for extra in package.dependency.extras}
{safe_extra(extra) for extra in dependency.extras}
)
)
):
continue

_dependencies.append(dep)

dependencies = self._get_dependencies_with_overrides(_dependencies, package)
dependencies = self._get_dependencies_with_overrides(
_dependencies, dependency_package
)

# Searching for duplicate dependencies
#
Expand Down Expand Up @@ -730,9 +741,11 @@ def fmt_warning(d: Dependency) -> str:
for dep in deps:
if not overrides_marker_intersection.intersect(dep.marker).is_empty():
current_overrides = self._overrides.copy()
package_overrides = current_overrides.get(package, {}).copy()
package_overrides = current_overrides.get(
dependency_package, {}
).copy()
package_overrides.update({dep.name: dep})
current_overrides.update({package: package_overrides})
current_overrides.update({dependency_package: package_overrides})
overrides.append(current_overrides)

if overrides:
Expand All @@ -741,9 +754,9 @@ def fmt_warning(d: Dependency) -> str:
# Modifying dependencies as needed
clean_dependencies = []
for dep in dependencies:
if not package.dependency.transitive_marker.without_extras().is_any():
if not dependency.transitive_marker.without_extras().is_any():
marker_intersection = (
package.dependency.transitive_marker.without_extras().intersect(
dependency.transitive_marker.without_extras().intersect(
dep.marker.without_extras()
)
)
Expand All @@ -755,9 +768,9 @@ def fmt_warning(d: Dependency) -> str:

dep.transitive_marker = marker_intersection

if not package.dependency.python_constraint.is_any():
if not dependency.python_constraint.is_any():
python_constraint_intersection = dep.python_constraint.intersect(
package.dependency.python_constraint
dependency.python_constraint
)
if python_constraint_intersection.is_empty():
# This dependency is not needed under current python constraint.
Expand All @@ -766,14 +779,13 @@ def fmt_warning(d: Dependency) -> str:

clean_dependencies.append(dep)

package = DependencyPackage(
package.dependency, package.package.with_dependency_groups([], only=True)
)
package = package.with_dependency_groups([], only=True)
dependency_package = DependencyPackage(dependency, package)

for dep in clean_dependencies:
package.package.add_dependency(dep)
package.add_dependency(dep)

return package
return dependency_package

def debug(self, message: str, depth: int = 0) -> None:
if not (self._io.is_very_verbose() or self._io.is_debug()):
Expand Down

0 comments on commit bf0dbc0

Please sign in to comment.