processing¶
The dykes plumbing module.
This is all the things used internally to turn your definitions into something useful.
- class dykes.processing.FieldDefinition(name: str, type_def: type[T], default_value: T | dykes.internal.UnsetType)
- default_value: T | UnsetType
- name: str
- type_def: type[T]
- class dykes.processing.TypeMeta(real_type, is_optional, is_list, options)
- is_list: bool
Alias for field number 2
- is_optional: bool
Alias for field number 1
- options: dict[type, Any]
Alias for field number 3
- real_type: type
Alias for field number 0
- dykes.processing.build_parser(application_definition: type, prog: str | None = None) ArgumentParser
- dykes.processing.generate_parameter_definitions(field_definitions: list[FieldDefinition]) list[ParameterOptions]
Turn an iterable of FieldDefinitions into a list of ParameterOptions
This function is gnarly and is basically the place we catch all the weird edge cases we care about. Things like what to do if the user declares a bool or list.
Organized into sections (look for comments) based on the order of the parameters to ParameterOptions. Don’t worry if incompatible fields for an action are set. Handling the API barrier between ParameterOptions and argparse live in the build_parser function.
- dykes.processing.get_field_definitions(app_definition: Any) list[FieldDefinition]
Produce a list of fields for generating an argument parser.
Will eventually have a pluggable interface to support struct libraries outside the standard library.
- dykes.processing.get_metadata(type_def: type, field_name: str) TypeMeta
- dykes.processing.parse_args(application_struct: type[ArgsType], *, args: list | None = None, development_mode: bool = False, prog: str | None = None) ArgsType
Process arguments and conform them to an input type.
Supports dataclasses and NamedTuples.
Sample use:
from dataclasses import dataclass from pathlib import Path from dykes import parse_args, Count @dataclass class Application: input: Path dry_run: bool verbosity: dykes.Count args = parse_args(Application) print(args)
You can provide arguments just like parser.parse_args by supplying args=[…]
Example:
args = parse_args(Application, args=["some", "arguments"])
Activate development mode with development_mode=True:
Example:
args = parse_args(Application, development_mode=True)
Some error messages will change in development mode.