Skip to content

Commit

Permalink
provider: fetch optional vcs dependency only if required
Browse files Browse the repository at this point in the history
Co-authored-by: Maxim Koltsov <kolmax94@gmail.com>
  • Loading branch information
2 people authored and neersighted committed Sep 24, 2022
1 parent c061ac5 commit 8f175f2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/poetry/puzzle/provider.py
Expand Up @@ -572,18 +572,6 @@ def complete_package(
dependency = dependency_package.dependency
requires = package.requires

if self._load_deferred:
# Retrieving constraints for deferred dependencies
for r in requires:
if r.is_direct_origin():
locked = self.get_locked(r)
# If lock file contains exactly the same URL and reference
# (commit hash) of dependency as is requested,
# do not analyze it again: nothing could have changed.
if locked is not None and locked.package.is_same_package_as(r):
continue
self.search_for_direct_origin_dependency(r)

optional_dependencies = []
_dependencies = []

Expand Down Expand Up @@ -636,6 +624,18 @@ def complete_package(

_dependencies.append(dep)

if self._load_deferred:
# Retrieving constraints for deferred dependencies
for dep in _dependencies:
if dep.is_direct_origin():
locked = self.get_locked(dep)
# If lock file contains exactly the same URL and reference
# (commit hash) of dependency as is requested,
# do not analyze it again: nothing could have changed.
if locked is not None and locked.package.is_same_package_as(dep):
continue
self.search_for_direct_origin_dependency(dep)

dependencies = self._get_dependencies_with_overrides(
_dependencies, dependency_package
)
Expand Down
22 changes: 22 additions & 0 deletions tests/puzzle/test_provider.py
Expand Up @@ -716,3 +716,25 @@ def test_complete_package_with_extras_preserves_source_name(
assert requires[0].source_name == source_name
assert requires[1].name == "b"
assert requires[1].source_name is None


@pytest.mark.parametrize("with_extra", [False, True])
def test_complete_package_fetches_optional_vcs_dependency_only_if_requested(
provider: Provider, repository: Repository, mocker: MockerFixture, with_extra: bool
):
optional_vcs_dependency = Factory.create_dependency(
"demo", {"git": "https://github.com/demo/demo.git", "optional": True}
)
package = Package("A", "1.0", features=["foo"] if with_extra else [])
package.add_dependency(optional_vcs_dependency)
package.extras["foo"] = [optional_vcs_dependency]
repository.add_package(package)

spy = mocker.spy(provider, "_search_for_vcs")

provider.complete_package(DependencyPackage(package.to_dependency(), package))

if with_extra:
spy.assert_called()
else:
spy.assert_not_called()

0 comments on commit 8f175f2

Please sign in to comment.