diff --git a/setup.py b/setup.py index 09621bb7..1a49016c 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,8 @@ import os from setuptools import setup, find_packages +from src.wireviz import __version__ + project_name = 'wireviz' # Utility function to read the README file. @@ -15,7 +17,7 @@ def read(fname): setup( name=project_name, - version='0.1', + version=__version__, author='Daniel Rojas', #author_email='', description='Easily document cables and wiring harnesses', diff --git a/src/wireviz/__init__.py b/src/wireviz/__init__.py index e69de29b..c8f5000d 100644 --- a/src/wireviz/__init__.py +++ b/src/wireviz/__init__.py @@ -0,0 +1,3 @@ +# Please don't import anything in this file to avoid issues when it is imported in setup.py + +__version__ = '0.1.1' diff --git a/src/wireviz/build_examples.py b/src/wireviz/build_examples.py index 10a4b1bf..5e594dae 100755 --- a/src/wireviz/build_examples.py +++ b/src/wireviz/build_examples.py @@ -9,26 +9,27 @@ script_path = Path(__file__).absolute() sys.path.insert(0, str(script_path.parent.parent)) # to find wireviz module -from wireviz import wireviz +from wireviz import wireviz, __version__ from wv_helper import open_file_write, open_file_read, open_file_append +dir = script_path.parent.parent.parent readme = 'readme.md' groups = { 'examples': { - 'path': Path(script_path).parent.parent.parent / 'examples', + 'path': dir / 'examples', 'prefix': 'ex', readme: [], # Include no files 'title': 'Example Gallery', }, 'tutorial' : { - 'path': Path(script_path).parent.parent.parent / 'tutorial', + 'path': dir / 'tutorial', 'prefix': 'tutorial', readme: ['md', 'yml'], # Include .md and .yml files 'title': 'WireViz Tutorial', }, 'demos' : { - 'path': Path(script_path).parent.parent.parent / 'examples', + 'path': dir / 'examples', 'prefix': 'demo', }, } @@ -96,17 +97,21 @@ def clean_generated(groupkeys): os.remove(filename) -def compare_generated(groupkeys, include_graphviz_output = False): +def compare_generated(groupkeys, branch = '', include_graphviz_output = False): + if branch: + branch = f' {branch.strip()}' compare_extensions = generated_extensions if include_graphviz_output else extensions_not_containing_graphviz_output for key in groupkeys: # collect and compare files for filename in collect_filenames('Comparing', key, compare_extensions): - cmd = f'git --no-pager diff "{filename}"' + cmd = f'git --no-pager diff{branch} -- "{filename}"' print(f' {cmd}') os.system(cmd) -def restore_generated(groupkeys): +def restore_generated(groupkeys, branch = ''): + if branch: + branch = f' {branch.strip()}' for key in groupkeys: # collect input YAML files filename_list = collect_filenames('Restoring', key, input_extensions) @@ -116,18 +121,21 @@ def restore_generated(groupkeys): filename_list.append(groups[key]['path'] / readme) # restore files for filename in filename_list: - cmd = f'git checkout -- "{filename}"' + cmd = f'git checkout{branch} -- "{filename}"' print(f' {cmd}') os.system(cmd) def parse_args(): parser = argparse.ArgumentParser(description='Wireviz Example Manager',) + parser.add_argument('-V', '--version', action='version', version='%(prog)s - wireviz ' + __version__) parser.add_argument('action', nargs='?', action='store', - choices=['build','clean','compare','restore'], default='build', + choices=['build','clean','compare','diff','restore'], default='build', help='what to do with the generated files (default: build)') parser.add_argument('-c', '--compare-graphviz-output', action='store_true', help='the Graphviz output is also compared (default: False)') + parser.add_argument('-b', '--branch', action='store', default='', + help='branch or commit to compare with or restore from') parser.add_argument('-g', '--groups', nargs='+', choices=groups.keys(), default=groups.keys(), help='the groups of generated files (default: all)') @@ -140,10 +148,10 @@ def main(): build_generated(args.groups) elif args.action == 'clean': clean_generated(args.groups) - elif args.action == 'compare': - compare_generated(args.groups, args.compare_graphviz_output) + elif args.action == 'compare' or args.action == 'diff': + compare_generated(args.groups, args.branch, args.compare_graphviz_output) elif args.action == 'restore': - restore_generated(args.groups) + restore_generated(args.groups, args.branch) if __name__ == '__main__': diff --git a/src/wireviz/wireviz.py b/src/wireviz/wireviz.py index 3adc0782..cac6aa0b 100755 --- a/src/wireviz/wireviz.py +++ b/src/wireviz/wireviz.py @@ -12,7 +12,7 @@ if __name__ == '__main__': sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) - +from wireviz import __version__ from wireviz.Harness import Harness from wireviz.wv_helper import expand, open_file_read @@ -211,9 +211,10 @@ def parse_cmdline(): parser = argparse.ArgumentParser( description='Generate cable and wiring harness documentation from YAML descriptions', ) + parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__) parser.add_argument('input_file', action='store', type=str, metavar='YAML_FILE') parser.add_argument('-o', '--output_file', action='store', type=str, metavar='OUTPUT') - parser.add_argument('--generate-bom', action='store_true', default=True) + # Not implemented: parser.add_argument('--generate-bom', action='store_true', default=True) parser.add_argument('--prepend-file', action='store', type=str, metavar='YAML_FILE') return parser.parse_args()