diff mbox series

[b4] Fix prep-perpatch-check-cmd in .b4-config

Message ID 20240626-b4-config-check-cmd-v1-1-83fc971196f9@collins.com (mailing list archive)
State Accepted
Headers show
Series [b4] Fix prep-perpatch-check-cmd in .b4-config | expand

Commit Message

Brandon Maier June 26, 2024, 7:34 p.m. UTC
Trying to use the 'prep-perpatch-check-cmd' config from a repo
with '.b4-config' fails. For example as follows

  $ b4 --version
  0.14.0
  $ printf '[b4]\n\tprep-perpatch-check-cmd = "true"\n' >.b4-config \
        && git add .b4-config && git commit -m b4-test
  $ b4 prep --check
  Checking patches using:
    t
    r
    u
    e
  ---
  Traceback (most recent call last):
    File "/home/blmaier/.local/bin/b4", line 8, in <module>
      sys.exit(cmd())
               ^^^^^
    File "/home/blmaier/.local/lib/python3.12/site-packages/b4/command.py", line 417, in cmd
      cmdargs.func(cmdargs)
    File "/home/blmaier/.local/lib/python3.12/site-packages/b4/command.py", line 83, in cmd_prep
      b4.ez.cmd_prep(cmdargs)
    File "/home/blmaier/.local/lib/python3.12/site-packages/b4/ez.py", line 2822, in cmd_prep
      return check(cmdargs)
             ^^^^^^^^^^^^^^
    File "/home/blmaier/.local/lib/python3.12/site-packages/b4/ez.py", line 1707, in check
      ckrep = b4.LoreMessage.run_local_check(ppcmdargs, commit, msg, nocache=cmdargs.nocache)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/blmaier/.local/lib/python3.12/site-packages/b4/__init__.py", line 1522, in run_local_check
      ecode, out, err = _run_command(cmdargs, stdin=bdata, rundir=topdir)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/home/blmaier/.local/lib/python3.12/site-packages/b4/__init__.py", line 2650, in _run_command
      sp = subprocess.Popen(cmdargs, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib64/python3.12/subprocess.py", line 1026, in __init__
      self._execute_child(args, executable, preexec_fn, close_fds,
    File "/usr/lib64/python3.12/subprocess.py", line 1955, in _execute_child
      raise child_exception_type(errno_num, err_msg, err_filename)
  FileNotFoundError: [Errno 2] No such file or directory: 't'

The problem is 'prep-perpatch-check-cmd' is the special 'multival' type
(Python list). But when the .b4-config is imported it does not specify
the multival types, so it gets imported as a string. When b4 tries to
call the check-cmd later on, it gets iterated over as if it were a list
but instead returns each character.

Signed-off-by: Brandon Maier <brandon.maier@collins.com>
---
 src/b4/__init__.py | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)


---
base-commit: 131835a44c63511e2def9d7adc680754b7ea502c
change-id: 20240626-b4-config-check-cmd-210f09b29138

Best regards,

Comments

Konstantin Ryabitsev Sept. 6, 2024, 2:47 p.m. UTC | #1
On Wed, 26 Jun 2024 19:34:46 +0000, Brandon Maier wrote:
> Trying to use the 'prep-perpatch-check-cmd' config from a repo
> with '.b4-config' fails. For example as follows
> 
>   $ b4 --version
>   0.14.0
>   $ printf '[b4]\n\tprep-perpatch-check-cmd = "true"\n' >.b4-config \
>         && git add .b4-config && git commit -m b4-test
>   $ b4 prep --check
>   Checking patches using:
>     t
>     r
>     u
>     e
>   ---
>   Traceback (most recent call last):
>     File "/home/blmaier/.local/bin/b4", line 8, in <module>
>       sys.exit(cmd())
>                ^^^^^
>     File "/home/blmaier/.local/lib/python3.12/site-packages/b4/command.py", line 417, in cmd
>       cmdargs.func(cmdargs)
>     File "/home/blmaier/.local/lib/python3.12/site-packages/b4/command.py", line 83, in cmd_prep
>       b4.ez.cmd_prep(cmdargs)
>     File "/home/blmaier/.local/lib/python3.12/site-packages/b4/ez.py", line 2822, in cmd_prep
>       return check(cmdargs)
>              ^^^^^^^^^^^^^^
>     File "/home/blmaier/.local/lib/python3.12/site-packages/b4/ez.py", line 1707, in check
>       ckrep = b4.LoreMessage.run_local_check(ppcmdargs, commit, msg, nocache=cmdargs.nocache)
>               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     File "/home/blmaier/.local/lib/python3.12/site-packages/b4/__init__.py", line 1522, in run_local_check
>       ecode, out, err = _run_command(cmdargs, stdin=bdata, rundir=topdir)
>                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     File "/home/blmaier/.local/lib/python3.12/site-packages/b4/__init__.py", line 2650, in _run_command
>       sp = subprocess.Popen(cmdargs, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     File "/usr/lib64/python3.12/subprocess.py", line 1026, in __init__
>       self._execute_child(args, executable, preexec_fn, close_fds,
>     File "/usr/lib64/python3.12/subprocess.py", line 1955, in _execute_child
>       raise child_exception_type(errno_num, err_msg, err_filename)
>   FileNotFoundError: [Errno 2] No such file or directory: 't'
> 
> [...]

Applied, thanks!

[1/1] Fix prep-perpatch-check-cmd in .b4-config
      commit: d5f395677ea538c12cb2fe055a11d569957bdc67

Best regards,
diff mbox series

Patch

diff --git a/src/b4/__init__.py b/src/b4/__init__.py
index 7164d3f..1f89280 100644
--- a/src/b4/__init__.py
+++ b/src/b4/__init__.py
@@ -2840,6 +2840,14 @@  def get_config_from_git(regexp: str, defaults: Optional[dict] = None,
     return gitconfig
 
 
+def _val_to_path(topdir, val):
+    if val.startswith('./'):
+        # replace it with full topdir path
+        return os.path.abspath(os.path.join(topdir, val))
+    else:
+        return val
+
+
 def _setup_main_config(cmdargs: Optional[argparse.Namespace] = None) -> None:
     global MAIN_CONFIG
 
@@ -2848,23 +2856,24 @@  def _setup_main_config(cmdargs: Optional[argparse.Namespace] = None) -> None:
     # so load them up and use as defaults
     topdir = git_get_toplevel()
     wtglobs = ['prep-*-check-cmd', 'send-*', '*mask', '*template*', 'trailer*', 'pw-*']
+    multivals = ['keyringsrc', 'am-perpatch-check-cmd', 'prep-perpatch-check-cmd']
     if topdir:
         wtcfg = os.path.join(topdir, '.b4-config')
         if os.access(wtcfg, os.R_OK):
             logger.debug('Loading worktree configs from %s', wtcfg)
-            wtconfig = get_config_from_git(r'b4\..*', source=wtcfg)
+            wtconfig = get_config_from_git(r'b4\..*', multivals=multivals, source=wtcfg)
             logger.debug('wtcfg=%s', wtconfig)
             for key, val in wtconfig.items():
-                if val.startswith('./'):
-                    # replace it with full topdir path
-                    val = os.path.abspath(os.path.join(topdir, val))
+                if key in multivals:
+                    val = [_val_to_path(topdir, x) for x in val]
+                else:
+                    val = _val_to_path(topdir, val)
                 for wtglob in wtglobs:
                     if fnmatch.fnmatch(key, wtglob):
                         logger.debug('wtcfg: %s=%s', key, val)
                         defcfg[key] = val
                         break
-    config = get_config_from_git(r'b4\..*', defaults=defcfg,
-                                 multivals=['keyringsrc', 'am-perpatch-check-cmd', 'prep-perpatch-check-cmd'])
+    config = get_config_from_git(r'b4\..*', defaults=defcfg, multivals=multivals)
     config['listid-preference'] = config['listid-preference'].split(',')
     config['listid-preference'].remove('*')
     config['listid-preference'].append('*')