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

fix #8614 source constriants failed with extras #8802

Closed
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion src/poetry/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,18 @@ def __init__(

self._locker = locker
self._config = config
self._pool = RepositoryPool(config=config)

local_config = local_config or {}
dependency_source_cache = {}

for group in [*local_config.get("group", {}).values(), local_config]:
for name, dependency in group.get("dependencies", {}).items():
if isinstance(dependency, dict) and "source" in dependency:
dependency_source_cache[name] = dependency["source"]

self._pool = RepositoryPool(
config=config, dependency_source_mapping=dependency_source_cache
)
self._plugin_manager: PluginManager | None = None
self._disable_cache = disable_cache

Expand Down
10 changes: 10 additions & 0 deletions src/poetry/repositories/repository_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(
repositories: list[Repository] | None = None,
ignore_repository_names: object = _SENTINEL,
*,
dependency_source_mapping: dict[str, str] | None = None,
config: Config | None = None,
) -> None:
super().__init__("poetry-repository-pool")
Expand All @@ -59,6 +60,10 @@ def __init__(
cache_dir=(config or Config.create()).artifacts_cache_directory
)

self._dependency_source_mapping: dict[str, str] = (
dependency_source_mapping or {}
)

if ignore_repository_names is not _SENTINEL:
warnings.warn(
"The 'ignore_repository_names' argument to 'RepositoryPool.__init__' is"
Expand Down Expand Up @@ -211,6 +216,11 @@ def find_packages(self, dependency: Dependency) -> list[Package]:
if repository_name:
return self.repository(repository_name).find_packages(dependency)

if dependency.name in self._dependency_source_mapping:
return self.repository(
self._dependency_source_mapping[dependency.name]
).find_packages(dependency)

packages: list[Package] = []
for repo in self.repositories:
if packages and self.get_priority(repo.name) is Priority.SUPPLEMENTAL:
Expand Down
17 changes: 17 additions & 0 deletions tests/repositories/test_repository_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,23 @@ def test_pool_find_packages_in_specified_repository() -> None:
assert returned_packages_unavailable == []


def test_pool_find_packages_with_dependency_source_mapping() -> None:
package_foo1 = get_package("foo1", "1.1.1")
package_foo2 = get_package("foo2", "1.1.1")

bar = Repository("bar", [package_foo1, package_foo2])
pool = RepositoryPool(dependency_source_mapping={"foo1": "bar"})
pool.add_repository(bar, priority=Priority.EXPLICIT)

available_dependency = get_dependency("foo1", "^1.0.0")
returned_packages_available = pool.find_packages(available_dependency)
unavailable_dependency = get_dependency("foo2", "^1.0.0")
returned_unavailable_dependency = pool.find_packages(unavailable_dependency)

assert returned_packages_available == [package_foo1]
assert returned_unavailable_dependency == []


def test_search_no_legacy_repositories() -> None:
package_foo1 = get_package("foo", "1.0.0")
package_foo2 = get_package("foo", "2.0.0")
Expand Down