Add support for setting default value to auto connected argparse arguments

This commit is contained in:
allegroai 2021-10-16 23:05:45 +03:00
parent 9085847c6d
commit 0bca84375b
2 changed files with 11 additions and 4 deletions

View File

@ -179,15 +179,16 @@ class _Arguments(object):
# Skip excluded arguments, Add prefix. # Skip excluded arguments, Add prefix.
if Session.check_min_api_version('2.9'): if Session.check_min_api_version('2.9'):
include_all = self._exclude_parser_args.get("*", True)
task_defaults = dict( task_defaults = dict(
[(self._prefix_args + k, v) for k, v in task_defaults.items() [(self._prefix_args + k, v) for k, v in task_defaults.items()
if self._exclude_parser_args.get(k, True)]) if self._exclude_parser_args.get(k, include_all)])
task_defaults_descriptions = dict( task_defaults_descriptions = dict(
[(self._prefix_args + k, v) for k, v in task_defaults_descriptions.items() [(self._prefix_args + k, v) for k, v in task_defaults_descriptions.items()
if self._exclude_parser_args.get(k, True)]) if self._exclude_parser_args.get(k, include_all)])
task_defaults_types = dict( task_defaults_types = dict(
[(self._prefix_args + k, v) for k, v in task_defaults_types.items() [(self._prefix_args + k, v) for k, v in task_defaults_types.items()
if self._exclude_parser_args.get(k, True)]) if self._exclude_parser_args.get(k, include_all)])
else: else:
task_defaults = dict( task_defaults = dict(
[(k, v) for k, v in task_defaults.items() if self._exclude_parser_args.get(k, True)]) [(k, v) for k, v in task_defaults.items() if self._exclude_parser_args.get(k, True)])

View File

@ -328,7 +328,9 @@ class Task(_Task):
- A dictionary - In addition to a boolean, you can use a dictionary for fined grained control of connected - A dictionary - In addition to a boolean, you can use a dictionary for fined grained control of connected
arguments. The dictionary keys are argparse variable names and the values are booleans. arguments. The dictionary keys are argparse variable names and the values are booleans.
The ``False`` value excludes the specified argument from the Task's parameter section. The ``False`` value excludes the specified argument from the Task's parameter section.
Keys missing from the dictionary default to ``True``, and an empty dictionary defaults to ``False``. Keys missing from the dictionary default to ``True``, you can change it to be ``False`` by adding
``*`` key as ``False`` to the dictionary.
An empty dictionary defaults to ``False``.
For example: For example:
@ -336,6 +338,10 @@ class Task(_Task):
auto_connect_arg_parser={'do_not_include_me': False, } auto_connect_arg_parser={'do_not_include_me': False, }
.. code-block:: py
auto_connect_arg_parser={"only_include_me": True, "*": False}
.. note:: .. note::
To manually connect an argparse, use :meth:`Task.connect`. To manually connect an argparse, use :meth:`Task.connect`.