[arch-projects] [namcap] [PATCH] Add rule to report on unneeded dependencies from hooks

Eli Schwartz eschwartz at archlinux.org
Thu Apr 11 01:45:19 UTC 2019


Just as it is unnecessary to run certain commands in a post_upgrade
script, if a hook already runs it, so too is it usually unnecessary to
depend on the package that installs the hook.

Sometimes these dependencies are left in even when the install script is
removed, because people lack understanding in the true subtleties of
hooks and the commands they run -- but the commands do not depend on the
list of files which trigger them in order to function, and are fully
operative when installed later. In fact, they will already be required
by the software that uses the results.

e.g. desktop-file-utils and shared-mime-info provide hooks to compile
the mime and desktop file databases, but upon first installing the hook,
a full database will already be compiled. The hook does not need to be
triggered by the filepath, and thus does not need to be a dependency of
every package that provides a desktop or mime file. Instead, desktop
environments which need a mime/desktop file database will depend on the
package and thereby ensure the database exists when needed.

Signed-off-by: Eli Schwartz <eschwartz at archlinux.org>
---

With this plus my previous patch, namcap will stop warning when these
dependencies are missing, and instead, warn when they are used.

I've yet to hear a convincing reason why these dependencies would be
wanted -- I suspect they exist mostly because of inertia, or because
they were copied from another (historic?) PKGBUILD that was used as a
role model.

 Namcap/rules/__init__.py    |  1 +
 Namcap/rules/hookdepends.py | 48 +++++++++++++++++++++++++++++++++++++
 namcap-tags                 |  8 ++++---
 3 files changed, 54 insertions(+), 3 deletions(-)
 create mode 100644 Namcap/rules/hookdepends.py

diff --git a/Namcap/rules/__init__.py b/Namcap/rules/__init__.py
index 1e05326..525dbc6 100644
--- a/Namcap/rules/__init__.py
+++ b/Namcap/rules/__init__.py
@@ -31,6 +31,7 @@ from . import (
   fileownership,
   gnomemime,
   hardlinks,
+  hookdepends,
   infodirectory,
   javafiles,
   kdeprograms,
diff --git a/Namcap/rules/hookdepends.py b/Namcap/rules/hookdepends.py
new file mode 100644
index 0000000..dcf03a1
--- /dev/null
+++ b/Namcap/rules/hookdepends.py
@@ -0,0 +1,48 @@
+#
+# namcap rules - hookdepends
+# Copyright (C) 2019 Eli Schwartz <eschwartz at archlinux.org>
+# Copyright (C) 2016 Kyle Keen <keenerd at gmail.com>
+#
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 2 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program; if not, write to the Free Software
+#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+#
+
+import re
+from Namcap.ruleclass import *
+
+class HookDependsRule(TarballRule):
+	name = "hookdepends"
+	description = "Check for redundant hook dependencies"
+	subrules = [
+		{
+			'path': '^usr/share/applications/.*\.desktop$',
+			'dep': 'desktop-file-utils',
+		},
+		{
+			'path': '^usr/share/mime$',
+			'dep': 'shared-mime-info',
+		}
+	]
+	def analyze(self, pkginfo, tar):
+		names = [entry.name for entry in tar]
+		for subrule in self.subrules:
+			pattern = re.compile(subrule['path'])
+			if any(pattern.search(n) for n in names):
+				dep = subrule['dep']
+				if dep in pkginfo['depends']:
+					self.warnings = [('external-hooks-unneeded-warning', ())]
+					self.infos.append(('external-hooks-unneeded-name %s', dep))
+
+
+# vim: set ts=4 sw=4 noet:
diff --git a/namcap-tags b/namcap-tags
index 17b9506..84cc3f7 100644
--- a/namcap-tags
+++ b/namcap-tags
@@ -1,11 +1,11 @@
 # namcap tags file
-# The tags file consists of lines specifying the human readable form of the 
-# hyphenated tags used in the namcap code. A line beginning with a '#' is 
+# The tags file consists of lines specifying the human readable form of the
+# hyphenated tags used in the namcap code. A line beginning with a '#' is
 # treated as a comment. Otherwise the format of the file is:
 #
 #	machine-parseable-tag %s :: This is machine parseable tag %s
 #
-# Note that a double colon (::) is used to separate the hyphenated tag from the 
+# Note that a double colon (::) is used to separate the hyphenated tag from the
 # human readable description.
 
 # rules tags
@@ -26,6 +26,8 @@ empty-directory %s :: Directory (%s) is empty
 error-running-rule %s :: Error running rule '%s'
 external-hooks-name %s :: .INSTALL file runs a command (%s) provided by hooks.
 external-hooks-warning :: .INSTALL file runs a command provided by hooks.
+external-hooks-unneeded-name %s :: unneeded dependency on a package (%s) run when needed by hooks.
+external-hooks-unneeded-warning :: unneeded dependency on a package run when needed by hooks.
 extra-var-begins-without-underscore %s :: Non standard variable '%s' doesn't start with an underscore
 file-in-non-standard-dir %s :: File (%s) exists in a non-standard directory.
 file-in-temporary-dir %s :: File (%s) is in a temporary directory.
-- 
2.21.0


More information about the arch-projects mailing list