Skip to content

Commit 04063de

Browse files
committed
Bumped linters. Moved version linting to setup.py.
Bumped linter versions and moved version consistency checks into a setup.py command. Pinning dependency versions in tox.ini.
1 parent e5dfc0a commit 04063de

File tree

3 files changed

+64
-25
lines changed

3 files changed

+64
-25
lines changed

setup.py

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,26 @@
55

66
import codecs
77
import os
8+
import re
89

9-
from setuptools import setup
10+
from setuptools import Command, setup
1011

12+
IMPORT = 'sphinxcontrib.versioning'
13+
INSTALL_REQUIRES = ['colorclass', 'docopt', 'sphinx']
14+
LICENSE = 'MIT'
1115
NAME = 'sphinxcontrib-versioning'
1216
VERSION = '1.0.0'
1317

1418

15-
def readme():
19+
def readme(path='README.rst'):
1620
"""Try to read README.rst or return empty string if failed.
1721
22+
:param str path: Path to README file.
23+
1824
:return: File contents.
1925
:rtype: str
2026
"""
21-
path = os.path.realpath(os.path.join(os.path.dirname(__file__), 'README.rst'))
27+
path = os.path.realpath(os.path.join(os.path.dirname(__file__), path))
2228
handle = None
2329
url_prefix = 'https://raw.githubusercontent.com/Robpol86/{name}/v{version}/'.format(name=NAME, version=VERSION)
2430
try:
@@ -30,6 +36,42 @@ def readme():
3036
getattr(handle, 'close', lambda: None)()
3137

3238

39+
class CheckVersion(Command):
40+
"""Make sure version strings and other metadata match here, in module/package, tox, and other places."""
41+
42+
description = 'verify consistent version/etc strings in project'
43+
user_options = []
44+
45+
@classmethod
46+
def initialize_options(cls):
47+
"""Required by distutils."""
48+
pass
49+
50+
@classmethod
51+
def finalize_options(cls):
52+
"""Required by distutils."""
53+
pass
54+
55+
@classmethod
56+
def run(cls):
57+
"""Check variables."""
58+
project = __import__(IMPORT, fromlist=[''])
59+
for expected, var in [('@Robpol86', '__author__'), (LICENSE, '__license__'), (VERSION, '__version__')]:
60+
if getattr(project, var) != expected:
61+
raise SystemExit('Mismatch: {0}'.format(var))
62+
# Check changelog.
63+
if not re.compile(r'^%s - \d{4}-\d{2}-\d{2}$' % VERSION, re.MULTILINE).search(readme()):
64+
raise SystemExit('Version not found in readme/changelog file.')
65+
# Check tox.
66+
if INSTALL_REQUIRES:
67+
section = re.compile(r'\ninstall_requires =\n(.+?)\n\w', re.DOTALL).findall(readme('tox.ini'))
68+
if not section:
69+
raise SystemExit('Missing install_requires section in tox.ini.')
70+
in_tox = re.findall(r' ([^=]+)==[\w\d.-]+', section[0])
71+
if INSTALL_REQUIRES != in_tox:
72+
raise SystemExit('Missing/unordered pinned dependencies in tox.ini.')
73+
74+
3375
setup(
3476
author='@Robpol86',
3577
author_email='[email protected]',
@@ -50,15 +92,16 @@ def readme():
5092
'Topic :: Documentation :: Sphinx',
5193
'Topic :: Software Development :: Documentation',
5294
],
95+
cmdclass=dict(check_version=CheckVersion),
5396
description='Sphinx extension that allows building versioned docs for self-hosting.',
5497
entry_points={'console_scripts': ['sphinx-versioning = sphinxcontrib.versioning.__main__:entry_point']},
55-
install_requires=['colorclass', 'docopt', 'sphinx'],
98+
install_requires=INSTALL_REQUIRES,
5699
keywords='sphinx versioning versions version branches tags',
57-
license='MIT',
100+
license=LICENSE,
58101
long_description=readme(),
59102
name=NAME,
60-
package_data={'': ['_templates/versions.html']},
61-
packages=[NAME.split('-')[0], os.path.join(*NAME.split('-'))],
103+
package_data={'': [os.path.join('_templates', 'versions.html')]},
104+
packages=['sphinxcontrib', os.path.join('sphinxcontrib', 'versioning')],
62105
url='https://github.com/Robpol86/' + NAME,
63106
version=VERSION,
64107
zip_safe=True,

tests/test__main__/test_main_push_scenarios.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def test_error_clone_failure(local_docs, run):
155155

156156

157157
def test_error_build_failure(local_docs_ghp, run):
158-
"""HandledError in main_build().
158+
"""Test HandledError in main_build().
159159
160160
:param local_docs_ghp: conftest fixture.
161161
:param run: conftest fixture.

tox.ini

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
[general]
2-
author = @Robpol86
3-
license = MIT
2+
install_requires =
3+
colorclass==2.2.0
4+
docopt==0.6.2
5+
sphinx==1.4.5
46
name = sphinxcontrib
5-
version = 1.0.0
67

78
[tox]
89
envlist = lint,py{34,27}
@@ -12,6 +13,7 @@ commands =
1213
py.test --cov-report term-missing --cov-report xml --cov {[general]name} --cov-config tox.ini \
1314
{posargs:tests}
1415
deps =
16+
{[general]install_requires}
1517
pytest-catchlog==1.2.2
1618
pytest-cov==2.3.0
1719
sphinx_rtd_theme==0.1.10a0
@@ -24,20 +26,15 @@ commands =
2426
python setup.py check --strict
2527
python setup.py check --strict -m
2628
python setup.py check --strict -s
29+
python setup.py check_version
2730
flake8 --application-import-names={[general]name},tests
2831
pylint --rcfile=tox.ini setup.py {[general]name}
29-
python -c "assert '{[general]author}' == __import__('{[general]name}.versioning').versioning.__author__"
30-
python -c "assert '{[general]license}' == __import__('{[general]name}.versioning').versioning.__license__"
31-
python -c "assert '{[general]version}' == __import__('{[general]name}.versioning').versioning.__version__"
32-
python -c "assert 'author=\'{[general]author}\'' in open('setup.py').read(102400)"
33-
python -c "assert 'license=\'{[general]license}\'' in open('setup.py').read(102400)"
34-
python -c "assert 'VERSION = \'{[general]version}\'' in open('setup.py').read(102400)"
35-
python -c "assert '\n{[general]version} - ' in open('README.rst').read(102400)"
3632
deps =
37-
coverage==4.2b1
38-
flake8==2.5.5
39-
flake8-import-order==0.5
40-
flake8-pep257==1.0.5
33+
{[general]install_requires}
34+
coverage==4.2
35+
flake8==3.0.3
36+
flake8-import-order==0.9.1
37+
flake8-docstrings==1.0.2
4138
pep8-naming==0.4.1
4239
pylint==1.6.4
4340

@@ -46,7 +43,7 @@ changedir = {toxinidir}/docs
4643
commands =
4744
sphinx-build -a -E -W . _build/html
4845
deps =
49-
Sphinx==1.4.5
46+
{[general]install_requires}
5047
sphinx-rtd-theme==0.1.10a0
5148

5249
[testenv:docsV]
@@ -63,8 +60,7 @@ passenv =
6360

6461
[flake8]
6562
exclude = .tox/*,build/*,docs/*,env/*,get-pip.py
66-
ignore = D203
67-
import-order-style = google
63+
import-order-style = smarkets
6864
max-line-length = 120
6965
statistics = True
7066

0 commit comments

Comments
 (0)