Function extract_config_obj_comments

Synopsis

def extract_config_obj_comments(config_obj)

Description

Extracts comments for a config object and any config-class children objects

Source

Lines 66-91 in anyfig/print_utils.py.

def extract_config_obj_comments(config_obj):
  ''' Extracts comments for a config object and any config-class children objects '''
  config_classes = figutils.get_config_classes().values()
  comments = _extract_comments(type(config_obj))

  # Remove the keys that aren't allowed from command line input
  allowed_cli_args = figutils.get_allowed_cli_args(config_obj)
  comments = {k: v for k, v in comments.items() if k in allowed_cli_args}

  flat_comments = {}
  for attribute_name, comment in comments.items():
    flat_comments[attribute_name] = comment

    # Check if config class has config-class children
    attribute_value = getattr(config_obj, attribute_name)
    if type(attribute_value) in config_classes:
      child_comments = extract_config_obj_comments(attribute_value)

      # Add child comments
      for child_attribute_name, child_comment in child_comments.items():
        nested_name = f'{attribute_name}.{child_attribute_name}'
        flat_comments[nested_name] = child_comment

  return flat_comments







Add Discussion as Guest

Log in