proj/pkgcore/pkgdev:main commit in: tests/scripts/, src/pkgdev/scripts/, /

"Arthur Zamarin" <[email protected]>
Newsgroups gmane.linux.gentoo.cvs
Message-ID <1786699696.1a6cb150b21d4a8a4150c6178962bb739d04613d.arthurzam@gentoo>
commit:     1a6cb150b21d4a8a4150c6178962bb739d04613d
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Fri Aug 14 09:28:16 2026 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Fri Aug 14 09:28:16 2026 +0000
URL:        https://gitweb.gentoo.org/proj/pkgcore/pkgdev.git/commit/?id=1a6cb150

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: https://github.com/pkgcore/pkgdev/issues/80
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 NEWS.rst                              |  6 ++++++
 src/pkgdev/scripts/pkgdev_manifest.py |  5 ++++-
 tests/scripts/test_pkgdev_manifest.py | 20 ++++++++++++++++++++
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/NEWS.rst b/NEWS.rst
index c2f4e3c..51a9270 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -12,6 +12,12 @@ pkgdev 0.2.17 (unreleased)
   containers and root shells. Per the XDG basedir spec such values are now
   discarded in favor of ``~/.config`` (Arthur Zamarin, #179)
 
+**pkgdev manifest:**
+
+- manifest: any file inside a package directory now manifests that package,
+  so ``pkgdev manifest files/some.patch`` works rather than failing to parse
+  the path as an atom (Arthur Zamarin, #80)
+
 **pkgdev bugs:**
 
 - bugs: bash and zsh completion now complete stabilization groups as targets,

diff --git a/src/pkgdev/scripts/pkgdev_manifest.py b/src/pkgdev/scripts/pkgdev_manifest.py
index 4a8fce4..66257da 100644
--- a/src/pkgdev/scripts/pkgdev_manifest.py
+++ b/src/pkgdev/scripts/pkgdev_manifest.py
@@ -85,7 +85,10 @@ def _restrict_targets(repo, targets):
         if os.path.exists(target):
             try:
                 if target in repo:
-                    target = os.path.relpath(target, repo.location)
+                    target = os.path.relpath(os.path.realpath(target), repo.location)
+                    # anything else inside a package dir manifests that package
+                    if len(parts := target.split(os.sep)) > 2 and not target.endswith(".ebuild"):
+                        target = os.sep.join(parts[:2])
                 restrictions.append(repo.path_restrict(target))
             except ValueError as exc:
                 manifest.error(exc)

diff --git a/tests/scripts/test_pkgdev_manifest.py b/tests/scripts/test_pkgdev_manifest.py
index ef83862..b02731e 100644
--- a/tests/scripts/test_pkgdev_manifest.py
+++ b/tests/scripts/test_pkgdev_manifest.py
@@ -1,3 +1,4 @@
+import os
 from contextlib import chdir
 from functools import partial
 from os.path import join as pjoin
@@ -5,6 +6,7 @@ from typing import List, Set
 from unittest.mock import patch
 
 import pytest
+from snakeoil.fileutils import touch
 
 from pkgdev.scripts import run
 
@@ -189,6 +191,24 @@ class TestPkgdevManifest:
         out, err = capsys.readouterr()
         assert out == err == ""
 
+    def test_target_within_pkgdir(self, capsys, repo):
+        """Any file inside a package dir manifests that package."""
+        repo.create_ebuild("cat/pkg-0")
+        pkgdir = os.path.dirname(repo.create_ebuild("cat/pkg-1"))
+        os.makedirs(pjoin(pkgdir, "files"), exist_ok=True)
+        touch(pjoin(pkgdir, "files", "a.patch"))
+        for target in ("files/a.patch", "files", "metadata.xml"):
+            touch(pjoin(pkgdir, "metadata.xml"))
+            with (
+                patch("sys.argv", self.args + [target]),
+                pytest.raises(SystemExit) as excinfo,
+                chdir(pkgdir),
+            ):
+                self.script()
+            assert excinfo.value.code == 0
+            out, err = capsys.readouterr()
+            assert err == ""
+
     def test_bad_manifest(self, capsys, repo):
         repo.create_ebuild("cat/pkg-0")
         repo.create_ebuild("cat/pkg-1", eapi="-1")
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.