Skip to content

Commit

Permalink
fix #8514 source constriants failed with extras
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemia committed Dec 18, 2023
1 parent f310a59 commit 2c8864d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
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

0 comments on commit 2c8864d

Please sign in to comment.