lebrice / SimpleParsing

Simple, Elegant, Typed Argument Parsing with argparse
MIT License
410 stars 52 forks source link

Other ArgumentParser options are ignored when add_config_path_arg is True #239

Closed jtbates closed 1 year ago

jtbates commented 1 year ago

Describe the bug Using the add_config_path_arg option in ArgumentParser causes other options to be ignored such as add_option_string_dash_variants, argument_generation_mode, and nested_mode.

To Reproduce

from dataclasses import dataclass, field

from simple_parsing import ArgumentParser, DashVariant
from simple_parsing.wrappers.field_wrapper import ArgumentGenerationMode, NestedMode

@dataclass
class NestedParams:
    num_units: int = 4

@dataclass
class Params:
    num_layers: int = 4
    nested: NestedParams = field(default_factory=lambda: NestedParams())

parser = ArgumentParser(
    add_config_path_arg=True,
    add_option_string_dash_variants=DashVariant.DASH,
    argument_generation_mode=ArgumentGenerationMode.NESTED,
    nested_mode=NestedMode.WITHOUT_ROOT,
)
parser.add_arguments(Params, dest="params")

args = parser.parse_args()

parser.print_help()

Expected behavior The expected output is

usage: test_add_config_path_dash.py [-h] [--num-layers int] [--nested.num-units int]

optional arguments:
  -h, --help            show this help message and exit
  --config-path Path    Path to a config file containing default values to use. (default: None)

Params ['params']:
  Params(num_layers: int = 4, nested: __main__.NestedParams = <factory>)

  --num-layers int      (default: 4)

NestedParams ['params.nested']:
  NestedParams(num_units: int = 4)

  --nested.num-units int
                        (default: 4)

Actual behavior The actual output is

usage: test_add_config_path_dash.py [-h] [--config_path Path] [--num_layers int] [--num_units int]

optional arguments:
  -h, --help          show this help message and exit
  --config_path Path  Path to a config file containing default values to use. (default: None)

Params ['params']:
  Params(num_layers: int = 4, nested: __main__.NestedParams = <factory>)

  --num_layers int    (default: 4)

NestedParams ['params.nested']:
  NestedParams(num_units: int = 4)

  --num_units int     (default: 4)

Desktop (please complete the following information):

lebrice commented 1 year ago

Hello there @jtbates , thanks for posting this!

Wow that's a really nice bug. I'll take a look and get back to you.

lebrice commented 1 year ago

I think this was fixed with #248