console module

create_console_parser()[source]

Create CharGer’s commandline parser.

See CharGerConfig for the detailed specification of each parameter.

Return type

argparse.ArgumentParser

parse_console(args=None)[source]

Create a CharGerConfig object based on the command-line arguments or the given args.

Return type

charger.config.CharGerConfig

setup_logger()[source]

Set up stderr logging format.

The logging format and colors can be overridden by setting up the environment variables such as LOGURU_FORMAT. See Loguru documentation for details.

Return type

None

run()[source]

Entry point of the program.

The charger command calls this function.

Return type

None

argtype module

class PathType(exists=None, type=None)[source]

Parse file path arguments as a pathlib.Path object.

Type factory for ArgumentParser.add_argument() that validates the file path arguments. Adapted from https://stackoverflow.com/a/33181083

Parameters
  • exists (Optional[bool]) – The path must exist when True, and the path must not exist when False. Skip the check when None.

  • type (Union[None, str, Callable[[pathlib.Path], bool]]) – file will be checked by is_file(). dir will be checked by is_dir(). It also accepts a function that takes Path object and returns True for valid paths. Skip the check when None.

Examples

>>> parser = argparse.ArgumentParser()

Add an argument that must be an existing file, but can also be specified as a dash (-) in the command,

>>> parser.add_argument('existing_file', type=PathType(exists=True, type='file'))

Add an argument for a new path that must NOT exist, but the parent folder exists,

>>> from pathlib import Path
>>> CreatablePathType = PathType(exists=False, type=lambda p: p.parent.is_dir())
>>> parser.add_argument('non_existing_folder', type=CreatablePathType)
class ModuleScoreOverrideType(defaults)[source]

Integrate override arguments to new scores of all modules.

Examples

>>> default_scores = {'A': 5, 'B': -2}
>>> override_score = ModuleScoreOverrideType(default_scores)
>>> override_score('A=7 B=-4')
{'A': 7, 'B': -4}
Parameters

defaults (Dict[str, int]) –