nugets.misc
Miscellaneous utilities
Functions
|
|
|
Configures the logging for the program |
|
Decorator that potentially creates an argument parser and passes it down |
Takes a dict where keys are strings, and values are jsonable, and outputs an order-independent set of bytes for hashing purposes |
|
|
Import all submodules of a module, recursively, including subpackages |
Take the argument annotations from another function |
Classes
|
|
|
|
|
Known bugs: |
|
|
|
Group arguments in an argument parser in a way that |
|
Exceptions
- nugets.misc.take_argument_annotation_from(this: Callable[[P], Any]) Callable[[Callable[[...], T]], Callable[[P], T]][source]
Take the argument annotations from another function
Decorator stating that the function it decorates should have the same annotations as the function passed as argument.
Inspired from https://stackoverflow.com/a/71262408/4948719
- class nugets.misc.CustomHelpAction(option_strings, dest='==SUPPRESS==', default='==SUPPRESS==', help=None)[source]
- class nugets.misc.CustomArgumentParser(*args, **kwargs)[source]
- Known bugs:
if using –help, and some required arguments are missing at a higher level, not all updates will be processed, so not all possible arguments will be shown
Solution to that would be to prevent exiting on unseen argument if there are still updates to be taken, but that is for sure a pain
- class nugets.misc.AddsUpdateAction(*args, inner_action_class, update, namespace_scope=None, **kwargs)[source]
- class nugets.misc.NamespacedArgumentGroup(*args, prefix=None, dest_group=None, **kwargs)[source]
Group arguments in an argument parser in a way that
every element from the group is saved into a custom namespace
groups can be nested infinitely (yay)
- nugets.misc.create_argument_parser(**argparse_kwargs) Callable[[Callable[[ArgumentParser], None]], CreateArgumentParserReturnSignature][source]
Decorator that potentially creates an argument parser and passes it down
This is a helper function that allows to have a function that either
- populates an already existing parser
(if passed as argument, generally for use with subparsers)
creates an all new parser
It decorates a function that takes a single argument, an ArgumentParser, and populates it.
usage:
# @create_argument_parser # accepts all the arguments of ArgumentParser. # They will be passed to the ArgumentParser constructor # if a new parser is created @create_argument_parser(description="This is the description") def my_argument_parser(parser: ArgumentParser): parser.add_argument("--my-arg", help="This is the help") specific_parser = my_argument_parser() # or parser = ArgumentParser() subparsers = parser.add_subparsers() my_argument_parser(subparsers.add_parser("my_subcommand"))
Note
The input function should only take a single argument parser, and does not need to return anything. The output function will return the parser.
- nugets.misc.dict_to_bytes(d: dict[str, Any])[source]
Takes a dict where keys are strings, and values are jsonable, and outputs an order-independent set of bytes for hashing purposes
- nugets.misc.import_submodules(package, recursive=True)[source]
Import all submodules of a module, recursively, including subpackages
- nugets.misc.configure_logging(packages, loglevel, logfile=None)[source]
Configures the logging for the program
Enables logging (either to stderr or to a file) for the following packages:
autocommit
basic_rag
mistral_tools
with the specified log level
- Parameters:
loglevel (int) – The log level
logfile (Path, optional) – The file to log to. Defaults to None.