Skip to content

Commit

Permalink
Preserve package's source when it has extras
Browse files Browse the repository at this point in the history
  • Loading branch information
maksbotan committed Sep 10, 2022
1 parent 338e02a commit 6e2e645
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/poetry/puzzle/provider.py
Expand Up @@ -603,7 +603,15 @@ def complete_package(
)
package = dependency_package.package
dependency = dependency_package.dependency
_dependencies.append(package.without_features().to_dependency())
new_dependency = package.without_features().to_dependency()

# When adding dependency foo[extra] -> foo, preserve foo's source, if it's
# specified. This prevents us from trying to get foo from PyPI
# when user explicitly set repo for foo[extra].
if not new_dependency.source_name and dependency.source_name:
new_dependency.source_name = dependency.source_name

_dependencies.append(new_dependency)

for dep in requires:
if not self._python_constraint.allows_any(dep.python_constraint):
Expand Down
28 changes: 28 additions & 0 deletions tests/puzzle/test_provider.py
Expand Up @@ -688,3 +688,31 @@ def test_complete_package_preserves_source_type_with_subdirectories(
dependency_one_copy.to_pep_508(),
dependency_two.to_pep_508(),
}


@pytest.mark.parametrize("source_name", [None, "repo"])
def test_complete_package_with_extras_preserves_source_name(
provider: Provider, repository: Repository, source_name: str | None
) -> None:
package_a = Package("A", "1.0")
package_b = Package("B", "1.0")
dep = get_dependency("B", "^1.0", optional=True)
package_a.add_dependency(dep)
package_a.extras = {"foo": [dep]}
repository.add_package(package_a)
repository.add_package(package_b)

dependency = Dependency("A", "1.0", extras=["foo"])
if source_name:
dependency.source_name = source_name

complete_package = provider.complete_package(
DependencyPackage(dependency, package_a)
)

requires = complete_package.package.all_requires
assert len(requires) == 2
assert requires[0].name == "a"
assert requires[0].source_name == source_name
assert requires[1].name == "b"
assert requires[1].source_name is None

0 comments on commit 6e2e645

Please sign in to comment.