Skip to content

Commit 1a6cb15

Browse files
committed
manifest: accept any path inside a package directory as a target
Only an ebuild or a package directory could be named. Anything else got handed to path_restrict as-is and parsed as an atom, so pointing at a file you had just touched failed with a message about the wrong thing entirely: $ pkgdev manifest files/some.patch pkgdev manifest: error: net-libs/files: missing package version Resolve a path below a package directory to that package, so naming a patch, metadata.xml or the Manifest itself manifests the package holding it. Resolves: #80 Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 69e6b88 commit 1a6cb15

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎NEWS.rst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ pkgdev 0.2.17 (unreleased)
1212
containers and root shells. Per the XDG basedir spec such values are now
1313
discarded in favor of ``~/.config`` (Arthur Zamarin, #179)
1414

15+
**pkgdev manifest:**
16+
17+
- manifest: any file inside a package directory now manifests that package,
18+
so ``pkgdev manifest files/some.patch`` works rather than failing to parse
19+
the path as an atom (Arthur Zamarin, #80)
20+
1521
**pkgdev bugs:**
1622

1723
- bugs: bash and zsh completion now complete stabilization groups as targets,

‎src/pkgdev/scripts/pkgdev_manifest.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ def _restrict_targets(repo, targets):
8585
if os.path.exists(target):
8686
try:
8787
if target in repo:
88-
target = os.path.relpath(target, repo.location)
88+
target = os.path.relpath(os.path.realpath(target), repo.location)
89+
# anything else inside a package dir manifests that package
90+
if len(parts := target.split(os.sep)) > 2 and not target.endswith(".ebuild"):
91+
target = os.sep.join(parts[:2])
8992
restrictions.append(repo.path_restrict(target))
9093
except ValueError as exc:
9194
manifest.error(exc)

‎tests/scripts/test_pkgdev_manifest.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import os
12
from contextlib import chdir
23
from functools import partial
34
from os.path import join as pjoin
45
from typing import List, Set
56
from unittest.mock import patch
67

78
import pytest
9+
from snakeoil.fileutils import touch
810

911
from pkgdev.scripts import run
1012

@@ -189,6 +191,24 @@ def test_good_manifest(self, capsys, repo):
189191
out, err = capsys.readouterr()
190192
assert out == err == ""
191193

194+
def test_target_within_pkgdir(self, capsys, repo):
195+
"""Any file inside a package dir manifests that package."""
196+
repo.create_ebuild("cat/pkg-0")
197+
pkgdir = os.path.dirname(repo.create_ebuild("cat/pkg-1"))
198+
os.makedirs(pjoin(pkgdir, "files"), exist_ok=True)
199+
touch(pjoin(pkgdir, "files", "a.patch"))
200+
for target in ("files/a.patch", "files", "metadata.xml"):
201+
touch(pjoin(pkgdir, "metadata.xml"))
202+
with (
203+
patch("sys.argv", self.args + [target]),
204+
pytest.raises(SystemExit) as excinfo,
205+
chdir(pkgdir),
206+
):
207+
self.script()
208+
assert excinfo.value.code == 0
209+
out, err = capsys.readouterr()
210+
assert err == ""
211+
192212
def test_bad_manifest(self, capsys, repo):
193213
repo.create_ebuild("cat/pkg-0")
194214
repo.create_ebuild("cat/pkg-1", eapi="-1")

0 commit comments

Comments
 (0)