Skip to content

Commit fc6c6fb

Browse files
committed
mangle: add the blank line after the EAPI assignment
Resolves: #127 Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent f8355c3 commit fc6c6fb

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

NEWS.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ pkgdev 0.2.18 (unreleased)
3030
and having its caches invalidated through a pkgcore internal meant for
3131
mutable repositories (Arthur Zamarin, #172)
3232

33+
- commit: the mangler now adds the blank line after the ``EAPI=`` assignment
34+
(Arthur Zamarin, #127)
35+
3336
**pkgdev showkw:**
3437

3538
- showkw: drop the vendored copy of tabulate in favor of a dependency on

src/pkgdev/mangle.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class decorator:
3131
def __init__(self, func):
3232
self.func = func
3333

34-
def __set_name__(self, owner, name):
34+
def __set_name__(self, owner, attr):
3535
owner._mangle_funcs[name] = self.func
36-
setattr(owner, name, self.func)
36+
setattr(owner, attr, self.func)
3737

3838
return decorator
3939

@@ -70,6 +70,17 @@ def _eof(self, change):
7070
"""Drop EOF whitespace and forcibly add EOF newline."""
7171
return change.update(change.data.rstrip() + "\n")
7272

73+
@mangle("eapi-blank-line")
74+
def _eapi_blank_line(self, change):
75+
"""Add the blank line after the EAPI assignment."""
76+
lines = change.data.splitlines()
77+
for i, line in enumerate(lines):
78+
if line.startswith("EAPI="):
79+
if i + 1 < len(lines) and lines[i + 1] != "":
80+
lines.insert(i + 1, "")
81+
break
82+
return change.update("\n".join(lines) + "\n")
83+
7384
@mangle("keywords")
7485
def _keywords(self, change):
7586
"""Fix keywords order."""

tests/scripts/test_pkgdev_commit.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,6 +1046,27 @@ def commit(args):
10461046
assert mo.group("begin") == years[:4] + "-"
10471047
assert mo.group("holder") == "Gentoo Authors"
10481048

1049+
# keep the rest of the ebuild, only the spacing after EAPI= varies
1050+
with open(ebuild_path) as f:
1051+
lines = f.read().splitlines()
1052+
eapi_lineno = next(i for i, line in enumerate(lines) if line.startswith("EAPI="))
1053+
head, rest = lines[: eapi_lineno + 1], [x for x in lines[eapi_lineno + 1 :] if x]
1054+
1055+
for original, expected in (
1056+
(["# comment"], ["", "# comment"]),
1057+
(["", "# comment"], ["", "# comment"]),
1058+
# a line which merely looks empty isn't one
1059+
([" ", "# comment"], ["", " ", "# comment"]),
1060+
):
1061+
# munge the lines after the EAPI assignment
1062+
with open(ebuild_path, "w") as f:
1063+
f.write("\n".join(head + original + rest) + "\n")
1064+
commit(["-n", "-u", "-m", "mangling"])
1065+
# verify the blank line after EAPI= is there
1066+
with open(ebuild_path) as f:
1067+
mangled = f.read().splitlines()
1068+
assert mangled[eapi_lineno + 1 : eapi_lineno + 1 + len(expected)] == expected
1069+
10491070
for original, expected in (
10501071
('"arm64 amd64 x86"', "amd64 arm64 x86"),
10511072
('"arm64 amd64 ~x86"', "amd64 arm64 ~x86"),

0 commit comments

Comments
 (0)