diff --git a/evering/__main__.py b/evering/__main__.py index 9044ccf..01b6875 100644 --- a/evering/__main__.py +++ b/evering/__main__.py @@ -2,12 +2,13 @@ import argparse import logging from pathlib import Path from typing import Any + from .config import * +from .explore import * from .known_files import * from .process import * -from .util import * -from .explore import * from .prompt import * +from .util import * #logging.basicConfig(level=logging.DEBUG, style="{", format="{levelname:>7}: {message}") logging.basicConfig(level=logging.INFO, style="{", format="{levelname:>7}: {message}") diff --git a/evering/eval.py b/evering/eval.py index 402d757..26e8fa1 100644 --- a/evering/eval.py +++ b/evering/eval.py @@ -5,7 +5,7 @@ managing local variables. import copy import types -from typing import Dict, Any +from typing import Any, Dict __all__ = ["copy_local_variables"] diff --git a/evering/explore.py b/evering/explore.py index 3a6b434..931377e 100644 --- a/evering/explore.py +++ b/evering/explore.py @@ -1,10 +1,10 @@ +import logging from dataclasses import dataclass from pathlib import Path from typing import Dict, List, Optional -import logging -from .util import * from .colors import * +from .util import * __all__ = ["FileInfo", "find_config_files"] logger = logging.getLogger(__name__) diff --git a/evering/parser.py b/evering/parser.py index 89296c9..5b9fb1e 100644 --- a/evering/parser.py +++ b/evering/parser.py @@ -53,7 +53,7 @@ class Parser: """ May raise: ParseException """ - + self.statement_prefix = statement_prefix self.expression_prefix = expression_prefix self.expression_suffix = expression_suffix @@ -97,7 +97,7 @@ class Line(ABC): pass return ActualLine(parser, text, line_number) - + def __init__(self, parser: Parser, line_number: int) -> None: self.parser = parser self.line_number = line_number @@ -112,7 +112,7 @@ class Line(ABC): def _parse_statement_noarg(self, text: str, statement_name: str) -> bool: return text.strip() == f"{self.parser.statement_prefix} {statement_name}" - + class ActualLine(Line): def __init__(self, parser: Parser, text: str, line_number: int) -> None: """ @@ -128,7 +128,7 @@ class ActualLine(Line): argument is the text contained in the chunk and the second argument a boolean that indicates whether this chunk is a python expression (or just plain text). - + Because it simplifies the program logic, a chunk's text may also be the empty string. @@ -173,7 +173,7 @@ class ActualLine(Line): """ May raise: ExecuteException """ - + if not chunk[1]: return chunk[0] @@ -232,7 +232,7 @@ class Block: """ May raise: ParseException """ - + self._elements: List[Union[ActualLine, IfBlock]] = [] while lines_queue: @@ -308,7 +308,7 @@ class IfBlock(Block): if not isinstance(lines_queue[-1], EndifStatement): raise ParseException.on_line(lines_queue[-1], "Expected 'end' statement") lines_queue.pop() - + def evaluate(self, local_vars: Dict[str, Any]) -> List[str]: for entry in self._sections: if entry[1] is None or safer_eval(entry[1], local_vars): diff --git a/evering/process.py b/evering/process.py index 52b77cd..514ae3f 100644 --- a/evering/process.py +++ b/evering/process.py @@ -37,7 +37,7 @@ class Processor: raise LessCatastrophicError( style_error("Could not load file ") + style_path(path) + f": {e}") - + header, lines = split_header_and_rest(text) try: @@ -46,7 +46,7 @@ class Processor: raise LessCatastrophicError( style_error("Could not parse header of file ") + style_path(path) + f": {e}") - + self._process_parseable(lines, config) def _process_file_with_header(self, path: Path, header_path: Path, config: Config) -> None: diff --git a/evering/util.py b/evering/util.py index dbf2283..1602990 100644 --- a/evering/util.py +++ b/evering/util.py @@ -16,10 +16,10 @@ def copy_local_variables(local: Dict[str, Any]) -> Dict[str, Any]: Attempts to deep-copy a set of local variables, but keeping modules at the top level alone, since they don't tend to deepcopy well. - + May raise: Not sure at the moment """ - + local_copy = {} for key, value in local.items(): @@ -32,12 +32,12 @@ def copy_local_variables(local: Dict[str, Any]) -> Dict[str, Any]: class ExecuteException(Exception): pass - + def safer_exec(code: str, local_vars: Dict[str, Any]) -> None: """ May raise: ExecuteException """ - + try: exec(code, {}, local_vars) except Exception as e: @@ -47,7 +47,7 @@ def safer_eval(code: str, local_vars: Dict[str, Any]) -> Any: """ May raise: ExecuteException """ - + try: return eval(code, {}, local_vars) except Exception as e: @@ -60,7 +60,7 @@ def read_file(path: Path) -> str: """ May raise: ReadFileException """ - + try: with open(path.expanduser()) as f: return f.read()