diff options
Diffstat (limited to 'setup.py')
-rw-r--r-- | setup.py | 74 |
1 files changed, 44 insertions, 30 deletions
@@ -1,4 +1,4 @@ -# setup.py for coverage. +# setup.py for coverage.py """Code coverage measurement for Python @@ -19,12 +19,11 @@ can be reported. New in 3.3: .coveragerc files. New in 3.2: Branch coverage! - """ # This file is used unchanged under all versions of Python, 2.x and 3.x. -classifiers = """ +classifiers = """\ Environment :: Console Intended Audience :: Developers License :: OSI Approved :: BSD License @@ -36,7 +35,7 @@ Topic :: Software Development :: Testing """ # Pull in the tools we need. -import sys +import os, sys # Distribute is a new fork of setuptools. It's supported on Py3.x, so we use # it there, but stick with classic setuptools on Py2.x until Distribute becomes @@ -51,17 +50,21 @@ use_setuptools() from setuptools import setup from distutils.core import Extension # pylint: disable=E0611,F0401 -# Get or massage our metadata. - -from coverage import __url__, __version__ +# Get or massage our metadata. We exec coverage/version.py so we can avoid +# importing the product code into setup.py. -scripts = ['coverage = coverage:main'] -if sys.version_info >= (3, 0): - scripts.append('coverage3 = coverage:main') +doc = __doc__ # __doc__ will be overwritten by version.py. +__version__ = __url__ = "" # keep pylint happy. -doclines = (__doc__ % __url__).split('\n') +cov_ver_py = os.path.join(os.path.split(__file__)[0], "coverage/version.py") +version_file = open(cov_ver_py) +try: + exec(compile(version_file.read(), cov_ver_py, 'exec')) +finally: + version_file.close() -classifier_list = [c for c in classifiers.split("\n") if c] +doclines = (doc % __url__).splitlines() +classifier_list = classifiers.splitlines() if 'a' in __version__: devstat = "3 - Alpha" @@ -71,7 +74,13 @@ else: devstat = "5 - Production/Stable" classifier_list.append("Development Status :: " + devstat) -# Set it up! +# Install a script as "coverage", and as "coverage[23]" +scripts = [ + 'coverage = coverage:main', + 'coverage%d = coverage:main' % sys.version_info[0], + ] + +# Create the keyword arguments for setup() setup_args = dict( name = 'coverage', @@ -126,20 +135,25 @@ if sys.version_info >= (3, 0): use_2to3=False, )) -# For a variety of reasons, it might not be possible to install the C -# extension. Try it with, and if it fails, try it without. -try: - setup(**setup_args) -except: # pylint: disable=W0702 - # When setup() can't compile, it tries to exit. We'll catch SystemExit - # here :-(, and try again. - if 'install' not in sys.argv or 'ext_modules' not in setup_args: - # We weren't trying to install an extension, so forget it. - raise - msg = "Couldn't install with extension module, trying without it..." - exc = sys.exc_info()[1] - exc_msg = "%s: %s" % (exc.__class__.__name__, exc) - print("**\n** %s\n** %s\n**" % (msg, exc_msg)) - - del setup_args['ext_modules'] - setup(**setup_args) +def main(): + """Actually invoke setup() with the arguments we built above.""" + # For a variety of reasons, it might not be possible to install the C + # extension. Try it with, and if it fails, try it without. + try: + setup(**setup_args) + except: # pylint: disable=W0702 + # When setup() can't compile, it tries to exit. We'll catch SystemExit + # here :-(, and try again. + if 'install' not in sys.argv or 'ext_modules' not in setup_args: + # We weren't trying to install an extension, so forget it. + raise + msg = "Couldn't install with extension module, trying without it..." + exc = sys.exc_info()[1] + exc_msg = "%s: %s" % (exc.__class__.__name__, exc) + print("**\n** %s\n** %s\n**" % (msg, exc_msg)) + + del setup_args['ext_modules'] + setup(**setup_args) + +if __name__ == '__main__': + main() |