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.
This commit is contained in:
KV 2020-10-15 20:42:34 +02:00 committed by Daniel Rojas
parent b00040cdd9
commit 7dcd1a7eeb
4 changed files with 16 additions and 15 deletions

View File

@ -4,9 +4,7 @@
import os import os
from setuptools import setup, find_packages from setuptools import setup, find_packages
from src.wireviz import __version__ from src.wireviz import __version__, CMD_NAME, APP_URL
project_name = 'wireviz'
# Utility function to read the README file. # Utility function to read the README file.
# Used for the long_description. It's nice, because now 1) we have a top level # 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() return open(os.path.join(os.path.dirname(__file__), fname)).read()
setup( setup(
name=project_name, name=CMD_NAME,
version=__version__, version=__version__,
author='Daniel Rojas', author='Daniel Rojas',
#author_email='', #author_email='',
@ -30,7 +28,7 @@ setup(
], ],
license='GPLv3', license='GPLv3',
keywords='cable connector hardware harness wiring wiring-diagram wiring-harness', keywords='cable connector hardware harness wiring wiring-diagram wiring-harness',
url='https://github.com/formatc1702/WireViz', url=APP_URL,
package_dir={'': 'src'}, package_dir={'': 'src'},
packages=find_packages('src'), packages=find_packages('src'),
entry_points={ entry_points={

View File

@ -3,7 +3,7 @@
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, 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_colors import get_color_hex
from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, \ from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, \
nested_html_table, flatten2d, index_if_list, html_line_breaks, \ nested_html_table, flatten2d, index_if_list, html_line_breaks, \
@ -63,8 +63,8 @@ class Harness:
def create_graph(self) -> Graph: def create_graph(self) -> Graph:
dot = Graph() dot = Graph()
dot.body.append('// Graph generated by WireViz ' + __version__) dot.body.append(f'// Graph generated by {APP_NAME} {__version__}')
dot.body.append('// https://github.com/formatc1702/WireViz') dot.body.append(f'// {APP_URL}')
font = 'arial' font = 'arial'
dot.attr('graph', rankdir='LR', dot.attr('graph', rankdir='LR',
ranksep='2', ranksep='2',
@ -298,9 +298,8 @@ class Harness:
file.write('<!DOCTYPE html>\n') file.write('<!DOCTYPE html>\n')
file.write('<html lang="en"><head>\n') file.write('<html lang="en"><head>\n')
file.write(' <meta charset="UTF-8">\n') file.write(' <meta charset="UTF-8">\n')
file.write(f' <meta name="generator" content="WireViz {__version__}' file.write(f' <meta name="generator" content="{APP_NAME} {__version__} - {APP_URL}">\n')
' - https://github.com/formatc1702/WireViz">\n') file.write(f' <title>{APP_NAME} Diagram and BOM</title>\n')
file.write(' <title>Wireviz Diagram and BOM</title>\n')
file.write('</head><body style="font-family:Arial">\n') file.write('</head><body style="font-family:Arial">\n')
file.write('<h1>Diagram</h1>') file.write('<h1>Diagram</h1>')

View File

@ -1,3 +1,7 @@
# Please don't import anything in this file to avoid issues when it is imported in setup.py # Please don't import anything in this file to avoid issues when it is imported in setup.py
__version__ = '0.1.1' __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'

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, __version__ from wireviz import wireviz, __version__, APP_NAME
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
@ -26,7 +26,7 @@ groups = {
'path': dir / 'tutorial', 'path': dir / 'tutorial',
'prefix': 'tutorial', 'prefix': 'tutorial',
readme: ['md', 'yml'], # Include .md and .yml files readme: ['md', 'yml'], # Include .md and .yml files
'title': 'WireViz Tutorial', 'title': f'{APP_NAME} Tutorial',
}, },
'demos' : { 'demos' : {
'path': dir / 'examples', 'path': dir / 'examples',
@ -127,8 +127,8 @@ def restore_generated(groupkeys, branch = ''):
def parse_args(): def parse_args():
parser = argparse.ArgumentParser(description='Wireviz Example Manager',) parser = argparse.ArgumentParser(description=f'{APP_NAME} Example Manager',)
parser.add_argument('-V', '--version', action='version', version='%(prog)s - wireviz ' + __version__) parser.add_argument('-V', '--version', action='version', version=f'%(prog)s - {APP_NAME} {__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)')