Utility Functions and the Parser¶
Groups¶
Parser¶
-
adles.parser.
check_syntax
(specfile_path: str, spec_type: str = 'exercise') → Optional[dict][source]¶ Checks the syntax of a specification file.
Parameters: - specfile_path – Path to the YAML specification file
- spec_type – Type of specification file
(exercise | package | infra) :return: The specification
-
adles.parser.
parse_yaml
(filename: str) → Optional[dict][source]¶ Parses a YAML file and returns a nested dictionary containing its contents.
Parameters: filename – Name of YAML file to parse Returns: Parsed file contents
-
adles.parser.
parse_yaml_file
(file: _io.TextIOWrapper) → Optional[dict][source]¶ Parses a YAML file and returns a nested dictionary containing its contents.
Parameters: file – Handle of file to parse Returns: Parsed file contents
-
adles.parser.
verify_exercise_syntax
(spec: dict) → Tuple[int, int][source]¶ Verifies the syntax of an environment specification.
Parameters: spec – Dictionary of environment specification Returns: Number of errors, Number of warnings
Utils¶
-
class
adles.utils.
TqdmHandler
(level=0)[source]¶ -
emit
(record)[source]¶ Emit a record.
If a formatter is specified, it is used to format the record. The record is then written to the stream with a trailing newline. If exception information is present, it is formatted using traceback.print_exception and appended to the stream. If the stream has an ‘encoding’ attribute, it is used to determine how to do the output to the stream.
-
-
adles.utils.
handle_keyboard_interrupt
(func: Callable) → Callable[source]¶ Function decorator to handle keyboard interrupts in a consistent manner.
-
adles.utils.
pad
(value: int, length: int = 2) → str[source]¶ Adds leading and trailing zeros to value (“pads” the value).
>>> pad(5) 05 >>> pad(9, 3) 009
Parameters: - value – integer value to pad
- length – Length to pad to
Returns: string of padded value
-
adles.utils.
read_json
(filename: str) → Optional[dict][source]¶ Reads input from a JSON file and returns the contents.
Parameters: filename – Path to JSON file to read Returns: Contents of the JSON file
-
adles.utils.
setup_logging
(filename: str, colors: bool = True, console_verbose: bool = False, server: Tuple[str, int] = None, show_progress: bool = True)[source]¶ Configures the logging interface used by everything for output.
Parameters: - filename – Name of file that logs should be saved to
- colors – Color the terminal output
- console_verbose – Print DEBUG logs to terminal
- server – SysLog server to forward logs to
- show_progress – Show live status as operations progress
-
adles.utils.
sizeof_fmt
(num: float) → str[source]¶ Generates the human-readable version of a file size.
>>> sizeof_fmt(512) 512bytes >>> sizeof_fmt(2048) 2KB
Parameters: num – Robot-readable file size in bytes Returns: Human-readable file size