From a841ddd00c1600662f3f42646d61dd0b34dfb7e4 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Wed, 24 Jul 2024 10:11:32 -0500 Subject: `spack pkg grep`: don't warn when grepping for quoted strings (#45412) The `Executable` class emits a warning when you pass quoted arguments to it: ``` > spack pkg grep '"namespace"' ==> Warning: Quotes in command arguments can confuse scripts like configure. The following arguments may cause problems when executed: "namespace" Quotes aren't needed because spack doesn't use a shell. Consider removing them. If multiple levels of quotation are required, use `ignore_quotes=True`. ``` This is to warn new package authors who aren't used to calling build commands in python. It's not useful for `spack pkg grep`, where we really are passing args on the command line, and if we pass a quoted string, we probably meant to. - [x] make `ignore_quotes` an instance variable, not just an argument to ``__call__` - [x] set `ignore_quotes` to `True` in `spack pkg grep` Signed-off-by: Todd Gamblin --- lib/spack/spack/cmd/pkg.py | 4 +++- lib/spack/spack/util/executable.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/spack/spack/cmd/pkg.py b/lib/spack/spack/cmd/pkg.py index e4e616db56..b21313cbc4 100644 --- a/lib/spack/spack/cmd/pkg.py +++ b/lib/spack/spack/cmd/pkg.py @@ -169,7 +169,9 @@ def pkg_hash(args): def get_grep(required=False): """Get a grep command to use with ``spack pkg grep``.""" - return exe.which(os.environ.get("SPACK_GREP") or "grep", required=required) + grep = exe.which(os.environ.get("SPACK_GREP") or "grep", required=required) + grep.ignore_quotes = True # allow `spack pkg grep '"quoted string"'` without warning + return grep def pkg_grep(args, unknown_args): diff --git a/lib/spack/spack/util/executable.py b/lib/spack/spack/util/executable.py index afb8bcaa39..b4974fc9b5 100644 --- a/lib/spack/spack/util/executable.py +++ b/lib/spack/spack/util/executable.py @@ -31,6 +31,7 @@ class Executable: self.default_envmod = EnvironmentModifications() self.returncode = None + self.ignore_quotes = False if not self.exe: raise ProcessError("Cannot construct executable for '%s'" % name) @@ -188,7 +189,7 @@ class Executable: fail_on_error = kwargs.pop("fail_on_error", True) ignore_errors = kwargs.pop("ignore_errors", ()) - ignore_quotes = kwargs.pop("ignore_quotes", False) + ignore_quotes = kwargs.pop("ignore_quotes", self.ignore_quotes) timeout = kwargs.pop("timeout", None) # If they just want to ignore one error code, make it a tuple. -- cgit v1.2.3-70-g09d2