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.
This commit is contained in:
KV 2020-10-10 20:35:20 +02:00 committed by Daniel Rojas
parent c4957f1475
commit 7df8a4b7cf
4 changed files with 10 additions and 3 deletions

View File

@ -4,6 +4,8 @@
import os import os
from setuptools import setup, find_packages from setuptools import setup, find_packages
from src.wireviz import __version__
project_name = 'wireviz' project_name = 'wireviz'
# Utility function to read the README file. # Utility function to read the README file.
@ -15,7 +17,7 @@ def read(fname):
setup( setup(
name=project_name, name=project_name,
version='0.1', version=__version__,
author='Daniel Rojas', author='Daniel Rojas',
#author_email='', #author_email='',
description='Easily document cables and wiring harnesses', description='Easily document cables and wiring harnesses',

View File

@ -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'

View File

@ -9,7 +9,7 @@ from pathlib import Path
script_path = Path(__file__).absolute() script_path = Path(__file__).absolute()
sys.path.insert(0, str(script_path.parent.parent)) # to find wireviz module 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 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(): def parse_args():
parser = argparse.ArgumentParser(description='Wireviz Example Manager',) 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', parser.add_argument('action', nargs='?', action='store',
choices=['build','clean','compare','diff','restore'], default='build', choices=['build','clean','compare','diff','restore'], default='build',
help='what to do with the generated files (default: build)') help='what to do with the generated files (default: build)')

View File

@ -12,7 +12,7 @@ import yaml
if __name__ == '__main__': if __name__ == '__main__':
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from wireviz import __version__
from wireviz.Harness import Harness from wireviz.Harness import Harness
from wireviz.wv_helper import expand, open_file_read from wireviz.wv_helper import expand, open_file_read
@ -211,6 +211,7 @@ def parse_cmdline():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Generate cable and wiring harness documentation from YAML descriptions', 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('input_file', action='store', type=str, metavar='YAML_FILE')
parser.add_argument('-o', '--output_file', action='store', type=str, metavar='OUTPUT') parser.add_argument('-o', '--output_file', action='store', type=str, metavar='OUTPUT')
# Not implemented: parser.add_argument('--generate-bom', action='store_true', default=True) # Not implemented: parser.add_argument('--generate-bom', action='store_true', default=True)