Merge pull request #1529 from trabucayre/parser_set_defaults
build/parser: overrides set_defaults and applying default values just before args_parse()
This commit is contained in:
commit
8599e2704d
|
@ -32,6 +32,9 @@ class LiteXArgumentParser(argparse.ArgumentParser):
|
|||
toolchain used at build time
|
||||
_default_toolchain: str
|
||||
toolchain to use by default or when no selection is done by the user
|
||||
_args_default: dict
|
||||
couple argument name / default value to apply just before to call
|
||||
parse_args()
|
||||
"""
|
||||
def __init__(self, platform=None, **kwargs):
|
||||
"""
|
||||
|
@ -55,6 +58,7 @@ class LiteXArgumentParser(argparse.ArgumentParser):
|
|||
self._toolchain = None
|
||||
self._target_group = None
|
||||
self._logging_group = None
|
||||
self._args_default = {}
|
||||
if platform is not None:
|
||||
self.set_platform(platform)
|
||||
self.add_target_group()
|
||||
|
@ -111,6 +115,18 @@ class LiteXArgumentParser(argparse.ArgumentParser):
|
|||
self._logging_group.add_argument("--log-filename", default=None, help="Logging filename.")
|
||||
self._logging_group.add_argument("--log-level", default="info", help="Logging level: debug, info (default), warning error or critical.")
|
||||
|
||||
def set_defaults(self, **kwargs):
|
||||
"""
|
||||
Overrides argparse.ArgumentParser.set_defaults. Used to delay default
|
||||
values application
|
||||
|
||||
Parameters
|
||||
==========
|
||||
kwargs: dict
|
||||
couple argument name / default value
|
||||
"""
|
||||
self._args_default.update(kwargs)
|
||||
|
||||
@property
|
||||
def builder_argdict(self):
|
||||
"""
|
||||
|
@ -178,6 +194,10 @@ class LiteXArgumentParser(argparse.ArgumentParser):
|
|||
if cpu_cls is not None and hasattr(cpu_cls, "args_fill"):
|
||||
cpu_cls.args_fill(self)
|
||||
|
||||
# Injects arguments default values
|
||||
if len(self._args_default):
|
||||
argparse.ArgumentParser.set_defaults(self, **self._args_default)
|
||||
|
||||
# Parse args.
|
||||
self._args = argparse.ArgumentParser.parse_args(self, args, namespace)
|
||||
|
||||
|
|
Loading…
Reference in New Issue