agatha.util.proto_util module

This module contains the functions necessary to load and manipulate proto objects. Key components of this module include the load_proto function, that wraps multiple proto parsers, as well as parse_args_into_proto, which loads and augments a proto from the command line.

agatha.util.proto_util.get_field(proto_obj, field)

Looks up a message or field from the supplied proto in the same way that getattr might. However, this function is smart enough to handle nested messages in terms of “a.b.c”

Return type

Any

agatha.util.proto_util.get_full_field_names(proto_obj)

Lists all field names in all nested messages in the given proto. For instance: : message Foo { : optional string str_1 = 1; : optional string str_2 = 2; : } : message Bar { : optional Foo foo = 1; : optional int32 num = 2; : } get_full_field_names(Foo()) contains [str_1, str_2] get_full_field_names(Bar()) contains [num, foo.str_1, foo.str_2]

Return type

List[str]

agatha.util.proto_util.load_json_as_proto(path, proto_obj)

Interprets path as a plaintext json file. Reads the data into proto_obj and returns a reference with the result.

Return type

~ProtoObj

agatha.util.proto_util.load_proto(path, proto_obj)

Attempts to parse the provided file using all available parsers. Raises exception if unavailable.

Return type

~ProtoObj

agatha.util.proto_util.load_serialized_pb_as_proto(path, proto_obj)

Interprets the file path as a serialized proto. Reads data into proto_obj. Returns a reference to the same proto_obj

Return type

~ProtoObj

agatha.util.proto_util.load_text_as_proto(path, proto_obj)

Interprets path as a plaintext proto file. Reads the data into proto_obj and returns a reference with the result.

Return type

~ProtoObj

agatha.util.proto_util.parse_args_to_config_proto(config_proto)

Combines the above steps to replace parse_args.

Return type

None

agatha.util.proto_util.set_field(proto_obj, field, val)
Return type

None

agatha.util.proto_util.setup_parser_with_proto(config_proto)

This class parses command line arguments into the config_proto. The idea is to have sensible defaults at all levels. Default Levels:

  • Written in proto definition

  • Written in config file

  • Written on command line

Return type

ArgumentParser

agatha.util.proto_util.transfer_args_to_proto(args, config_proto)

Writes the fields from the args to the config proto.

Return type

None