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

"Arthur Zamarin" <[email protected]>
Newsgroups gmane.linux.gentoo.cvs
Message-ID <1786987641.e839d0cf6b0e3bac2517f7be96b29c481bc2c7af.arthurzam@gentoo>
commit:     e839d0cf6b0e3bac2517f7be96b29c481bc2c7af
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Mon Aug 17 17:27:21 2026 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Mon Aug 17 17:27:21 2026 +0000
URL:        https://gitweb.gentoo.org/proj/pkgcore/pkgdev.git/commit/?id=e839d0cf

mangle: use pkgcore's sort_keywords

Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/pkgdev/mangle.py |  8 ++------
 tests/test_mangle.py | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/pkgdev/mangle.py b/src/pkgdev/mangle.py
index e818965..78a5319 100644
--- a/src/pkgdev/mangle.py
+++ b/src/pkgdev/mangle.py
@@ -8,6 +8,7 @@ import signal
 import traceback
 from datetime import datetime
 
+from pkgcore.ebuild.misc import sort_keywords
 from snakeoil.cli.exceptions import UserException
 from snakeoil.mappings import OrderedSet
 
@@ -71,15 +72,10 @@ class Mangler:
     @mangle("keywords")
     def _keywords(self, change):
         """Fix keywords order."""
-
-        def keywords_sort_key(kw):
-            return tuple(reversed(kw.lstrip("-~").partition("-")))
-
         lines = change.data.splitlines()
         for i, line in enumerate(lines):
             if mo := keywords_regex.match(line):
-                kw = sorted(mo.group("keywords").split(), key=keywords_sort_key)
-                new_kw = " ".join(kw)
+                new_kw = " ".join(sort_keywords(mo.group("keywords").split()))
                 if not mo.group("quote"):
                     new_kw = f'"{new_kw}"'
                 lines[i] = f"{mo.group('pre')}{new_kw}{mo.group('post')}"

diff --git a/tests/test_mangle.py b/tests/test_mangle.py
index 207a3ee..b594202 100644
--- a/tests/test_mangle.py
+++ b/tests/test_mangle.py
@@ -52,6 +52,22 @@ class TestMangler:
         assert list(Mangler([fake_change(path)])) == [str(path)]
         assert path.read_text() == "# comment\n"
 
+    @pytest.mark.parametrize(
+        ("original", "expected"),
+        (
+            # glob-arches first, then arches, then prefix-arches
+            ('KEYWORDS="~x86-macos amd64 -* ~alpha"', '"-* ~alpha amd64 ~x86-macos"'),
+            # unquoted keywords gain quotes
+            ("KEYWORDS=sparc", '"sparc"'),
+            ("KEYWORDS='sparc ~arm64 alpha'", "'alpha ~arm64 sparc'"),
+        ),
+    )
+    def test_keywords_order(self, tmp_path, original, expected):
+        path = tmp_path / "pkg-1.ebuild"
+        path.write_text(f"# comment\n{original}\n")
+        assert list(Mangler([fake_change(path)])) == [str(path)]
+        assert path.read_text() == f"# comment\nKEYWORDS={expected}\n"
+
     def test_iterator_exceptions(self, tmp_path):
         """Test parallelized iterator against unhandled exceptions."""
         path = tmp_path / "file"
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.