Ned Batchelder avatar Ned Batchelder committed d577a86

Don't import coverage into setup.py to get the version number. Do something far worse... :) #73

Comments (0)

Files changed (5)

coverage/__init__.py

 
 """
 
-__version__ = "3.5.4b1"       # see detailed history in CHANGES.txt
-
-__url__ = "http://nedbatchelder.com/code/coverage"
-if max(__version__).isalpha():
-    # For pre-releases, use a version-specific URL.
-    __url__ += "/" + __version__
+from coverage.version import __version__, __url__
 
 from coverage.control import coverage, process_startup
 from coverage.data import CoverageData
 from coverage.cmdline import main, CoverageScript
 from coverage.misc import CoverageException
 
-
 # Module-level functions.  The original API to this module was based on
 # functions defined directly in the module, with a singleton of the coverage()
 # class.  That design hampered programmability, so the current api uses

coverage/version.py

+"""The version and URL for coverage.py"""
+# This file is exec'ed in setup.py, don't import anything!
+
+__version__ = "3.5.4b1"       # see detailed history in CHANGES.txt
+
+__url__ = "http://nedbatchelder.com/code/coverage"
+if max(__version__).isalpha():
+    # For pre-releases, use a version-specific URL.
+    __url__ += "/" + __version__
     - Ubuntu
     - Mac
     - Pythons 2.3, 2.4, 2.5, 2.6, 2.7, 3.1, 3.2, 3.3
-- Version number in coverage/__init__.py
+- Version number in coverage/version.py
     - 3.1a1, 3.1b1, 3.1c1, 3.1
 - Update CHANGES.txt, including release date.
 - Update docstring in setup.py, including "New in x.y:"
-# setup.py for coverage.
+# setup.py for coverage.py
 
 """Code coverage measurement for Python
 
 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
 """
 
 # 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
 from setuptools import setup
 from distutils.core import Extension    # pylint: disable=E0611,F0401
 
-# Get or massage our metadata.
+# Get or massage our metadata.  We exec coverage/version.py so we can avoid
+# importing the product code into setup.py.
 
-from coverage import __url__, __version__
+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")
+exec(compile(open(cov_ver_py).read(), cov_ver_py, 'exec'))
 
-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"
     devstat = "5 - Production/Stable"
 classifier_list.append("Development Status :: " + devstat)
 
-# Set it up!
+# Create the keyword arguments for setup()
 
 setup_args = dict(
     name = 'coverage',

test/test_misc.py

 import os, sys
 
 from coverage.misc import Hasher
+from coverage import __version__, __url__
 sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k
 from coveragetest import CoverageTest
 
         h2 = Hasher()
         h2.update({'b': 23, 'a': 17})
         self.assertEqual(h1.digest(), h2.digest())
+
+
+class SetupPyTest(CoverageTest):
+    """Tests of setup.py"""
+
+    run_in_temp_dir = False
+
+    def test_version(self):
+        status, output = self.run_command_status(
+            "python setup.py --description --version --url --author"
+            )
+        self.assertEqual(status, 0)
+        out = output.splitlines()
+        self.assertIn("measurement", out[0])
+        self.assertEqual(out[1], __version__)
+        self.assertEqual(out[2], __url__)
+        self.assertIn("Ned Batchelder", out[3])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.