55
66import codecs
77import 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'
1115NAME = 'sphinxcontrib-versioning'
1216VERSION = '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+
3375setup (
3476 author = '@Robpol86' ,
3577@@ -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 ,
0 commit comments