~bzr/ubuntu/hardy/python-testtools/bzr-ppa

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Max Bowsher
  • Date: 2010-12-18 13:57:02 UTC
  • mfrom: (27.1.1 jaunty)
  • Revision ID: maxb@f2s.com-20101218135702-2rzgh1qrq1210kt5
Tags: 0.9.8-1~bazaar1~hardy1
New upstream release. Closes: #606479

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
"""Distutils installer for testtools."""
3
3
 
4
4
from distutils.core import setup
 
5
import email
 
6
import os
 
7
 
5
8
import testtools
6
 
version = '.'.join(str(component) for component in testtools.__version__[0:3])
7
 
phase = testtools.__version__[3]
8
 
if phase != 'final':
 
9
 
 
10
 
 
11
def get_revno():
9
12
    import bzrlib.workingtree
10
13
    t = bzrlib.workingtree.WorkingTree.open_containing(__file__)[0]
 
14
    return t.branch.revno()
 
15
 
 
16
 
 
17
def get_version_from_pkg_info():
 
18
    """Get the version from PKG-INFO file if we can."""
 
19
    pkg_info_path = os.path.join(os.path.dirname(__file__), 'PKG-INFO')
 
20
    try:
 
21
        pkg_info_file = open(pkg_info_path, 'r')
 
22
    except (IOError, OSError):
 
23
        return None
 
24
    try:
 
25
        pkg_info = email.message_from_file(pkg_info_file)
 
26
    except email.MessageError:
 
27
        return None
 
28
    return pkg_info.get('Version', None)
 
29
 
 
30
 
 
31
def get_version():
 
32
    """Return the version of testtools that we are building."""
 
33
    version = '.'.join(
 
34
        str(component) for component in testtools.__version__[0:3])
 
35
    phase = testtools.__version__[3]
 
36
    if phase == 'final':
 
37
        return version
 
38
    pkg_info_version = get_version_from_pkg_info()
 
39
    if pkg_info_version:
 
40
        return pkg_info_version
 
41
    revno = get_revno()
11
42
    if phase == 'alpha':
12
43
        # No idea what the next version will be
13
 
        version = 'next-%s' % t.branch.revno()
 
44
        return 'next-r%s' % revno
14
45
    else:
15
46
        # Preserve the version number but give it a revno prefix
16
 
        version = version + '~%s' % t.branch.revno()
 
47
        return version + '-r%s' % revno
 
48
 
 
49
 
 
50
def get_long_description():
 
51
    manual_path = os.path.join(os.path.dirname(__file__), 'MANUAL')
 
52
    return open(manual_path).read()
 
53
 
17
54
 
18
55
setup(name='testtools',
19
56
      author='Jonathan M. Lange',
21
58
      url='https://launchpad.net/testtools',
22
59
      description=('Extensions to the Python standard library unit testing '
23
60
                   'framework'),
24
 
      version=version,
 
61
      long_description=get_long_description(),
 
62
      version=get_version(),
 
63
      classifiers=["License :: OSI Approved :: MIT License"],
25
64
      packages=['testtools', 'testtools.testresult', 'testtools.tests'])