geowatch.utils.lightning_ext.argparse_ext module

Do a better job with default argparse

TODO: work on this

import liberator

lib = liberator.Liberator() lib.add_dynamic(get_init_arguments_and_types) lib.add_dynamic(str_to_bool) lib.add_dynamic(str_to_bool_or_int) lib.add_dynamic(str_to_bool_or_str) lib.add_dynamic(_int_or_float_type) lib.add_dynamic(_gpus_allowed_type) lib.expand([‘pytorch_lightning’]) print(lib.current_sourcecode())

geowatch.utils.lightning_ext.argparse_ext.get_init_arguments_and_types(cls)[source]

Scans the class signature and returns argument names, types and default values.

Returns:

(argument name, set with argument types, argument default value).

Return type:

List with tuples of 3 values

geowatch.utils.lightning_ext.argparse_ext.str_to_bool_or_str(val: str)[source]
Possibly convert a string representation of truth to bool. Returns the input otherwise. Based on the python

implementation distutils.utils.strtobool.

True values are ‘y’, ‘yes’, ‘t’, ‘true’, ‘on’, and ‘1’; false values are ‘n’, ‘no’, ‘f’, ‘false’, ‘off’, and ‘0’.

geowatch.utils.lightning_ext.argparse_ext.str_to_bool_or_int(val: str)[source]

Convert a string representation to truth of bool if possible, or otherwise try to convert it to an int.

>>> str_to_bool_or_int("FALSE")
False
>>> str_to_bool_or_int("1")
True
>>> str_to_bool_or_int("2")
2
>>> str_to_bool_or_int("abc")
'abc'
geowatch.utils.lightning_ext.argparse_ext.str_to_bool(val: str) bool[source]

Convert a string representation of truth to bool.

True values are ‘y’, ‘yes’, ‘t’, ‘true’, ‘on’, and ‘1’; false values are ‘n’, ‘no’, ‘f’, ‘false’, ‘off’, and ‘0’.

Raises:
ValueError:

If val isn’t in one of the aforementioned true or false values.

>>> str_to_bool('YES')
True
>>> str_to_bool('FALSE')
False
geowatch.utils.lightning_ext.argparse_ext.parse_docstring_args(cls)[source]
geowatch.utils.lightning_ext.argparse_ext.add_arginfos_to_parser(parent_parser, arg_infos)[source]
geowatch.utils.lightning_ext.argparse_ext.add_argparse_args(cls, parent_parser)[source]