Clean up and fix whitespace
This commit is contained in:
parent
46b913941d
commit
189282a3f6
6 changed files with 21 additions and 20 deletions
|
|
@ -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}")
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
|
||||
|
|
|
|||
|
|
@ -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__)
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue