Function get_allowed_cli_args

Synopsis

def get_allowed_cli_args(config_obj)

Description

Returns the attribute names that can be be overwritten from command line input. Raises AttributeError if an attribute doesn't exist

Source

Lines 136-158 in anyfig/figutils.py.

def get_allowed_cli_args(config_obj):
  ''' Returns the attribute names that can be be overwritten from command line input.
  Raises AttributeError if an attribute doesn't exist '''
  allowed_items = config_obj.allowed_cli_args()
  if allowed_items is None:
    allowed_items = []
  if isinstance(allowed_items, str):
    allowed_items = [allowed_items]
  err_msg = (
    f"Expected return type 'String, None or Iterable' for {type(config_obj).__name__}'s allowed_cli_args method, "
    f"was {allowed_items} with type {type(allowed_items)}")
  assert isinstance(allowed_items, Iterable), err_msg

  attributes = config_obj.get_parameters()
  for item in allowed_items:
    if item not in attributes:
      err_msg = (
        f"'{type(config_obj).__name__}' has no attribute '{item}' and should not be marked as an allowed command line "
        "input argument")
      raise AttributeError(err_msg)
  return allowed_items







Add Discussion as Guest

Log in