[arch-projects] [namcap] [PATCH 1/5] namcap-devel: Quote arguments
--- namcap-devel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/namcap-devel b/namcap-devel index 8619a67..bdb94df 100755 --- a/namcap-devel +++ b/namcap-devel @@ -6,4 +6,4 @@ export PARSE_PKGBUILD_PATH PYTHONPATH="$(pwd)" export PYTHONPATH -./namcap -t namcap-tags $@ +./namcap -t namcap-tags "$@" -- 2.25.0
--- namcap-devel | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/namcap-devel b/namcap-devel index bdb94df..5b88fe3 100755 --- a/namcap-devel +++ b/namcap-devel @@ -1,9 +1,8 @@ #!/bin/sh -PATH="$(pwd):$PATH" -PARSE_PKGBUILD_PATH="$(pwd)" -export PARSE_PKGBUILD_PATH +namcap=$(cd "$(dirname "$0")" && pwd) +PATH=$namcap:$PATH +export PARSE_PKGBUILD_PATH=$namcap -PYTHONPATH="$(pwd)" -export PYTHONPATH +export PYTHONPATH=$namcap -./namcap -t namcap-tags "$@" +"$namcap"/namcap -t "$namcap"/namcap-tags "$@" -- 2.25.0
--- README | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README b/README index c90315e..83b406b 100644 --- a/README +++ b/README @@ -141,6 +141,16 @@ warnings we are expecting from the rules. The test suite is in Namcap/tests. The makepkg and pkgbuild_test submodules provide easy generic methods to test a rule. +To run the test suite, run: + +env PARSE_PKGBUILD_PATH="$PWD" \ + PATH="$PWD:$PATH" \ + python setup.py test + +To run a single test, append e.g. +"-s Namcap.tests.package.test_shebangdepends" +to the command-line above. + Here is an example testing the rule "pkgnameindesc" from Namcap.tests.pkgbuild_test import PkgbuildTest -- 2.25.0
--- README | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README b/README index 83b406b..b018466 100644 --- a/README +++ b/README @@ -21,8 +21,14 @@ Minimal examples (very simple packages forged to exhibit unexpected behaviour from namcap) are also welcome to extend namcap's test suite. If you've a patch (fixing a bug or a new namcap module), then you can send it -to the arch-projects mailing list. Namcap development is managed with git, so -git-formatted patches are preferred. +to the arch-projects mailing list. + +Namcap development is managed with git, so git-formatted patches are preferred. +When sending patches to the mailing list, make sure to set a valid +subjectprefix, otherwise the email will be rejected by Mailman. Git can be +configured as follows: + +git config format.subjectprefix namcap] [PATCH' Namcap's source is available on: -- 2.25.0
Vladimir Panteleev writes:
--- README | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/README b/README index 83b406b..b018466 100644 --- a/README +++ b/README @@ -21,8 +21,14 @@ Minimal examples (very simple packages forged to exhibit unexpected behaviour from namcap) are also welcome to extend namcap's test suite.
If you've a patch (fixing a bug or a new namcap module), then you can send it -to the arch-projects mailing list. Namcap development is managed with git, so -git-formatted patches are preferred. +to the arch-projects mailing list. + +Namcap development is managed with git, so git-formatted patches are preferred. +When sending patches to the mailing list, make sure to set a valid +subjectprefix, otherwise the email will be rejected by Mailman. Git can be +configured as follows: + +git config format.subjectprefix namcap] [PATCH'
Looks like a typo, I believe it is?
Namcap's source is available on:
Artur Juraszek <artur@juraszek.xyz> writes:
Vladimir Panteleev writes:
+git config format.subjectprefix namcap] [PATCH'
Looks like a typo, I believe it is?
Oops, yes, I missed a '. If that's the only problem, please add it before committing, I'll fix it in v2 otherwise.
If the user has a non-canonical (i.e. symlinked on Arch) location in front of their $PATH, such as /usr/sbin, shutil.which will return locations with that path. This later causes the rule to fail to find the binary in any packages, causing spurious library-no-package-associated and dependency-not-needed warnings. Fix this by resolving all symlinks for executables (using os.path.realpath) before trying to find them among installed packages. --- Namcap/rules/shebangdepends.py | 3 +- Namcap/tests/package/test_shebangdepends.py | 38 +++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Namcap/rules/shebangdepends.py b/Namcap/rules/shebangdepends.py index 07896df..fc359c3 100644 --- a/Namcap/rules/shebangdepends.py +++ b/Namcap/rules/shebangdepends.py @@ -21,7 +21,7 @@ """Checks dependencies on programs specified in shebangs.""" -import shutil +import shutil, os.path import Namcap.package from Namcap.util import is_script, script_type from Namcap.ruleclass import * @@ -59,6 +59,7 @@ def findowners(scriptlist): out = shutil.which(s) if not out: continue + out = os.path.realpath(out) # strip leading slash scriptpath = out.lstrip('/') diff --git a/Namcap/tests/package/test_shebangdepends.py b/Namcap/tests/package/test_shebangdepends.py index dbacd86..b92e9fe 100644 --- a/Namcap/tests/package/test_shebangdepends.py +++ b/Namcap/tests/package/test_shebangdepends.py @@ -60,5 +60,43 @@ package() { ]) self.assertEqual(w, []) + valid_pkgbuild = """ +pkgname=__namcap_test_shebangdepends +pkgver=1.0 +pkgrel=1 +pkgdesc="A package" +arch=('any') +url="http://www.example.com/" +license=('GPL') +depends=('python') +source=() +options=(!purge !zipman) +build() { + cd "${srcdir}" + echo -e "#! /usr/bin/env python\nprint('a script')" > python_sample +} +package() { + install -Dm755 "$srcdir/python_sample" "$pkgdir/usr/bin/python_sample" +} +""" + def test_shebangdepends_noncanonical(self): + "shutil.which returns noncanonical path (e.g. in /usr/sbin)" + pkgfile = "__namcap_test_shebangdepends-1.0-1-any.pkg.tar" + with open(os.path.join(self.tmpdir, "PKGBUILD"), "w") as f: + f.write(self.valid_pkgbuild) + self.run_makepkg() + old_path = os.environ['PATH'] + try: + os.environ['PATH'] = '/usr/sbin:' + old_path + pkg, r = self.run_rule_on_tarball( + os.path.join(self.tmpdir, pkgfile), + Namcap.rules.shebangdepends.ShebangDependsRule + ) + finally: + os.environ['PATH'] = old_path + e, w, i = Namcap.depends.analyze_depends(pkg) + self.assertEqual(e, []) + self.assertEqual(w, []) + # vim: set ts=4 sw=4 noet: -- 2.25.0
On 1/17/20 8:19 AM, Vladimir Panteleev wrote:
If the user has a non-canonical (i.e. symlinked on Arch) location in front of their $PATH, such as /usr/sbin, shutil.which will return locations with that path. This later causes the rule to fail to find the binary in any packages, causing spurious library-no-package-associated and dependency-not-needed warnings.
Fix this by resolving all symlinks for executables (using os.path.realpath) before trying to find them among installed packages.
FWIW a lot of software will break if you do this, not just namcap. There's an exceedingly good reason why /usr/sbin and other symlink directories are *not* added to the $PATH on archlinux, unless the user has unwisely added it by hand. -- Eli Schwartz Bug Wrangler and Trusted User
Eli Schwartz <eschwartz@archlinux.org> writes:
FWIW a lot of software will break if you do this, not just namcap. There's an exceedingly good reason why /usr/sbin and other symlink directories are *not* added to the $PATH on archlinux, unless the user has unwisely added it by hand.
FWIW, in my case I added it to my .profile so that it worked on other distributions too, without requiring fancy logic such as checking distro or filesystem layout. That was several years ago, and this is the first problem I noticed so far.
participants (3)
-
Artur Juraszek
-
Eli Schwartz
-
Vladimir Panteleev