2010-03-31 04:19:36 +02:00
#!/usr/bin/env python
""" Distutils installer for testtools. """
from distutils . core import setup
2010-12-09 14:51:17 +01:00
import email
import os
2010-03-31 04:19:36 +02:00
import testtools
2010-12-09 14:51:17 +01:00
def get_revno ( ) :
2011-08-27 16:07:25 +02:00
import bzrlib . errors
2010-03-31 04:19:36 +02:00
import bzrlib . workingtree
2011-08-27 16:07:25 +02:00
try :
t = bzrlib . workingtree . WorkingTree . open_containing ( __file__ ) [ 0 ]
except ( bzrlib . errors . NotBranchError , bzrlib . errors . NoWorkingTree ) :
return None
else :
return t . branch . revno ( )
2010-12-09 14:51:17 +01:00
def get_version_from_pkg_info ( ) :
""" Get the version from PKG-INFO file if we can. """
pkg_info_path = os . path . join ( os . path . dirname ( __file__ ) , ' PKG-INFO ' )
try :
pkg_info_file = open ( pkg_info_path , ' r ' )
except ( IOError , OSError ) :
return None
try :
pkg_info = email . message_from_file ( pkg_info_file )
except email . MessageError :
return None
return pkg_info . get ( ' Version ' , None )
def get_version ( ) :
""" Return the version of testtools that we are building. """
version = ' . ' . join (
str ( component ) for component in testtools . __version__ [ 0 : 3 ] )
phase = testtools . __version__ [ 3 ]
if phase == ' final ' :
return version
pkg_info_version = get_version_from_pkg_info ( )
if pkg_info_version :
return pkg_info_version
revno = get_revno ( )
2011-08-27 16:07:25 +02:00
if revno is None :
2011-12-08 21:21:59 +01:00
# Apparently if we just say "snapshot" then distribute won't accept it
# as satisfying versioned dependencies. This is a problem for the
# daily build version.
return " snapshot- %s " % ( version , )
2010-03-31 04:19:36 +02:00
if phase == ' alpha ' :
# No idea what the next version will be
2010-12-09 14:51:17 +01:00
return ' next-r %s ' % revno
2010-03-31 04:19:36 +02:00
else :
# Preserve the version number but give it a revno prefix
2010-12-09 14:51:17 +01:00
return version + ' -r %s ' % revno
def get_long_description ( ) :
2011-08-27 16:07:25 +02:00
manual_path = os . path . join (
os . path . dirname ( __file__ ) , ' doc/overview.rst ' )
2010-12-09 14:51:17 +01:00
return open ( manual_path ) . read ( )
2010-03-31 04:19:36 +02:00
setup ( name = ' testtools ' ,
author = ' Jonathan M. Lange ' ,
author_email = ' jml+testtools@mumak.net ' ,
url = ' https://launchpad.net/testtools ' ,
description = ( ' Extensions to the Python standard library unit testing '
' framework ' ) ,
2010-12-09 14:51:17 +01:00
long_description = get_long_description ( ) ,
version = get_version ( ) ,
2012-12-26 22:11:04 +01:00
classifiers = [ " License :: OSI Approved :: MIT License " ,
" Programming Language :: Python :: 3 " ,
] ,
2012-11-14 09:46:53 +01:00
packages = [
' testtools ' ,
' testtools.matchers ' ,
' testtools.testresult ' ,
' testtools.tests ' ,
' testtools.tests.matchers ' ,
] ,
cmdclass = { ' test ' : testtools . TestCommand } ,
zip_safe = False )