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

provider: fetch optional vcs dependency only if required #6615

Merged
merged 1 commit into from Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()