Add cron.py, a pretty important (and easy) one.
[python_utils.git] / config.py
index 588b7e072006d6d27cbf115e7220f9e40b6cc706..22660cc41c46fc92dba8c32e0caf61c4d5d207c5 100644 (file)
--- a/config.py
+++ b/config.py
@@ -84,10 +84,24 @@ program_name: str = os.path.basename(sys.argv[0])
 original_argv: List[str] = [arg for arg in sys.argv]
 
 
+class OptionalRawFormatter(argparse.HelpFormatter):
+    """This formatter has the same bahavior as the normal argparse text
+    formatter except when the help text of an argument begins with
+    "RAW|".  In that case, the line breaks are preserved and the text
+    is not wrapped.
+
+    """
+
+    def _split_lines(self, text, width):
+        if text.startswith('RAW|'):
+            return text[4:].splitlines()
+        return argparse.HelpFormatter._split_lines(self, text, width)
+
+
 # A global parser that we will collect arguments into.
 args = argparse.ArgumentParser(
     description=None,
-    formatter_class=argparse.ArgumentDefaultsHelpFormatter,
+    formatter_class=OptionalRawFormatter,
     fromfile_prefix_chars="@",
     epilog=f'{program_name} uses config.py ({__file__}) for global, cross-module configuration setup and parsing.',
 )
@@ -191,9 +205,7 @@ def augment_sys_argv_from_environment_variables():
                 if env in os.environ:
                     if not is_flag_already_in_argv(var):
                         value = os.environ[env]
-                        saved_messages.append(
-                            f'Initialized from environment: {var} = {value}'
-                        )
+                        saved_messages.append(f'Initialized from environment: {var} = {value}')
                         from string_utils import to_bool
 
                         if len(chunks) == 1 and to_bool(value):
@@ -282,9 +294,7 @@ def parse(entry_module: Optional[str]) -> Dict[str, Any]:
             raise Exception(
                 f'Encountered unrecognized config argument(s) {unknown} with --config_rejects_unrecognized_arguments enabled; halting.'
             )
-        saved_messages.append(
-            f'Config encountered unrecognized commandline arguments: {unknown}'
-        )
+        saved_messages.append(f'Config encountered unrecognized commandline arguments: {unknown}')
     sys.argv = sys.argv[:1] + unknown
 
     # Check for savefile and populate it if requested.