Skip to content

Commit 4b0add2

Browse files
committed
Replace narrow_for_display workaround with _FmtRange subclass
nab-resolver's error reporter renders constraints via two code paths: _narrow_positive (which calls narrow_for_display) and direct interpolation of Incompatibility.constraint_range in the CONSTRAINT-cause path. The previous narrow_for_display approach only covered the first path, leaving CONSTRAINT-cause lines with raw (-inf, X) sentinel notation. _FmtRange overrides __str__ to produce operator-prefixed output and overrides all Range operators to preserve the subclass through composition. _constraint_to_range now returns _FmtRange, so every range we construct formats itself at every render site. narrow_for_display becomes a one-line fallback that wraps any library-internal Range the resolver might surface directly.
1 parent 8996fef commit 4b0add2

3 files changed

Lines changed: 14 additions & 21 deletions

File tree

‎testing/baselines/tests.builtin-spicy-version-error/output‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
22
error: failed to resolve dependencies: because no versions of one/alice/foo <X.X.X | >X.X.X are available
3-
because one/alice/foo =X.X.X depends on zeek-builtin/spicy-plugin (-inf, X.X.X)
4-
so one/alice/foo * and not zeek-builtin/spicy-plugin (-inf, X.X.X)
3+
because one/alice/foo =X.X.X depends on zeek-builtin/spicy-plugin <X.X.X
4+
so one/alice/foo * and not zeek-builtin/spicy-plugin <X.X.X
55
because no versions of zeek-builtin/spicy-plugin <X.X.X are available
66
so one/alice/foo *
77
because your project depends on one/alice/foo *

‎testing/baselines/tests.unsatisfied-version-tag-dependency/fail.out‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
22
error: failed to resolve dependencies: because no versions of one/alice/foo <0.0.0 | >0.0.0 are available
3-
because one/alice/foo =0.0.0 depends on one/alice/bar 1.0.0
4-
so one/alice/foo * and not one/alice/bar 1.0.0
3+
because one/alice/foo =0.0.0 depends on one/alice/bar =1.0.0
4+
so one/alice/foo * and not one/alice/bar =1.0.0
55
because no versions of one/alice/bar =1.0.0 are available
66
so one/alice/foo *
77
because your project depends on one/alice/foo *

‎zeekpkg/_resolver.py‎

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from nab_resolver.ranges import Range
2020
from nab_resolver.resolver import Resolver, ResolverProvider
2121
from nab_resolver.types import Incompatibility, RangeProtocol
22+
from typing_extensions import Self
2223

2324
from ._util import _semver_versions, git_version_tags, is_sha1
2425
from .package import (
@@ -74,25 +75,25 @@ def _normalize_constraint(spec: str) -> str:
7475
return spec
7576

7677

77-
def _constraint_to_range(constraint: str) -> Range[semver.Version]:
78+
def _constraint_to_range(constraint: str) -> _FmtRange:
7879
"""Convert a normalized zkg constraint string to a nab-resolver `Range`."""
7980
if constraint in ("*", ""):
80-
return Range.full()
81-
result: Range[semver.Version] = Range.full()
81+
return _FmtRange(Range.full()._intervals)
82+
result: _FmtRange = _FmtRange(Range.full()._intervals)
8283
clause = semver.SimpleSpec(_normalize_constraint(constraint)).clause
8384
matchers = list(clause.clauses) if hasattr(clause, "clauses") else [clause]
8485
for m in matchers:
8586
v = semver.Version.coerce(str(m.target))
8687
if m.operator == ">=":
87-
result = result & Range.at_least(v)
88+
result = result & _FmtRange(Range.at_least(v)._intervals)
8889
elif m.operator == ">":
89-
result = result & Range.greater_than(v)
90+
result = result & _FmtRange(Range.greater_than(v)._intervals)
9091
elif m.operator == "<=":
91-
result = result & Range.at_most(v)
92+
result = result & _FmtRange(Range.at_most(v)._intervals)
9293
elif m.operator == "<":
93-
result = result & Range.less_than(v)
94+
result = result & _FmtRange(Range.less_than(v)._intervals)
9495
elif m.operator == "==":
95-
result = result & Range.singleton(v)
96+
result = result & _FmtRange(Range.singleton(v)._intervals)
9697
return result
9798

9899

@@ -349,15 +350,7 @@ def narrow_for_display(
349350
constraint: RangeProtocol[semver.Version],
350351
) -> RangeProtocol[semver.Version]:
351352
r = cast(Range[semver.Version], constraint)
352-
display = _fmt_range(r)
353-
354-
class _Displayed(Range[semver.Version]):
355-
__slots__ = ()
356-
357-
def __str__(self) -> str:
358-
return display
359-
360-
return cast(RangeProtocol[semver.Version], _Displayed(r._intervals))
353+
return _FmtRange(r._intervals)
361354

362355

363356
def _run_solver(

0 commit comments

Comments
 (0)