Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use hash of dependency instead of object in a provider's deferred cache #5903

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/poetry/puzzle/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def __init__(
self._is_debugging: bool = self._io.is_debug() or self._io.is_very_verbose()
self._in_progress = False
self._overrides: dict[DependencyPackage, dict[str, Dependency]] = {}
self._deferred_cache: dict[Dependency, Package] = {}
self._deferred_cache: dict[int, Package] = {}
self._load_deferred = True
self._source_root: Path | None = None
self._installed = installed
Expand Down Expand Up @@ -288,7 +288,7 @@ def search_for_vcs(self, dependency: VCSDependency) -> list[Package]:
dependency._source_resolved_reference = package.source_resolved_reference
dependency._source_subdirectory = package.source_subdirectory

self._deferred_cache[dependency] = package
self._deferred_cache[hash(dependency)] = package

return [package]

Expand All @@ -315,8 +315,8 @@ def get_package_from_vcs(
)

def search_for_file(self, dependency: FileDependency) -> list[Package]:
if dependency in self._deferred_cache:
_package = self._deferred_cache[dependency]
if hash(dependency) in self._deferred_cache:
_package = self._deferred_cache[hash(dependency)]

package = _package.clone()
else:
Expand All @@ -325,7 +325,7 @@ def search_for_file(self, dependency: FileDependency) -> list[Package]:
dependency._constraint = package.version
dependency._pretty_constraint = package.version.text

self._deferred_cache[dependency] = package
self._deferred_cache[hash(dependency)] = package

self.validate_package_for_dependency(dependency=dependency, package=package)

Expand All @@ -352,8 +352,8 @@ def get_package_from_file(cls, file_path: Path) -> Package:
return package

def search_for_directory(self, dependency: DirectoryDependency) -> list[Package]:
if dependency in self._deferred_cache:
_package = self._deferred_cache[dependency]
if hash(dependency) in self._deferred_cache:
_package = self._deferred_cache[hash(dependency)]

package = _package.clone()
else:
Expand All @@ -362,7 +362,7 @@ def search_for_directory(self, dependency: DirectoryDependency) -> list[Package]
dependency._constraint = package.version
dependency._pretty_constraint = package.version.text

self._deferred_cache[dependency] = package
self._deferred_cache[hash(dependency)] = package

self.validate_package_for_dependency(dependency=dependency, package=package)

Expand All @@ -378,8 +378,8 @@ def get_package_from_directory(cls, directory: Path) -> Package:
return PackageInfo.from_directory(path=directory).to_package(root_dir=directory)

def search_for_url(self, dependency: URLDependency) -> list[Package]:
if dependency in self._deferred_cache:
return [self._deferred_cache[dependency]]
if hash(dependency) in self._deferred_cache:
return [self._deferred_cache[hash(dependency)]]

package = self.get_package_from_url(dependency.url)

Expand All @@ -396,7 +396,7 @@ def search_for_url(self, dependency: URLDependency) -> list[Package]:
dependency._constraint = package.version
dependency._pretty_constraint = package.version.text

self._deferred_cache[dependency] = package
self._deferred_cache[hash(dependency)] = package

return [package]

Expand Down