From ed19fd8aaef92d9c0bd623081ae791bef34b20c3 Mon Sep 17 00:00:00 2001 From: KV Date: Sat, 10 Oct 2020 21:43:27 +0200 Subject: [PATCH 1/3] Add version number to output files with meta info Tag the .gv and .html output files with generator and version number. --- src/wireviz/Harness.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index a29ce35b..f5ef5e54 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -3,7 +3,7 @@ from wireviz.DataClasses import Connector, Cable from graphviz import Graph -from wireviz import wv_colors, wv_helper +from wireviz import wv_colors, wv_helper, __version__ from wireviz.wv_colors import get_color_hex from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, \ nested_html_table, flatten2d, index_if_list, html_line_breaks, \ @@ -63,7 +63,7 @@ def connect(self, from_name: str, from_pin: (int, str), via_name: str, via_pin: def create_graph(self) -> Graph: dot = Graph() - dot.body.append('// Graph generated by WireViz') + dot.body.append('// Graph generated by WireViz ' + __version__) dot.body.append('// https://github.com/formatc1702/WireViz') font = 'arial' dot.attr('graph', rankdir='LR', @@ -296,7 +296,12 @@ def output(self, filename: (str, Path), view: bool = False, cleanup: bool = True # HTML output with open_file_write(f'{filename}.html') as file: file.write('\n') - file.write('') + file.write('\n') + file.write(' \n') + file.write(f' \n') + file.write(' Wireviz Diagram and BOM\n') + file.write('\n') file.write('

Diagram

') with open_file_read(f'{filename}.svg') as svg: From b31c164b57250383460d90d71d3ad792690ed8c9 Mon Sep 17 00:00:00 2001 From: KV Date: Thu, 15 Oct 2020 20:42:34 +0200 Subject: [PATCH 2/3] Define application name and URL only once The application name and URL was defined several places in the code, and the name was not written exactly the same everywhere. By using the same constants everywhere, consistency is obtained. --- setup.py | 8 +++----- src/wireviz/Harness.py | 11 +++++------ src/wireviz/__init__.py | 4 ++++ src/wireviz/build_examples.py | 8 ++++---- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/setup.py b/setup.py index cd289742..af1b715f 100644 --- a/setup.py +++ b/setup.py @@ -4,9 +4,7 @@ import os from setuptools import setup, find_packages -from src.wireviz import __version__ - -project_name = 'wireviz' +from src.wireviz import __version__, CMD_NAME, APP_URL # Utility function to read the README file. # Used for the long_description. It's nice, because now 1) we have a top level @@ -16,7 +14,7 @@ def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() setup( - name=project_name, + name=CMD_NAME, version=__version__, author='Daniel Rojas', #author_email='', @@ -30,7 +28,7 @@ def read(fname): ], license='GPLv3', keywords='cable connector hardware harness wiring wiring-diagram wiring-harness', - url='https://github.com/formatc1702/WireViz', + url=APP_URL, package_dir={'': 'src'}, packages=find_packages('src'), entry_points={ diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index f5ef5e54..e597a153 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -3,7 +3,7 @@ from wireviz.DataClasses import Connector, Cable from graphviz import Graph -from wireviz import wv_colors, wv_helper, __version__ +from wireviz import wv_colors, wv_helper, __version__, APP_NAME, APP_URL from wireviz.wv_colors import get_color_hex from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, \ nested_html_table, flatten2d, index_if_list, html_line_breaks, \ @@ -63,8 +63,8 @@ def connect(self, from_name: str, from_pin: (int, str), via_name: str, via_pin: def create_graph(self) -> Graph: dot = Graph() - dot.body.append('// Graph generated by WireViz ' + __version__) - dot.body.append('// https://github.com/formatc1702/WireViz') + dot.body.append(f'// Graph generated by {APP_NAME} {__version__}') + dot.body.append(f'// {APP_URL}') font = 'arial' dot.attr('graph', rankdir='LR', ranksep='2', @@ -298,9 +298,8 @@ def output(self, filename: (str, Path), view: bool = False, cleanup: bool = True file.write('\n') file.write('\n') file.write(' \n') - file.write(f' \n') - file.write(' Wireviz Diagram and BOM\n') + file.write(f' \n') + file.write(f' {APP_NAME} Diagram and BOM\n') file.write('\n') file.write('

Diagram

') diff --git a/src/wireviz/__init__.py b/src/wireviz/__init__.py index c8f5000d..3f3bcf3c 100644 --- a/src/wireviz/__init__.py +++ b/src/wireviz/__init__.py @@ -1,3 +1,7 @@ # Please don't import anything in this file to avoid issues when it is imported in setup.py __version__ = '0.1.1' + +CMD_NAME = 'wireviz' # Lower case command and module name +APP_NAME = 'WireViz' # Application name in texts meant to be human readable +APP_URL = 'https://github.com/formatc1702/WireViz' diff --git a/src/wireviz/build_examples.py b/src/wireviz/build_examples.py index 5e594dae..4195b121 100755 --- a/src/wireviz/build_examples.py +++ b/src/wireviz/build_examples.py @@ -9,7 +9,7 @@ script_path = Path(__file__).absolute() sys.path.insert(0, str(script_path.parent.parent)) # to find wireviz module -from wireviz import wireviz, __version__ +from wireviz import wireviz, __version__, APP_NAME from wv_helper import open_file_write, open_file_read, open_file_append @@ -26,7 +26,7 @@ 'path': dir / 'tutorial', 'prefix': 'tutorial', readme: ['md', 'yml'], # Include .md and .yml files - 'title': 'WireViz Tutorial', + 'title': f'{APP_NAME} Tutorial', }, 'demos' : { 'path': dir / 'examples', @@ -127,8 +127,8 @@ def restore_generated(groupkeys, branch = ''): def parse_args(): - parser = argparse.ArgumentParser(description='Wireviz Example Manager',) - parser.add_argument('-V', '--version', action='version', version='%(prog)s - wireviz ' + __version__) + parser = argparse.ArgumentParser(description=f'{APP_NAME} Example Manager',) + parser.add_argument('-V', '--version', action='version', version=f'%(prog)s - {APP_NAME} {__version__}') parser.add_argument('action', nargs='?', action='store', choices=['build','clean','compare','diff','restore'], default='build', help='what to do with the generated files (default: build)') From f6d0f23ba14213cd16212f0a6861e85a593160a0 Mon Sep 17 00:00:00 2001 From: KV Date: Thu, 15 Oct 2020 20:56:05 +0200 Subject: [PATCH 3/3] Avoid errors from HTML validator The https://validator.w3.org/ reported Errors: The align attribute on the th/td element is obsolete. Use CSS instead. By replacing align="X" attributes with text-align:X; CSS equivalent, the validator now completes without any errors or warnings. This solves the remaining issues from #97. --- src/wireviz/Harness.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index e597a153..8b401c21 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -316,14 +316,14 @@ def output(self, filename: (str, Path), view: bool = False, cleanup: bool = True file.write('') file.write('') for item in listy[0]: - file.write(f'') + file.write(f'') file.write('') for row in listy[1:]: file.write('') for i, item in enumerate(row): item_str = item.replace('\u00b2', '²') - align = 'align="right"' if listy[0][i] == 'Qty' else '' - file.write(f'') + align = 'text-align:right; ' if listy[0][i] == 'Qty' else '' + file.write(f'') file.write('') file.write('
{item}{item}
{item_str}{item_str}
')