toml_formatter package

Package to run the Destination Earth on Demand Extremes system.

class GeneralConstants[source]

Bases: object

General package-related constants.

PACKAGE_DIRECTORY = PosixPath('/home/runner/work/toml-formatter/toml-formatter/toml_formatter')
PACKAGE_NAME = 'toml_formatter'
VERSION = '0.1.0'

Submodules

toml_formatter.argparse_wrapper module

Wrappers for argparse functionality.

get_parsed_args(program_name='toml_formatter', argv=None)[source]

Get parsed command line arguments.

Parameters:
  • program_name (str) – The name of the program.

  • argv (list) – A list of passed command line args.

Returns:

Parsed command line arguments.

Return type:

argparse.Namespace

toml_formatter.commands_functions module

Implement the package’s commands.

check_toml_files_format(args, config)[source]

Implement the check command.

show_configs(args, config)[source]

Implement the ‘show_config’ command.

Parameters:
  • args (argparse.Namespace) – Parsed command line arguments.

  • config (.formatter_options.FormatterOptions) – Parsed config file contents.

toml_formatter.formatter module

Code related to TOML formatting.

class FormattedToml(raw_data: Sequence[str], formatter_options: FormatterOptions = FormatterOptions(line_length=90, indentation=2, section_order_overrides=(), loglevel='INFO'))[source]

Bases: object

Class to help format the contents of a TOML file.

dumps()[source]

Return a string representation of the formatted TOML.

classmethod from_file(path: Path | str, **kwargs)[source]

Return a class instance with info read from file located at path.

classmethod from_string(toml_string: str, **kwargs)[source]

Return a class instance with info retrieved from toml_string.

property indentation: int

Return the indentation applied for each scope level change.

property sections: Tuple[_FormattedTomlFileSection]

Return the sections present in the file.

toml_formatter.formatter_options module

Registration and validation of options passed to the formatter.

pydantic model FormatterOptions[source]

Bases: BaseModel

Model for the formatter’s configuration options.

Show JSON schema
{
   "title": "FormatterOptions",
   "description": "Model for the formatter's configuration options.",
   "type": "object",
   "properties": {
      "line_length": {
         "default": 90,
         "exclusiveMinimum": 0,
         "title": "Line Length",
         "type": "integer"
      },
      "indentation": {
         "default": 2,
         "minimum": 0,
         "title": "Indentation",
         "type": "integer"
      },
      "section_order_overrides": {
         "default": [],
         "items": {
            "type": "string"
         },
         "title": "Section Order Overrides",
         "type": "array"
      },
      "loglevel": {
         "default": "INFO",
         "enum": [
            "INFO",
            "DEBUG",
            "WARNING",
            "ERROR",
            "CRITICAL"
         ],
         "title": "Loglevel",
         "type": "string"
      }
   }
}

Fields:
field indentation: int = 2
Constraints:
  • ge = 0

field line_length: int = 90
Constraints:
  • gt = 0

field loglevel: Literal['INFO', 'DEBUG', 'WARNING', 'ERROR', 'CRITICAL'] = 'INFO'
field section_order_overrides: tuple[str, ...] = ()
classmethod from_toml_file(path: str | Path)[source]

Parse a config file and return an instance of the class.

toml_formatter.logs module

Logging-related classes, functions and definitions.

class LogDefaults[source]

Bases: object

Defaults used for the logging system.

DIRECTORY = PosixPath('/home/runner/.logs/toml_formatter')
LEVEL = 'INFO'
LOGLEVEL_ENVVAR = 'TOML_FORMATTER_LOGLEVEL'
RETENTION_TIME = '1 week'
SINKS = {'console': <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>, 'logfile': PosixPath('/home/runner/.logs/toml_formatter/toml_formatter_{time}.log')}
class LogFormatter(datetime: str = '<green>{time:YYYY-MM-DD HH:mm:ss}</green>', level: str = '<level>{level: <8}</level>', code_location: str = '<cyan>@{name}</cyan>:<cyan>{function}</cyan> <cyan><{file.path}</cyan>:<cyan>{line}>:</cyan>', message: str = '<level>{message}</level>')[source]

Bases: object

Helper class to setup logging without poluting the module’s main scope.

code_location: str = '<cyan>@{name}</cyan>:<cyan>{function}</cyan> <cyan><{file.path}</cyan>:<cyan>{line}>:</cyan>'
datetime: str = '<green>{time:YYYY-MM-DD HH:mm:ss}</green>'
format_string(loglevel: str)[source]

Return the appropriate fmt string according to log level and fmt opts.

level: str = '<level>{level: <8}</level>'
message: str = '<level>{message}</level>'
class LoggerHandlers(default_level: str = 'INFO', **sinks)[source]

Bases: Sequence

Helper class to configure logger handlers when using loguru.logger.configure.

add(name, sink, **configs)[source]

Add handler to instance.

log_elapsed_time(**kwargs)[source]

Return a decorator that logs beginning, exit and elapsed time of function.