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

Preserve package's source when it has extras #6472

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
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