asteroid.utils.parser_utils module¶
-
asteroid.utils.parser_utils.
isfloat
(value)[source]¶ Computes whether value can be cast to a float.
Parameters: value (str) – Value to check. Returns: bool – Whether value can be cast to a float.
-
asteroid.utils.parser_utils.
isint
(value)[source]¶ Computes whether value can be cast to an int
Parameters: value (str) – Value to check. Returns: bool – Whether value can be cast to an int.
-
asteroid.utils.parser_utils.
parse_args_as_dict
(parser, return_plain_args=False, args=None)[source]¶ Get a dict of dicts out of process parser.parse_args()
Top-level keys corresponding to groups and bottom-level keys corresponding to arguments. Under ‘main_args’, the arguments which don’t belong to a argparse group (i.e main arguments defined before parsing from a dict) can be found.
Parameters: - parser (argparse.ArgumentParser) – ArgumentParser instance containing groups. Output of prepare_parser_from_dict.
- return_plain_args (bool) – Whether to return the output or parser.parse_args().
- args (list) – List of arguments as read from the command line. Used for unit testing.
Returns: dict – Dictionary of dictionaries containing the arguments. Optionally the direct output parser.parse_args().
-
asteroid.utils.parser_utils.
prepare_parser_from_dict
(dic, parser=None)[source]¶ Prepare an argparser from a dictionary.
Parameters: - dic (dict) – Two-level config dictionary with unique bottom-level keys.
- parser (argparse.ArgumentParser, optional) – If a parser already exists, add the keys from the dictionary on the top of it.
Returns: argparse.ArgumentParser – Parser instance with groups corresponding to the first level keys and arguments corresponding to the second level keys with default values given by the values.
-
asteroid.utils.parser_utils.
str2bool
(value)[source]¶ Type to convert strings to Boolean (returns input if not boolean)