public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH] patman: Fix defaults not propegating to subparsers
@ 2022-04-22 16:50 Sean Anderson
  2022-04-27 20:11 ` Alper Nebi Yasak
  0 siblings, 1 reply; 3+ messages in thread
From: Sean Anderson @ 2022-04-22 16:50 UTC (permalink / raw)
  To: u-boot, Simon Glass; +Cc: Sean Anderson

On python 3.8.10, subparsers are not updated with defaults. I suspect
this is related to [1]. Fix this by explicitly updating subparsers with
settings.

[1] https://github.com/python/cpython/issues/89398

Fixes: 3145b63513 ("patman: Update defaults in subparsers")
Signed-off-by: Sean Anderson <sean.anderson@seco.com>
---

 tools/patman/settings.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/patman/settings.py b/tools/patman/settings.py
index 7c2b5c196c..658fe12be5 100644
--- a/tools/patman/settings.py
+++ b/tools/patman/settings.py
@@ -246,8 +246,10 @@ def _UpdateDefaults(main_parser, config):
 
     # Collect the defaults from each parser
     defaults = {}
+    parser_defaults = []
     for parser in parsers:
         pdefs = parser.parse_known_args()[0]
+        parser_defaults.append(pdefs)
         defaults.update(vars(pdefs))
 
     # Go through the settings and collect defaults
@@ -264,8 +266,10 @@ def _UpdateDefaults(main_parser, config):
         else:
             print("WARNING: Unknown setting %s" % name)
 
-    # Set all the defaults (this propagates through all subparsers)
+    # Set all the defaults (this does NOT propagate through all subparsers)
     main_parser.set_defaults(**defaults)
+    for parser, pdefs in zip(parsers, parser_defaults):
+        parser.set_defaults(**{ k: v for k, v in defaults.items() if k in pdefs})
 
 def _ReadAliasFile(fname):
     """Read in the U-Boot git alias file if it exists.
-- 
2.35.1.1320.gc452695387.dirty


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

* Re: [PATCH] patman: Fix defaults not propegating to subparsers
  2022-04-22 16:50 [PATCH] patman: Fix defaults not propegating to subparsers Sean Anderson
@ 2022-04-27 20:11 ` Alper Nebi Yasak
  2022-04-28 14:41   ` Sean Anderson
  0 siblings, 1 reply; 3+ messages in thread
From: Alper Nebi Yasak @ 2022-04-27 20:11 UTC (permalink / raw)
  To: Sean Anderson; +Cc: u-boot, Simon Glass

On 22/04/2022 19:50, Sean Anderson wrote:
> On python 3.8.10, subparsers are not updated with defaults. I suspect
> this is related to [1]. Fix this by explicitly updating subparsers with
> settings.
> 
> [1] https://github.com/python/cpython/issues/89398
> 
> Fixes: 3145b63513 ("patman: Update defaults in subparsers")
> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
> ---
> 
>  tools/patman/settings.py | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

Also happens on Python 3.10. I can add the following to ~/.patman:

    [settings]
    ignore_bad_tags: True
    dry_run: True

and they start taking effect only after this patch.

Reviewed-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Tested-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>

> 
> diff --git a/tools/patman/settings.py b/tools/patman/settings.py
> index 7c2b5c196c..658fe12be5 100644
> --- a/tools/patman/settings.py
> +++ b/tools/patman/settings.py
> @@ -246,8 +246,10 @@ def _UpdateDefaults(main_parser, config):
>  
>      # Collect the defaults from each parser
>      defaults = {}
> +    parser_defaults = []
>      for parser in parsers:
>          pdefs = parser.parse_known_args()[0]
> +        parser_defaults.append(pdefs)
>          defaults.update(vars(pdefs))
>  
>      # Go through the settings and collect defaults
> @@ -264,8 +266,10 @@ def _UpdateDefaults(main_parser, config):
>          else:
>              print("WARNING: Unknown setting %s" % name)
>  
> -    # Set all the defaults (this propagates through all subparsers)
> +    # Set all the defaults (this does NOT propagate through all subparsers)

Something like 'Set all the defaults and manually propagate ...' would
be clearer here.

>      main_parser.set_defaults(**defaults)
> +    for parser, pdefs in zip(parsers, parser_defaults):
> +        parser.set_defaults(**{ k: v for k, v in defaults.items() if k in pdefs})

I think this would look better if you extract the dict as a variable.

>  
>  def _ReadAliasFile(fname):
>      """Read in the U-Boot git alias file if it exists.

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

* Re: [PATCH] patman: Fix defaults not propegating to subparsers
  2022-04-27 20:11 ` Alper Nebi Yasak
@ 2022-04-28 14:41   ` Sean Anderson
  0 siblings, 0 replies; 3+ messages in thread
From: Sean Anderson @ 2022-04-28 14:41 UTC (permalink / raw)
  To: Alper Nebi Yasak; +Cc: u-boot, Simon Glass

Hi Alper,

On 4/27/22 4:11 PM, Alper Nebi Yasak wrote:
> On 22/04/2022 19:50, Sean Anderson wrote:
>> On python 3.8.10, subparsers are not updated with defaults. I suspect
>> this is related to [1]. Fix this by explicitly updating subparsers with
>> settings.
>> 
>> [1] https://github.com/python/cpython/issues/89398
>> 
>> Fixes: 3145b63513 ("patman: Update defaults in subparsers")
>> Signed-off-by: Sean Anderson <sean.anderson@seco.com>
>> ---
>> 
>>  tools/patman/settings.py | 6 +++++-
>>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> Also happens on Python 3.10. I can add the following to ~/.patman:
> 
>     [settings]
>     ignore_bad_tags: True
>     dry_run: True
> 
> and they start taking effect only after this patch.
> 
> Reviewed-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
> Tested-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
> 
>> 
>> diff --git a/tools/patman/settings.py b/tools/patman/settings.py
>> index 7c2b5c196c..658fe12be5 100644
>> --- a/tools/patman/settings.py
>> +++ b/tools/patman/settings.py
>> @@ -246,8 +246,10 @@ def _UpdateDefaults(main_parser, config):
>>  
>>      # Collect the defaults from each parser
>>      defaults = {}
>> +    parser_defaults = []
>>      for parser in parsers:
>>          pdefs = parser.parse_known_args()[0]
>> +        parser_defaults.append(pdefs)
>>          defaults.update(vars(pdefs))
>>  
>>      # Go through the settings and collect defaults
>> @@ -264,8 +266,10 @@ def _UpdateDefaults(main_parser, config):
>>          else:
>>              print("WARNING: Unknown setting %s" % name)
>>  
>> -    # Set all the defaults (this propagates through all subparsers)
>> +    # Set all the defaults (this does NOT propagate through all subparsers)
> 
> Something like 'Set all the defaults and manually propagate ...' would
> be clearer here.

Sounds good.

>>      main_parser.set_defaults(**defaults)
>> +    for parser, pdefs in zip(parsers, parser_defaults):
>> +        parser.set_defaults(**{ k: v for k, v in defaults.items() if k in pdefs})
> 
> I think this would look better if you extract the dict as a variable.

I'm not sure what you mean. I'm not a big fan of single-use variables (though
this is an 81-character line...)

--Sean

>>  
>>  def _ReadAliasFile(fname):
>>      """Read in the U-Boot git alias file if it exists.
> 

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

end of thread, other threads:[~2022-04-28 14:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-22 16:50 [PATCH] patman: Fix defaults not propegating to subparsers Sean Anderson
2022-04-27 20:11 ` Alper Nebi Yasak
2022-04-28 14:41   ` Sean Anderson

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