nugets.misc

Miscellaneous utilities

Functions

compact_wandb_sweep_config(config_dict)

configure_logging(packages, loglevel[, logfile])

Configures the logging for the program

create_argument_parser(**argparse_kwargs)

Decorator that potentially creates an argument parser and passes it down

dict_to_bytes(d)

Takes a dict where keys are strings, and values are jsonable, and outputs an order-independent set of bytes for hashing purposes

import_submodules(package[, recursive])

Import all submodules of a module, recursively, including subpackages

take_argument_annotation_from(this)

Take the argument annotations from another function

Classes

AddsUpdateAction(*args, inner_action_class, ...)

CreateArgumentParserReturnSignature(*args, ...)

CustomArgumentParser(*args, **kwargs)

Known bugs:

CustomHelpAction(option_strings[, dest, ...])

NamespacedArgumentGroup(*args[, prefix, ...])

Group arguments in an argument parser in a way that

Nestedspace(**kwargs)

Exceptions

RetryException

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.Nestedspace(**kwargs)[source]
class nugets.misc.CustomHelpAction(option_strings, dest='==SUPPRESS==', default='==SUPPRESS==', help=None)[source]
exception nugets.misc.RetryException[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

error(message: string)[source]

Prints a usage message incorporating the message to stderr and exits.

If you override this in a subclass, it should not return – it should either exit or raise an exception.

run_updates(namespace)[source]

Runs all pending updates. :returns: True if any update was run, False otherwise

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)

class nugets.misc.CreateArgumentParserReturnSignature(*args, **kwargs)[source]
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.