Gentoo Archives: gentoo-commits

From: Arthur Zamarin <arthurzam@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/, ...
Date: Mon, 31 Oct 2022 18:17:59
Message-Id: 1667240170.bda333c718420b2c1ff124ed2e32b9f96f534d2e.arthurzam@gentoo
1 commit: bda333c718420b2c1ff124ed2e32b9f96f534d2e
2 Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
3 AuthorDate: Fri Oct 28 13:57:38 2022 +0000
4 Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
5 CommitDate: Mon Oct 31 18:16:10 2022 +0000
6 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=bda333c7
7
8 DoCompressedFilesCheck: new check for compressed do calls
9
10 New check for catching passing compressed manpages to doman and newman,
11 and passing compressed info to doinfo.
12
13 Resolves: https://github.com/pkgcore/pkgcheck/issues/477
14 Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>
15
16 src/pkgcheck/checks/codingstyle.py | 49 ++++++++++++++++++++++
17 .../InstallCompressedInfo/expected.json | 4 ++
18 .../InstallCompressedManpage/expected.json | 4 ++
19 .../InstallCompressedInfo-0.ebuild | 12 ++++++
20 .../InstallCompressedManpage-0.ebuild | 12 ++++++
21 5 files changed, 81 insertions(+)
22
23 diff --git a/src/pkgcheck/checks/codingstyle.py b/src/pkgcheck/checks/codingstyle.py
24 index b6ef8c34..4bf9932d 100644
25 --- a/src/pkgcheck/checks/codingstyle.py
26 +++ b/src/pkgcheck/checks/codingstyle.py
27 @@ -1118,3 +1118,52 @@ class LineLengthCheck(Check):
28 lines.append(lineno)
29 if lines:
30 yield ExcessiveLineLength(lines=lines, pkg=pkg)
31 +
32 +
33 +class InstallCompressedManpage(results.LineResult, results.Warning):
34 + """Compressed manpages are not supported by ``doman`` or ``newman``."""
35 +
36 + def __init__(self, func, **kwargs):
37 + super().__init__(**kwargs)
38 + self.func = func
39 +
40 + @property
41 + def desc(self):
42 + return f'line {self.lineno}: compressed manpage {self.line!r} passed to {self.func}'
43 +
44 +
45 +class InstallCompressedInfo(results.LineResult, results.Warning):
46 + """Compressed manpages are not supported by ``doinfo``."""
47 +
48 + def __init__(self, func, **kwargs):
49 + super().__init__(**kwargs)
50 + self.func = func
51 +
52 + @property
53 + def desc(self):
54 + return f'line {self.lineno}: compressed info {self.line!r} passed to {self.func}'
55 +
56 +
57 +class DoCompressedFilesCheck(Check):
58 + """Scan ebuild for compressed files passed to ``do*`` or ``new**``."""
59 +
60 + _source = sources.EbuildParseRepoSource
61 + known_results = frozenset([InstallCompressedManpage, InstallCompressedInfo])
62 +
63 + compresion_extentions = ('.Z', '.gz', '.bz2', '.lzma', '.lz', '.lzo', '.lz4', '.xz', '.zst')
64 + functions = ImmutableDict({
65 + 'doman': InstallCompressedManpage,
66 + 'newman': InstallCompressedManpage,
67 + 'doinfo': InstallCompressedInfo,
68 + })
69 +
70 + def feed(self, pkg):
71 + for node, _ in bash.cmd_query.captures(pkg.tree.root_node):
72 + call_name = pkg.node_str(node.child_by_field_name('name'))
73 + if call_name not in self.functions:
74 + continue
75 + for arg in node.children[1:]:
76 + arg_name = pkg.node_str(arg).strip('\'\"')
77 + lineno, _ = arg.start_point
78 + if arg_name.endswith(self.compresion_extentions):
79 + yield self.functions[call_name](call_name, lineno=lineno+1, line=arg_name, pkg=pkg)
80
81 diff --git a/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/expected.json b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/expected.json
82 new file mode 100644
83 index 00000000..fcc8d776
84 --- /dev/null
85 +++ b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/expected.json
86 @@ -0,0 +1,4 @@
87 +{"__class__": "InstallCompressedInfo", "category": "DoCompressedFilesCheck", "package": "InstallCompressedInfo", "version": "0", "line": "${PN}.bz2", "lineno": 9, "func": "doinfo"}
88 +{"__class__": "InstallCompressedInfo", "category": "DoCompressedFilesCheck", "package": "InstallCompressedInfo", "version": "0", "line": "test.gz", "lineno": 9, "func": "doinfo"}
89 +{"__class__": "InstallCompressedInfo", "category": "DoCompressedFilesCheck", "package": "InstallCompressedInfo", "version": "0", "line": "${P}.xz", "lineno": 10, "func": "newinfo"}
90 +{"__class__": "InstallCompressedInfo", "category": "DoCompressedFilesCheck", "package": "InstallCompressedInfo", "version": "0", "line": "${PN}.xz", "lineno": 10, "func": "newinfo"}
91
92 diff --git a/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/expected.json b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/expected.json
93 new file mode 100644
94 index 00000000..b743d171
95 --- /dev/null
96 +++ b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/expected.json
97 @@ -0,0 +1,4 @@
98 +{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "${PN}.2.bz2", "lineno": 9, "func": "doman"}
99 +{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "test.gz", "lineno": 9, "func": "doman"}
100 +{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "${PN}.1.xz", "lineno": 10, "func": "newman"}
101 +{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "${PN}.xz", "lineno": 10, "func": "newman"}
102
103 diff --git a/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/InstallCompressedInfo-0.ebuild b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/InstallCompressedInfo-0.ebuild
104 new file mode 100644
105 index 00000000..73020827
106 --- /dev/null
107 +++ b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/InstallCompressedInfo-0.ebuild
108 @@ -0,0 +1,12 @@
109 +EAPI=7
110 +
111 +DESCRIPTION="Ebuild installing compressed info"
112 +HOMEPAGE="https://github.com/pkgcore/pkgcheck"
113 +SLOT="0"
114 +LICENSE="BSD"
115 +
116 +src_install() {
117 + doinfo 'test.gz' "${PN}.bz2"
118 + newinfo ${P}.xz "${PN}.xz"
119 + doinfo "${PN}"
120 +}
121
122 diff --git a/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/InstallCompressedManpage-0.ebuild b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/InstallCompressedManpage-0.ebuild
123 new file mode 100644
124 index 00000000..7248d16a
125 --- /dev/null
126 +++ b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/InstallCompressedManpage-0.ebuild
127 @@ -0,0 +1,12 @@
128 +EAPI=7
129 +
130 +DESCRIPTION="Ebuild installing compressed man pages"
131 +HOMEPAGE="https://github.com/pkgcore/pkgcheck"
132 +SLOT="0"
133 +LICENSE="BSD"
134 +
135 +src_install() {
136 + doman 'test.gz' "${PN}.2.bz2"
137 + newman ${PN}.xz "${PN}.1.xz"
138 + doman "${PN}"
139 +}