Support operating on source repos (#10)
Some checks failed
CI via Tox / tox (pull_request) Failing after 1m23s

So I happened to find another reason to work on #10 - it's useful
for figuring out the consequences of dropping a package:

quality/tickets#880 (comment)

The good news is, this turns out to be easy. We only need a small
change to the repository modification code to handle source repos,
where the package entries don't specifiy a sourcerpm - we just
take the package name. We identify this case by looking at the
package arch; if it's "src" we just take the name, if it's
anything else we use the existing approach.

With this change, you can just include the appropriate source
repository as a base repository, and otherwise use rmdepcheck
just the same. e.g. this command tests what happens if you drop
the python-pytest-xprocess package from F44:

./rmdepcheck.py --removes https://dl.fedoraproject.org/pub/fedora/linux/development/44/Everything/x86_64/os/,https://dl.fedoraproject.org/pub/fedora/linux/development/44/Everything/source/tree/ python-pytest-xprocess

You can see it works because there are results for .src packages
from the source repo; these are build dependencies. If you run the
same command without the source repo you get a smaller set of
results covering only the runtime dependencies.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
This commit is contained in:
Adam Williamson 2026-03-17 11:55:12 -07:00
commit c212769e1b
3 changed files with 37 additions and 13 deletions

View file

@ -153,8 +153,13 @@ def replace_primary(primfn: str, removes: Iterable[str]) -> tuple[str, int, str,
primtree = et.parse(primfn)
primroot = primtree.getroot()
for pkg in primroot.findall("common:package", XMLNS):
srpm = mfind(mfind(pkg, "common:format", XMLNS), "rpm:sourcerpm", XMLNS).text
if srpm and srpm.rsplit("-", 2)[0] in removes:
if mfind(pkg, "common:arch", XMLNS).text == "src":
spkg = mfind(pkg, "common:name", XMLNS).text
else:
spkg = mfind(mfind(pkg, "common:format", XMLNS), "rpm:sourcerpm", XMLNS).text
if spkg:
spkg = spkg.rsplit("-", 2)[0]
if spkg and spkg in removes:
primroot.remove(pkg)
tempfn = f"{rddir}/primtemp.xml"

View file

@ -95,24 +95,43 @@ def test_get_download_primary():
)
def test_replace_primary():
@pytest.mark.parametrize(
"repotup", (
(
"binary",
(
"42daebf05f6c3cabe9d029acb3a8056f7fc533cde9820b7388d90acb1f6e7dbe",
1067,
"562981a96ba946cd0f993d180108c4dd107d1a5f24210c5768b19cdd93e8f33a",
7531,
)
),
(
"source",
(
"3378e32450503892f65c6ff2a77a451f069146c4284a69f21752e113918da64f",
566,
"7ac52d6a0f3c0314a58f78eff39f4a7b5721127816b1b59d8ef30f4a29e091d9",
1045,
)
)
)
)
def test_replace_primary(repotup):
repo, expected = repotup
with tempfile.TemporaryDirectory() as tempdir:
shutil.copy2(
# this is an old version of base's primary file
f"{TESTDATA}/test_replace_primary.xml",
# binary.xml is an old version of base's primary file
# source.xml is a primary file from a repo with just
# ccc.src and ddd.src packages
f"{TESTDATA}/test_replace_primary_{repo}.xml",
f"{tempdir}/test.xml",
)
ret = rmdepcheck.replace_primary(f"{tempdir}/test.xml", "ccc")
print(tempdir)
assert ret == (
"42daebf05f6c3cabe9d029acb3a8056f7fc533cde9820b7388d90acb1f6e7dbe",
1067,
"562981a96ba946cd0f993d180108c4dd107d1a5f24210c5768b19cdd93e8f33a",
7531,
)
assert ret == expected
assert os.path.exists(
# pylint: disable-next=line-too-long
f"{tempdir}/42daebf05f6c3cabe9d029acb3a8056f7fc533cde9820b7388d90acb1f6e7dbe-primary.xml.zst"
f"{tempdir}/{expected[0]}-primary.xml.zst"
)