From 7df8a4b7cfe322f62dbf55a1d6c7f506a5743e60 Mon Sep 17 00:00:00 2001 From: KV Date: Sat, 10 Oct 2020 20:35:20 +0200 Subject: [PATCH] Add command line options to show version number Add -V command line option (and --version as an alias) to both wireviz.py and build_examples.py that show version number. Move the version number from setup.py into __init__.py to access the same version number specification from all files needing it. This solves part 4 of issue #167. --- setup.py | 4 +++- src/wireviz/__init__.py | 3 +++ src/wireviz/build_examples.py | 3 ++- src/wireviz/wireviz.py | 3 ++- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 09621bb..1a49016 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 e69de29..c8f5000 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 942fd80..5e594da 100755 --- a/src/wireviz/build_examples.py +++ b/src/wireviz/build_examples.py @@ -9,7 +9,7 @@ from pathlib import Path 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 @@ -128,6 +128,7 @@ 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.add_argument('action', nargs='?', action='store', choices=['build','clean','compare','diff','restore'], default='build', help='what to do with the generated files (default: build)') diff --git a/src/wireviz/wireviz.py b/src/wireviz/wireviz.py index 0bee938..cac6aa0 100755 --- a/src/wireviz/wireviz.py +++ b/src/wireviz/wireviz.py @@ -12,7 +12,7 @@ import yaml 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,6 +211,7 @@ 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') # Not implemented: parser.add_argument('--generate-bom', action='store_true', default=True)