Function init_config

Synopsis

def init_config(default_config, cli_args=None)

Description

No description yet.

Mentioned in

Source

Lines 14-59 in anyfig/anyfig_setup.py.

def init_config(default_config, cli_args=None):
  assert default_config is not None

  err_msg = (
    "Expected 'default_config' to be a class definition but most likely got an object. E.g. expected ConfigClass but "
    "got ConfigClass() with parentheses.")
  assert type(default_config) == type(type), err_msg

  err_msg = f"Expected 'default_config' to be an anyfig config class, was {default_config}"
  assert figutils.is_config_class(default_config), err_msg

  if cli_args is not None:
    err_msg = f"Expected 'cli_args' to be a dict like object, was {type(cli_args)}"
    assert isinstance(cli_args, Mapping), err_msg

  # Parse command line arguments
  if cli_args is None:
    cli_args = parse_cli_args()

  # Create config
  config_str = cli_args.pop('config', default_config.__name__)
  config = create_config(config_str)
  fields.validate_fields(config)

  # Print config help
  if 'help' in cli_args or 'h' in cli_args:
    print(config.cli_help())
    sys.exit(0)

  # Overwrite parameters via optional input flags
  config = overwrite(config, cli_args)

  # Perform deep post init after input flags
  figutils.post_init(config)

  # Unwrap the field values
  fields.resolve_fields(config)

  # Freezes config
  config.frozen(freeze=True)

  # Registers config with anyfig
  figutils.register_globally(config)
  return config







Add Discussion as Guest

Log in