Remove unused parameter, fix default parameter

This commit is contained in:
Jason R. Jones 2020-07-10 07:42:32 -04:00
parent 8f5b1aaf16
commit 35330082ad
3 changed files with 14 additions and 12 deletions

View File

@ -4,7 +4,9 @@
from wireviz.DataClasses import Connector, Cable from wireviz.DataClasses import Connector, Cable
from graphviz import Graph from graphviz import Graph
from wireviz import wv_colors from wireviz import wv_colors
from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, nested, nested_html_table, flatten2d, index_if_list, html_line_breaks, graphviz_line_breaks, remove_line_breaks from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, nested, \
nested_html_table, flatten2d, index_if_list, html_line_breaks, \
graphviz_line_breaks, remove_line_breaks
from collections import Counter from collections import Counter
from typing import List from typing import List
@ -27,7 +29,8 @@ class Harness:
def connect(self, from_name, from_pin, via_name, via_pin, to_name, to_pin): def connect(self, from_name, from_pin, via_name, via_pin, to_name, to_pin):
for (name, pin) in zip([from_name, to_name], [from_pin, to_pin]): # check from and to connectors # check from and to connectors
for (name, pin) in zip([from_name, to_name], [from_pin, to_pin]):
if name is not None and name in self.connectors: if name is not None and name in self.connectors:
connector = self.connectors[name] connector = self.connectors[name]
if pin in connector.pinnumbers and pin in connector.pinout: if pin in connector.pinnumbers and pin in connector.pinout:
@ -278,7 +281,7 @@ class Harness:
data.seek(0) data.seek(0)
return data.read() return data.read()
def output(self, filename, directory='_output', view=False, cleanup=True, fmt='pdf', gen_bom=False): def output(self, filename, directory='_output', view=False, cleanup=True, fmt=('pdf', )):
# graphical output # graphical output
graph = self.create_graph() graph = self.create_graph()
for f in fmt: for f in fmt:

View File

@ -16,7 +16,7 @@ if demos:
for i in range(1,demos+1): for i in range(1,demos+1):
fn = '../../examples/demo{:02d}.yml'.format(i) fn = '../../examples/demo{:02d}.yml'.format(i)
print(fn) print(fn)
wireviz.parse_file(fn, generate_bom=True) wireviz.parse_file(fn)
if examples: if examples:
with open(os.path.abspath('../../examples/readme.md'), 'w') as file: with open(os.path.abspath('../../examples/readme.md'), 'w') as file:
@ -24,7 +24,7 @@ if examples:
for i in range(1,examples+1): for i in range(1,examples+1):
fn = '../../examples/ex{:02d}.yml'.format(i) fn = '../../examples/ex{:02d}.yml'.format(i)
print(fn) print(fn)
wireviz.parse_file(fn, generate_bom=True) wireviz.parse_file(fn)
file.write('## Example {:02d}\n'.format(i)) file.write('## Example {:02d}\n'.format(i))
file.write('![](ex{:02d}.png)\n\n'.format(i)) file.write('![](ex{:02d}.png)\n\n'.format(i))
@ -36,7 +36,7 @@ if tutorials:
for i in range(1,tutorials+1): for i in range(1,tutorials+1):
fn = '../../tutorial/tutorial{:02d}.yml'.format(i) fn = '../../tutorial/tutorial{:02d}.yml'.format(i)
print(fn) print(fn)
wireviz.parse_file(fn, generate_bom=True) wireviz.parse_file(fn)
with open(os.path.abspath('../../tutorial/tutorial{:02d}.md'.format(i)), 'r') as info: with open(os.path.abspath('../../tutorial/tutorial{:02d}.md'.format(i)), 'r') as info:
for line in info: for line in info:

View File

@ -15,13 +15,12 @@ if __name__ == '__main__':
from wireviz.Harness import Harness from wireviz.Harness import Harness
def parse(yaml_input, file_out=None, generate_bom=False, return_types: (None, str, Tuple[str]) = None): def parse(yaml_input, file_out=None, return_types: (None, str, Tuple[str]) = None):
""" """
Parses yaml input string and does the high-level harness conversion Parses yaml input string and does the high-level harness conversion
:param yaml_input: a string containing the yaml input data :param yaml_input: a string containing the yaml input data
:param file_out: :param file_out:
:param generate_bom:
:param return_types: if None, then returns None; if the value is a string, then a :param return_types: if None, then returns None; if the value is a string, then a
corresponding data format will be returned; if the value is a tuple of strings, corresponding data format will be returned; if the value is a tuple of strings,
then for every valid format in the `return_types` tuple, another return type then for every valid format in the `return_types` tuple, another return type
@ -194,7 +193,7 @@ def parse(yaml_input, file_out=None, generate_bom=False, return_types: (None, st
raise Exception('Wrong number of connection parameters') raise Exception('Wrong number of connection parameters')
if file_out is not None: if file_out is not None:
harness.output(filename=file_out, fmt=('png', 'svg'), gen_bom=generate_bom, view=False) harness.output(filename=file_out, fmt=('png', 'svg'), view=False)
if return_types is not None: if return_types is not None:
returns = [] returns = []
@ -211,7 +210,7 @@ def parse(yaml_input, file_out=None, generate_bom=False, return_types: (None, st
return tuple(returns) if len(returns) != 1 else returns[0] return tuple(returns) if len(returns) != 1 else returns[0]
def parse_file(yaml_file, file_out=None, generate_bom=False): def parse_file(yaml_file, file_out=None):
with open(yaml_file, 'r') as file: with open(yaml_file, 'r') as file:
yaml_input = file.read() yaml_input = file.read()
@ -220,7 +219,7 @@ def parse_file(yaml_file, file_out=None, generate_bom=False):
file_out = fn file_out = fn
file_out = os.path.abspath(file_out) file_out = os.path.abspath(file_out)
parse(yaml_input, file_out=file_out, generate_bom=generate_bom) parse(yaml_input, file_out=file_out)
def parse_cmdline(): def parse_cmdline():
@ -261,7 +260,7 @@ def main():
file_out = args.output_file file_out = args.output_file
file_out = os.path.abspath(file_out) file_out = os.path.abspath(file_out)
parse(yaml_input, file_out=file_out, generate_bom=args.generate_bom) parse(yaml_input, file_out=file_out)
if __name__ == '__main__': if __name__ == '__main__':