Compare commits

..
Author SHA1 Message Date
d2e4d3d240
lib.pkg_relations: Beautify exceptions
Some checks failed
CI / Packaging - Kali Linux (pull_request) Failing after 4m7s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Failing after 3m58s
CI / Packaging test (pull_request) Failing after 0s
In pkg_relations(), pass dependent_package to Dependency.parse_deps_spec()
for better error reporting.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-09-10 08:11:01 +02:00
7d2217597b
lib.version.Dependency: Beautify exceptions
Add a dependent_package parameter to Dependency's constructor, and use it
in exceptions the class raises.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-09-10 08:11:01 +02:00
2 changed files with 14 additions and 12 deletions

View file

@ -45,11 +45,6 @@ class Dependency: # export
case 3:
if not parts[0] or not parts[2]:
self.__raise(f'Invalid dependency spec "{self.__spec}"')
if parts[2] == 'REVISION':
self.__raise(
f'Spec "{self.__spec}": a bare REVISION renders as a '
'bare number, which is likely not what the user intended'
)
return parts[0], Boundary(
op=parts[1],
version=Version(parts[0], parts[2], self.__lookup_version),

View file

@ -1,3 +1,6 @@
import io
from jw.pkg.lib.log import add_capture_stream, rm_capture_stream
from jw.pkg.lib.version import Component, Dependency, Syntax, Version
class FakeApp:
@ -79,13 +82,17 @@ assert d.constraint_str(untemplated=False, include_revision=False) == \
# untemplated=False keeps the specifiers as written
d = Dependency('foo = VERSION', app.get_version)
assert d.constraint_str(untemplated = False) == 'foo = VERSION'
# A bare REVISION is rejected on the grounds that is assumed that
# the user wanted VERSION instead
try:
Dependency('foo = REVISION', app.get_version).constraint_str()
assert False, 'Should have raised'
except Dependency.Error:
pass
# REVISION resolves to the revision part
d = Dependency('foo = REVISION', app.get_version)
assert d.constraint_str() == 'foo = 45'
assert d.constraint_str(untemplated = False) == 'foo = REVISION'
# A bare REVISION warns: RPM reads a bare number as a version
buf = io.StringIO()
sd = add_capture_stream(buf)
d = Dependency('foo = REVISION', app.get_version)
assert d.constraint_str() == 'foo = 45'
assert 'not a release constraint' in buf.getvalue()
rm_capture_stream(sd)
# The lookup uses the base name, not the subpackage name
d = Dependency('foo-devel = VERSION', app.get_version)