Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
VaeterchenFrost committed Jun 26, 2020
1 parent 8442c63 commit 80d7678
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
10 changes: 7 additions & 3 deletions tdvisu/construct_dpdb_visu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tdvisu/dijkstra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions tdvisu/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
35 changes: 25 additions & 10 deletions tdvisu/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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).
"""
Expand All @@ -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.
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions tdvisu/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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'

Expand Down

0 comments on commit 80d7678

Please sign in to comment.