Release 1.2.1.
[third_party/testtools] / setup.py
1 #!/usr/bin/env python
2 """Distutils installer for testtools."""
3
4 from setuptools import setup
5 from distutils.command.build_py import build_py
6 import email
7 import os
8 import sys
9
10 import testtools
11 cmd_class = {}
12 if getattr(testtools, 'TestCommand', None) is not None:
13     cmd_class['test'] = testtools.TestCommand
14
15
16 class testtools_build_py(build_py):
17     def build_module(self, module, module_file, package):
18         if sys.version_info >= (3,) and module == '_compat2x':
19             return
20         return build_py.build_module(self, module, module_file, package)
21 cmd_class['build_py'] = testtools_build_py
22
23
24 def get_version_from_pkg_info():
25     """Get the version from PKG-INFO file if we can."""
26     pkg_info_path = os.path.join(os.path.dirname(__file__), 'PKG-INFO')
27     try:
28         pkg_info_file = open(pkg_info_path, 'r')
29     except (IOError, OSError):
30         return None
31     try:
32         pkg_info = email.message_from_file(pkg_info_file)
33     except email.MessageError:
34         return None
35     return pkg_info.get('Version', None)
36
37
38 def get_version():
39     """Return the version of testtools that we are building."""
40     version = '.'.join(
41         str(component) for component in testtools.__version__[0:3])
42     phase = testtools.__version__[3]
43     if phase == 'final':
44         return version
45     pkg_info_version = get_version_from_pkg_info()
46     if pkg_info_version:
47         return pkg_info_version
48     # Apparently if we just say "snapshot" then distribute won't accept it
49     # as satisfying versioned dependencies. This is a problem for the
50     # daily build version.
51     return "%s.0dev0" % (version,)
52
53
54 def get_long_description():
55     manual_path = os.path.join(
56         os.path.dirname(__file__), 'doc/overview.rst')
57     return open(manual_path).read()
58
59
60 setup(name='testtools',
61       author='Jonathan M. Lange',
62       author_email='jml+testtools@mumak.net',
63       url='https://github.com/testing-cabal/testtools',
64       description=('Extensions to the Python standard library unit testing '
65                    'framework'),
66       long_description=get_long_description(),
67       version=get_version(),
68       classifiers=["License :: OSI Approved :: MIT License",
69         "Programming Language :: Python :: 3",
70         ],
71       packages=[
72         'testtools',
73         'testtools.matchers',
74         'testtools.testresult',
75         'testtools.tests',
76         'testtools.tests.matchers',
77         ],
78       cmdclass=cmd_class,
79       zip_safe=False,
80       install_requires=[
81         'extras',
82         # 'mimeparse' has not been uploaded by the maintainer with Python3 compat
83         # but someone kindly uploaded a fixed version as 'python-mimeparse'.
84         'python-mimeparse',
85         'unittest2>=0.8.0',
86         ],
87       )