From 6f209ed33a4628facf24f35bef70c82f8521d744 Mon Sep 17 00:00:00 2001 From: Robpol86 Date: Sun, 31 Jul 2016 17:42:02 -0700 Subject: [PATCH] CheckVersion Moving version asserts to a setup.py command. --- setup.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++--------- tox.ini | 8 +------- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/setup.py b/setup.py index 7becf88..31431db 100755 --- a/setup.py +++ b/setup.py @@ -5,20 +5,26 @@ import codecs import os +import re -from setuptools import setup +from setuptools import Command, setup -NAME = 'terminaltables' +AUTHOR = '@Robpol86' +INSTALL_REQUIRES = [] +LICENSE = 'MIT' +NAME = IMPORT = 'terminaltables' VERSION = '3.0.0' -def readme(): +def readme(path='README.rst'): """Try to read README.rst or return empty string if failed. + :param str path: Path to README file. + :return: File contents. :rtype: str """ - path = os.path.realpath(os.path.join(os.path.dirname(__file__), 'README.rst')) + path = os.path.realpath(os.path.join(os.path.dirname(__file__), path)) handle = None url_prefix = 'https://raw.githubusercontent.com/Robpol86/{name}/v{version}/'.format(name=NAME, version=VERSION) try: @@ -30,8 +36,41 @@ def readme(): getattr(handle, 'close', lambda: None)() +class CheckVersion(Command): + """Make sure version strings and other metadata match here, in module/package, tox, and other places.""" + + description = 'verify consistent version/etc strings in project' + user_options = [] + + @classmethod + def initialize_options(cls): + """Required by distutils.""" + pass + + @classmethod + def finalize_options(cls): + """Required by distutils.""" + pass + + @classmethod + def run(cls): + """Check variables.""" + project = __import__(IMPORT) + for expected, var in [(AUTHOR, '__author__'), (LICENSE, '__license__'), (VERSION, '__version__')]: + if getattr(project, var) != expected: + raise SystemExit('Mismatch: {0}'.format(var)) + # Check changelog. + if not re.compile(r'^%s - \d{4}-\d{2}-\d{2}$' % VERSION, re.MULTILINE).search(readme()): + raise SystemExit('Version not found in readme/changelog file.') + # Check tox. + if INSTALL_REQUIRES: + in_tox = re.findall(r'\ninstall_requires =\n(?: ([^=]+)==[\w\d.-]+\n)+?', readme('tox.ini')) + if set(INSTALL_REQUIRES) != set(in_tox): + raise SystemExit('Missing pinned dependencies in tox.ini.') + + setup( - author='@Robpol86', + author=AUTHOR, author_email='robpol86@gmail.com', classifiers=[ 'Development Status :: 5 - Production/Stable', @@ -54,14 +93,15 @@ def readme(): 'Topic :: Terminals', 'Topic :: Text Processing :: Markup', ], + cmdclass=dict(check_version=CheckVersion), description='Generate simple tables in terminals from a nested list of strings.', - install_requires=[], + install_requires=INSTALL_REQUIRES, keywords='Shell Bash ANSI ASCII terminal tables', - license='MIT', + license=LICENSE, long_description=readme(), name=NAME, - packages=[NAME], - url='https://github.com/Robpol86/' + NAME, + packages=[IMPORT], + url='https://github.com/{0}/{1}'.format(AUTHOR, NAME), version=VERSION, zip_safe=True, ) diff --git a/tox.ini b/tox.ini index a2ae304..b37c5b4 100644 --- a/tox.ini +++ b/tox.ini @@ -44,15 +44,9 @@ commands = python setup.py check --strict python setup.py check --strict -m python setup.py check --strict -s + python setup.py check_version flake8 --application-import-names={[general]name},tests pylint --rcfile=tox.ini setup.py {[general]name} - python -c "assert '{[general]author}' == __import__('{[general]name}').__author__" - python -c "assert '{[general]license}' == __import__('{[general]name}').__license__" - python -c "assert '{[general]version}' == __import__('{[general]name}').__version__" - python -c "assert 'author=\'{[general]author}\'' in open('setup.py').read(102400)" - python -c "assert 'license=\'{[general]license}\'' in open('setup.py').read(102400)" - python -c "assert 'VERSION = \'{[general]version}\'' in open('setup.py').read(102400)" - python -c "assert '\n{[general]version} - ' in open('README.rst').read(102400)" deps = coverage==4.2 flake8-docstrings==1.0.2