public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/, ...
@ 2022-10-31 18:17 Arthur Zamarin
  0 siblings, 0 replies; 2+ messages in thread
From: Arthur Zamarin @ 2022-10-31 18:17 UTC (permalink / raw
  To: gentoo-commits

commit:     bda333c718420b2c1ff124ed2e32b9f96f534d2e
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 28 13:57:38 2022 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 31 18:16:10 2022 +0000
URL:        https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=bda333c7

DoCompressedFilesCheck: new check for compressed do calls

New check for catching passing compressed manpages to doman and newman,
and passing compressed info to doinfo.

Resolves: https://github.com/pkgcore/pkgcheck/issues/477
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/pkgcheck/checks/codingstyle.py                 | 49 ++++++++++++++++++++++
 .../InstallCompressedInfo/expected.json            |  4 ++
 .../InstallCompressedManpage/expected.json         |  4 ++
 .../InstallCompressedInfo-0.ebuild                 | 12 ++++++
 .../InstallCompressedManpage-0.ebuild              | 12 ++++++
 5 files changed, 81 insertions(+)

diff --git a/src/pkgcheck/checks/codingstyle.py b/src/pkgcheck/checks/codingstyle.py
index b6ef8c34..4bf9932d 100644
--- a/src/pkgcheck/checks/codingstyle.py
+++ b/src/pkgcheck/checks/codingstyle.py
@@ -1118,3 +1118,52 @@ class LineLengthCheck(Check):
             lines.append(lineno)
         if lines:
             yield ExcessiveLineLength(lines=lines, pkg=pkg)
+
+
+class InstallCompressedManpage(results.LineResult, results.Warning):
+    """Compressed manpages are not supported by ``doman`` or ``newman``."""
+
+    def __init__(self, func, **kwargs):
+        super().__init__(**kwargs)
+        self.func = func
+
+    @property
+    def desc(self):
+        return f'line {self.lineno}: compressed manpage {self.line!r} passed to {self.func}'
+
+
+class InstallCompressedInfo(results.LineResult, results.Warning):
+    """Compressed manpages are not supported by ``doinfo``."""
+
+    def __init__(self, func, **kwargs):
+        super().__init__(**kwargs)
+        self.func = func
+
+    @property
+    def desc(self):
+        return f'line {self.lineno}: compressed info {self.line!r} passed to {self.func}'
+
+
+class DoCompressedFilesCheck(Check):
+    """Scan ebuild for compressed files passed to ``do*`` or ``new**``."""
+
+    _source = sources.EbuildParseRepoSource
+    known_results = frozenset([InstallCompressedManpage, InstallCompressedInfo])
+
+    compresion_extentions = ('.Z', '.gz', '.bz2', '.lzma', '.lz', '.lzo', '.lz4', '.xz', '.zst')
+    functions = ImmutableDict({
+        'doman': InstallCompressedManpage,
+        'newman': InstallCompressedManpage,
+        'doinfo': InstallCompressedInfo,
+    })
+
+    def feed(self, pkg):
+        for node, _ in bash.cmd_query.captures(pkg.tree.root_node):
+            call_name = pkg.node_str(node.child_by_field_name('name'))
+            if call_name not in self.functions:
+                continue
+            for arg in node.children[1:]:
+                arg_name = pkg.node_str(arg).strip('\'\"')
+                lineno, _ = arg.start_point
+                if arg_name.endswith(self.compresion_extentions):
+                    yield self.functions[call_name](call_name, lineno=lineno+1, line=arg_name, pkg=pkg)

diff --git a/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/expected.json b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/expected.json
new file mode 100644
index 00000000..fcc8d776
--- /dev/null
+++ b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/expected.json
@@ -0,0 +1,4 @@
+{"__class__": "InstallCompressedInfo", "category": "DoCompressedFilesCheck", "package": "InstallCompressedInfo", "version": "0", "line": "${PN}.bz2", "lineno": 9, "func": "doinfo"}
+{"__class__": "InstallCompressedInfo", "category": "DoCompressedFilesCheck", "package": "InstallCompressedInfo", "version": "0", "line": "test.gz", "lineno": 9, "func": "doinfo"}
+{"__class__": "InstallCompressedInfo", "category": "DoCompressedFilesCheck", "package": "InstallCompressedInfo", "version": "0", "line": "${P}.xz", "lineno": 10, "func": "newinfo"}
+{"__class__": "InstallCompressedInfo", "category": "DoCompressedFilesCheck", "package": "InstallCompressedInfo", "version": "0", "line": "${PN}.xz", "lineno": 10, "func": "newinfo"}

diff --git a/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/expected.json b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/expected.json
new file mode 100644
index 00000000..b743d171
--- /dev/null
+++ b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/expected.json
@@ -0,0 +1,4 @@
+{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "${PN}.2.bz2", "lineno": 9, "func": "doman"}
+{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "test.gz", "lineno": 9, "func": "doman"}
+{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "${PN}.1.xz", "lineno": 10, "func": "newman"}
+{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "${PN}.xz", "lineno": 10, "func": "newman"}

diff --git a/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/InstallCompressedInfo-0.ebuild b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/InstallCompressedInfo-0.ebuild
new file mode 100644
index 00000000..73020827
--- /dev/null
+++ b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/InstallCompressedInfo-0.ebuild
@@ -0,0 +1,12 @@
+EAPI=7
+
+DESCRIPTION="Ebuild installing compressed info"
+HOMEPAGE="https://github.com/pkgcore/pkgcheck"
+SLOT="0"
+LICENSE="BSD"
+
+src_install() {
+	doinfo 'test.gz' "${PN}.bz2"
+	newinfo ${P}.xz "${PN}.xz"
+	doinfo "${PN}"
+}

diff --git a/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/InstallCompressedManpage-0.ebuild b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/InstallCompressedManpage-0.ebuild
new file mode 100644
index 00000000..7248d16a
--- /dev/null
+++ b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/InstallCompressedManpage-0.ebuild
@@ -0,0 +1,12 @@
+EAPI=7
+
+DESCRIPTION="Ebuild installing compressed man pages"
+HOMEPAGE="https://github.com/pkgcore/pkgcheck"
+SLOT="0"
+LICENSE="BSD"
+
+src_install() {
+	doman 'test.gz' "${PN}.2.bz2"
+	newman ${PN}.xz "${PN}.1.xz"
+	doman "${PN}"
+}


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/, ...
@ 2022-10-31 18:20 Arthur Zamarin
  0 siblings, 0 replies; 2+ messages in thread
From: Arthur Zamarin @ 2022-10-31 18:20 UTC (permalink / raw
  To: gentoo-commits

commit:     be9e91b4f8ebd49aeff8efd69cac8c61c54d5ba6
Author:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 28 13:57:38 2022 +0000
Commit:     Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Mon Oct 31 18:20:23 2022 +0000
URL:        https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=be9e91b4

DoCompressedFilesCheck: new check for compressed do calls

New check for catching passing compressed manpages to doman and newman,
and passing compressed info to doinfo.

Resolves: https://github.com/pkgcore/pkgcheck/issues/477
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>

 src/pkgcheck/checks/codingstyle.py                 | 49 ++++++++++++++++++++++
 .../InstallCompressedInfo/expected.json            |  2 +
 .../InstallCompressedManpage/expected.json         |  4 ++
 .../InstallCompressedInfo-0.ebuild                 | 11 +++++
 .../InstallCompressedManpage-0.ebuild              | 12 ++++++
 5 files changed, 78 insertions(+)

diff --git a/src/pkgcheck/checks/codingstyle.py b/src/pkgcheck/checks/codingstyle.py
index b6ef8c34..4bf9932d 100644
--- a/src/pkgcheck/checks/codingstyle.py
+++ b/src/pkgcheck/checks/codingstyle.py
@@ -1118,3 +1118,52 @@ class LineLengthCheck(Check):
             lines.append(lineno)
         if lines:
             yield ExcessiveLineLength(lines=lines, pkg=pkg)
+
+
+class InstallCompressedManpage(results.LineResult, results.Warning):
+    """Compressed manpages are not supported by ``doman`` or ``newman``."""
+
+    def __init__(self, func, **kwargs):
+        super().__init__(**kwargs)
+        self.func = func
+
+    @property
+    def desc(self):
+        return f'line {self.lineno}: compressed manpage {self.line!r} passed to {self.func}'
+
+
+class InstallCompressedInfo(results.LineResult, results.Warning):
+    """Compressed manpages are not supported by ``doinfo``."""
+
+    def __init__(self, func, **kwargs):
+        super().__init__(**kwargs)
+        self.func = func
+
+    @property
+    def desc(self):
+        return f'line {self.lineno}: compressed info {self.line!r} passed to {self.func}'
+
+
+class DoCompressedFilesCheck(Check):
+    """Scan ebuild for compressed files passed to ``do*`` or ``new**``."""
+
+    _source = sources.EbuildParseRepoSource
+    known_results = frozenset([InstallCompressedManpage, InstallCompressedInfo])
+
+    compresion_extentions = ('.Z', '.gz', '.bz2', '.lzma', '.lz', '.lzo', '.lz4', '.xz', '.zst')
+    functions = ImmutableDict({
+        'doman': InstallCompressedManpage,
+        'newman': InstallCompressedManpage,
+        'doinfo': InstallCompressedInfo,
+    })
+
+    def feed(self, pkg):
+        for node, _ in bash.cmd_query.captures(pkg.tree.root_node):
+            call_name = pkg.node_str(node.child_by_field_name('name'))
+            if call_name not in self.functions:
+                continue
+            for arg in node.children[1:]:
+                arg_name = pkg.node_str(arg).strip('\'\"')
+                lineno, _ = arg.start_point
+                if arg_name.endswith(self.compresion_extentions):
+                    yield self.functions[call_name](call_name, lineno=lineno+1, line=arg_name, pkg=pkg)

diff --git a/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/expected.json b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/expected.json
new file mode 100644
index 00000000..96e4e20c
--- /dev/null
+++ b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/expected.json
@@ -0,0 +1,2 @@
+{"__class__": "InstallCompressedInfo", "category": "DoCompressedFilesCheck", "package": "InstallCompressedInfo", "version": "0", "line": "${PN}.bz2", "lineno": 9, "func": "doinfo"}
+{"__class__": "InstallCompressedInfo", "category": "DoCompressedFilesCheck", "package": "InstallCompressedInfo", "version": "0", "line": "test.gz", "lineno": 9, "func": "doinfo"}

diff --git a/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/expected.json b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/expected.json
new file mode 100644
index 00000000..b743d171
--- /dev/null
+++ b/testdata/data/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/expected.json
@@ -0,0 +1,4 @@
+{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "${PN}.2.bz2", "lineno": 9, "func": "doman"}
+{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "test.gz", "lineno": 9, "func": "doman"}
+{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "${PN}.1.xz", "lineno": 10, "func": "newman"}
+{"__class__": "InstallCompressedManpage", "category": "DoCompressedFilesCheck", "package": "InstallCompressedManpage", "version": "0", "line": "${PN}.xz", "lineno": 10, "func": "newman"}

diff --git a/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/InstallCompressedInfo-0.ebuild b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/InstallCompressedInfo-0.ebuild
new file mode 100644
index 00000000..d82c952a
--- /dev/null
+++ b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/InstallCompressedInfo-0.ebuild
@@ -0,0 +1,11 @@
+EAPI=7
+
+DESCRIPTION="Ebuild installing compressed info"
+HOMEPAGE="https://github.com/pkgcore/pkgcheck"
+SLOT="0"
+LICENSE="BSD"
+
+src_install() {
+	doinfo 'test.gz' "${PN}.bz2"
+	doinfo "${PN}"
+}

diff --git a/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/InstallCompressedManpage-0.ebuild b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/InstallCompressedManpage-0.ebuild
new file mode 100644
index 00000000..7248d16a
--- /dev/null
+++ b/testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedManpage/InstallCompressedManpage-0.ebuild
@@ -0,0 +1,12 @@
+EAPI=7
+
+DESCRIPTION="Ebuild installing compressed man pages"
+HOMEPAGE="https://github.com/pkgcore/pkgcheck"
+SLOT="0"
+LICENSE="BSD"
+
+src_install() {
+	doman 'test.gz' "${PN}.2.bz2"
+	newman ${PN}.xz "${PN}.1.xz"
+	doman "${PN}"
+}


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-31 18:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-31 18:20 [gentoo-commits] proj/pkgcore/pkgcheck:master commit in: testdata/repos/standalone/DoCompressedFilesCheck/InstallCompressedInfo/, Arthur Zamarin
  -- strict thread matches above, loose matches on Subject: below --
2022-10-31 18:17 Arthur Zamarin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox