From 80d767866a3fc39d8e983c480ecde44781f0b532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20R=C3=B6bke?= Date: Fri, 26 Jun 2020 16:42:10 +0200 Subject: [PATCH] Format --- tdvisu/construct_dpdb_visu.py | 10 +++++++--- tdvisu/dijkstra.py | 2 +- tdvisu/reader.py | 10 +++++----- tdvisu/utilities.py | 35 +++++++++++++++++++++++++---------- tdvisu/visualization.py | 3 +-- 5 files changed, 39 insertions(+), 21 deletions(-) diff --git a/tdvisu/construct_dpdb_visu.py b/tdvisu/construct_dpdb_visu.py index c160a6e..26296b9 100644 --- a/tdvisu/construct_dpdb_visu.py +++ b/tdvisu/construct_dpdb_visu.py @@ -77,7 +77,7 @@ def good_db_status() -> tuple: pg.extensions.TRANSACTION_STATUS_INTRANS) -def read_cfg(cfg_file, section:str, prefer_cfg:bool=False) -> dict: +def read_cfg(cfg_file, section: str, prefer_cfg: bool = False) -> dict: """Read the config file and return the result of one section.""" try: file_content = read_yml_or_cfg(cfg_file, prefer_cfg=prefer_cfg) @@ -91,7 +91,8 @@ def read_cfg(cfg_file, section:str, prefer_cfg:bool=False) -> dict: return content -def db_config(filename:str='database.ini', section:str='postgresql') -> dict: +def db_config(filename: str = 'database.ini', + section: str = 'postgresql') -> dict: """Return the database config as JSON""" LOGGER.info("Read db_config['%s'] from '%s'", section, filename) cfg = read_cfg(filename, section) @@ -459,7 +460,10 @@ def connect() -> pg.extensions.connection: return conn -def create_json(problem: int, tw_file=None, intermed_nodes:bool=False) -> dict: +def create_json( + problem: int, + tw_file=None, + intermed_nodes: bool = False) -> dict: """Create the JSON for the specified problem instance.""" try: diff --git a/tdvisu/dijkstra.py b/tdvisu/dijkstra.py index b5bcefe..e5e8537 100644 --- a/tdvisu/dijkstra.py +++ b/tdvisu/dijkstra.py @@ -187,7 +187,7 @@ class DijkstraNoPath(RuntimeError): """Raised when there was no path found during Dijkstra algorithm""" -def _weight_function(weight, multigraph:bool=False): +def _weight_function(weight, multigraph: bool = False): """Returns a function that returns the weight of an edge. The returned function is specifically suitable for input to diff --git a/tdvisu/reader.py b/tdvisu/reader.py index 78e4c50..e0dd279 100644 --- a/tdvisu/reader.py +++ b/tdvisu/reader.py @@ -51,16 +51,16 @@ def main() class Reader(): """Base class for string-readers.""" @classmethod - def from_filename(cls, fname)-> Reader: + def from_filename(cls, fname) -> Reader: with open(fname, "r") as file: return cls.from_string(file.read()) @classmethod - def from_filewrapper(cls, fwrapper)-> Reader: + def from_filewrapper(cls, fwrapper) -> Reader: return cls.from_string(fwrapper.read()) @classmethod - def from_stream(cls, stream)-> Reader: + def from_stream(cls, stream) -> Reader: return cls.from_string(stream.read().decode()) @classmethod @@ -97,13 +97,13 @@ def store_problem_vars(self): pass @staticmethod - def is_comment(line:str) -> bool: + def is_comment(line: str) -> bool: return line.startswith("c ") or line == "c" def body(self, lines): pass - def preamble(self, lines:Iterable[str]) -> int: + def preamble(self, lines: Iterable[str]) -> int: """ Searches for the preamble line in lines and saves: problem_solution_type, format, _problem_vars diff --git a/tdvisu/utilities.py b/tdvisu/utilities.py index 1cbfbce..10f0cd0 100644 --- a/tdvisu/utilities.py +++ b/tdvisu/utilities.py @@ -188,7 +188,8 @@ def logging_cfg(filename: str, prefer_cfg: bool = False, LOGGER.error(config_err, file.resolve(), exc_info=True) -def convert_to_adj(edgelist: Iterable[Tuple[int,int]], directed:bool=False) -> dict: +def convert_to_adj( + edgelist: Iterable[Tuple[int, int]], directed: bool = False) -> dict: """ Helper function to convert the edgelist into the adj-format from NetworkX. @@ -221,7 +222,11 @@ def convert_to_adj(edgelist: Iterable[Tuple[int,int]], directed:bool=False) -> d return adj -def add_edge_to(edges:set, adjacency_dict:dict, vertex1: Any, vertex2: Any) -> None: +def add_edge_to( + edges: set, + adjacency_dict: dict, + vertex1: Any, + vertex2: Any) -> None: """ Adding (undirected) edge from 'vertex1' to 'vertex2' to the edges and adjacency-list. @@ -280,13 +285,17 @@ def gen_arg(arg_or_iter: Any) -> Generator: yield item -def base_style(graph, node:str, color:str='white', penwidth:float=1.0) -> None: +def base_style( + graph, + node: str, + color: str = 'white', + penwidth: float = 1.0) -> None: """Style the node with default fillcolor and penwidth.""" graph.node(node, fillcolor=color, penwidth=str(penwidth)) -def emphasise_node(graph, node:str, color:str='yellow', - penwidth:float=2.5) -> None: +def emphasise_node(graph, node: str, color: str = 'yellow', + penwidth: float = 2.5) -> None: """Emphasise node with a different fillcolor (default:'yellow') and penwidth (default:2.5). """ @@ -296,18 +305,24 @@ def emphasise_node(graph, node:str, color:str='yellow', graph.node(node, penwidth=str(penwidth)) -def style_hide_node(graph, node:str) -> None: +def style_hide_node(graph, node: str) -> None: """Make the node invisible during drawing.""" graph.node(node, style='invis') -def style_hide_edge(graph, source:str, target:str) -> None: +def style_hide_edge(graph, source: str, target: str) -> None: """Make the edge source->target invisible during drawing.""" graph.edge(source, target, style='invis') -def bag_node(head, tail, anchor:str='anchor', headcolor:str='white', - tableborder:int=0, cellborder:int=0, cellspacing:int=0) -> str: +def bag_node( + head, + tail, + anchor: str = 'anchor', + headcolor: str = 'white', + tableborder: int = 0, + cellborder: int = 0, + cellspacing: int = 0) -> str: """HTML format with 'head' as the first label, then appending further labels. @@ -333,7 +348,7 @@ def bag_node(head, tail, anchor:str='anchor', headcolor:str='white', def solution_node( - solution_table:Iterable[List[str]], + solution_table: Iterable[List[str]], toplabel: str = '', bottomlabel: str = '', transpose: bool = False, diff --git a/tdvisu/visualization.py b/tdvisu/visualization.py index 6e25854..248e8ee 100644 --- a/tdvisu/visualization.py +++ b/tdvisu/visualization.py @@ -91,7 +91,6 @@ def __init__(self, infile: StrOrIo, outfolder: Path): self.tree_dec_digraph = None LOGGER.debug("Initialized: %s", self) - def inspect_json(self, infile: StrOrIo) -> VisualizationData: """Read and preprocess the needed data from the infile into VisualizationData.""" LOGGER.debug("Reading from: %s", infile) @@ -408,7 +407,7 @@ def general_graph( """ _filename = self.outfolder / file_basename LOGGER.info("Generating general-graph for '%s'", file_basename) - vartag_n : str = var_name + '%d' + vartag_n: str = var_name + '%d' # sfdp http://yifanhu.net/SOFTWARE/SFDP/index.html default_engine = 'sfdp'