Merge lp:~jml/testtools/better-snapshot-613734 into lp:~testtools-committers/testtools/trunk

Proposed by Jonathan Lange
Status: Merged
Merged at revision: 110
Proposed branch: lp:~jml/testtools/better-snapshot-613734
Merge into: lp:~testtools-committers/testtools/trunk
Diff against target: 76 lines (+35/-7)
2 files modified
MANIFEST.in (+0/-1)
setup.py (+35/-6)
To merge this branch: bzr merge lp:~jml/testtools/better-snapshot-613734
Reviewer Review Type Date Requested Status
testtools developers Pending
Review via email: mp+38719@code.launchpad.net

Description of the change

This branch addresses bug 613734 by attempting to read the version number from PKG-INFO if it is present. This prevents bzrlib from being used to get the revno when using a testtools snapshot in buildout.

PKG-INFO is defined as being an RFC 822 message, and the 'email' module is the recommended way of reading such.

I changed the version number for development versions to be of the form 0.9.8-r123. This is largely because buildout explodes on the ~.

setup.py is also refactored a little to make it more readable to me.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

Thanks, doit.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'MANIFEST.in'
2--- MANIFEST.in 2009-12-13 00:34:05 +0000
3+++ MANIFEST.in 2010-10-18 13:33:39 +0000
4@@ -5,5 +5,4 @@
5 include MANUAL
6 include NEWS
7 include README
8-include run-tests
9 include .bzrignore
10
11=== modified file 'setup.py'
12--- setup.py 2010-09-11 13:44:56 +0000
13+++ setup.py 2010-10-18 13:33:39 +0000
14@@ -2,20 +2,49 @@
15 """Distutils installer for testtools."""
16
17 from distutils.core import setup
18+import email
19 import os
20
21 import testtools
22-version = '.'.join(str(component) for component in testtools.__version__[0:3])
23-phase = testtools.__version__[3]
24-if phase != 'final':
25+
26+
27+def get_revno():
28 import bzrlib.workingtree
29 t = bzrlib.workingtree.WorkingTree.open_containing(__file__)[0]
30+ return t.branch.revno()
31+
32+
33+def get_version_from_pkg_info():
34+ """Get the version from PKG-INFO file if we can."""
35+ pkg_info_path = os.path.join(os.path.dirname(__file__), 'PKG-INFO')
36+ try:
37+ pkg_info_file = open(pkg_info_path, 'r')
38+ except (IOError, OSError):
39+ return None
40+ try:
41+ pkg_info = email.message_from_file(pkg_info_file)
42+ except email.MessageError:
43+ return None
44+ return pkg_info.get('Version', None)
45+
46+
47+def get_version():
48+ """Return the version of testtools that we are building."""
49+ version = '.'.join(
50+ str(component) for component in testtools.__version__[0:3])
51+ phase = testtools.__version__[3]
52+ if phase == 'final':
53+ return version
54+ pkg_info_version = get_version_from_pkg_info()
55+ if pkg_info_version:
56+ return pkg_info_version
57+ revno = get_revno()
58 if phase == 'alpha':
59 # No idea what the next version will be
60- version = 'next-%s' % t.branch.revno()
61+ return 'next-r%s' % revno
62 else:
63 # Preserve the version number but give it a revno prefix
64- version = version + '~%s' % t.branch.revno()
65+ return version + '-r%s' % revno
66
67
68 def get_long_description():
69@@ -30,6 +59,6 @@
70 description=('Extensions to the Python standard library unit testing '
71 'framework'),
72 long_description=get_long_description(),
73- version=version,
74+ version=get_version(),
75 classifiers=["License :: OSI Approved :: MIT License"],
76 packages=['testtools', 'testtools.testresult', 'testtools.tests'])

Subscribers

People subscribed via source and target branches