Skip to content

Add test and detailed error message for unsupported dependency case #184

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

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/poetry_plugin_export/walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,27 @@ def get_locked_package(

# If we have an overlapping candidate, we must use it.
if overlapping_candidates:
compatible_candidates = [
filtered_compatible_candidates = [
package
for package in compatible_candidates
if package in overlapping_candidates
]

if not filtered_compatible_candidates:
# TODO: Support this case:
# https://github.com/python-poetry/poetry-plugin-export/issues/183
raise DependencyWalkerError(
f"The `{dependency.name}` package has the following compatible"
f" candidates `{compatible_candidates}`; but, the exporter dependency"
f" walker previously elected `{overlapping_candidates.pop()}` which is"
f" not compatible with the dependency `{dependency}`. Please contribute"
" to `poetry-plugin-export` to solve this problem."
)

compatible_candidates = filtered_compatible_candidates

return next(iter(compatible_candidates), None)


class DependencyWalkerError(Exception):
pass
27 changes: 27 additions & 0 deletions tests/test_walker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from __future__ import annotations

import pytest

from packaging.utils import NormalizedName
from poetry.core.packages.dependency import Dependency
from poetry.core.packages.package import Package

from poetry_plugin_export.walker import DependencyWalkerError
from poetry_plugin_export.walker import walk_dependencies


def test_walk_dependencies_multiple_versions_when_latest_is_not_compatible() -> None:
# TODO: Support this case:
# https://github.com/python-poetry/poetry-plugin-export/issues/183
with pytest.raises(DependencyWalkerError):
walk_dependencies(
dependencies=[
Dependency("grpcio", ">=1.42.0"),
Dependency("grpcio", ">=1.42.0,<=1.49.1"),
Dependency("grpcio", ">=1.47.0,<2.0dev"),
],
packages_by_name={
"grpcio": [Package("grpcio", "1.51.3"), Package("grpcio", "1.49.1")]
},
root_package_name=NormalizedName("package-name"),
)