Skip to content

Commit

Permalink
Improve unsatisfied output (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb authored Dec 14, 2023
1 parent bcf3222 commit 8d0d29b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
20 changes: 11 additions & 9 deletions src/packse/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,19 @@ def render_versions(
for_requirement: Requirement | None = None,
):
versions = packages[package].versions
if for_requirement:
versions = [
version
for version in versions
if for_requirement.specifier.contains(version)
]

if not versions:
yield prefix + last + "unsatisfied: no matching version"
return

pointers = [tee] * (len(versions) - 1) + [last]
satisfied = False
for pointer, version in zip(pointers, versions):
if for_requirement and not for_requirement.specifier.contains(version):
continue

satisfied = True
message = "satisfied by " if for_requirement else ""
yield prefix + pointer + message + f"{package}-{version}"

Expand All @@ -81,9 +86,6 @@ def render_versions(
versions[version].requires, prefix=prefix + extension
)

if for_requirement and not satisfied:
yield prefix + last + "unsatisfied"

def render_requirements(requirements: list[str], prefix: str = ""):
pointers = [tee] * (len(requirements) - 1) + [last]
for pointer, requirement in zip(pointers, sorted(requirements)):
Expand All @@ -99,7 +101,7 @@ def render_requirements(requirements: list[str], prefix: str = ""):
for_requirement=parsed_requirement,
)
else:
yield prefix + space + last + "unsatisfied"
yield prefix + space + last + "unsatisfied: no versions for package"

# Print the root package first
pointer = tee if scenario.packages else last
Expand Down
14 changes: 7 additions & 7 deletions tests/__snapshots__/test_scenarios.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -631,12 +631,12 @@
requires-package-does-not-exist-e4666012
└── root
└── requires a
└── unsatisfied
└── unsatisfied: no versions for package

requires-exact-version-does-not-exist-c640da4b
├── root
│ └── requires a==2.0.0
│ └── unsatisfied
│ └── unsatisfied: no matching version
└── a
└── a-1.0.0

Expand All @@ -651,7 +651,7 @@
requires-less-version-does-not-exist-14de847d
├── root
│ └── requires a<2.0.0
│ └── unsatisfied
│ └── unsatisfied: no matching version
└── a
├── a-2.0.0
├── a-3.0.0
Expand All @@ -664,7 +664,7 @@
└── a
└── a-1.0.0
└── requires b
└── unsatisfied
└── unsatisfied: no versions for package


''',
Expand All @@ -686,7 +686,7 @@
requires-direct-incompatible-versions-3a64108d
├── root
│ ├── requires a==1.0.0
│ │ ── satisfied by a-1.0.0
│ │ ── satisfied by a-1.0.0
│ └── requires a==2.0.0
│ └── satisfied by a-2.0.0
└── a
Expand All @@ -698,7 +698,7 @@
│ ├── requires a
│ │ └── satisfied by a-1.0.0
│ └── requires b==1.0.0
── satisfied by b-1.0.0
── satisfied by b-1.0.0
├── a
│ └── a-1.0.0
│ └── requires b==2.0.0
Expand All @@ -716,7 +716,7 @@
├── a
│ └── a-1.0.0
│ └── requires c==1.0.0
── satisfied by c-1.0.0
── satisfied by c-1.0.0
├── b
│ └── b-1.0.0
│ └── requires c==2.0.0
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/test_view.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
├── b-1.0.0
├── b-2.0.0
│ └── requires c
│ └── unsatisfied
│ └── unsatisfied: no versions for package
└── b-3.0.0


Expand Down

0 comments on commit 8d0d29b

Please sign in to comment.