Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Commit

Permalink
CheckVersion
Browse files Browse the repository at this point in the history
Moving version asserts to a setup.py command.
  • Loading branch information
Robpol86 committed Aug 1, 2016
1 parent c472b32 commit 6f209ed
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
58 changes: 49 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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',
Expand All @@ -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,
)
8 changes: 1 addition & 7 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6f209ed

Please sign in to comment.