setup.py: use setuptools, modify get_version() (#7496)
get_version() depends only on git now.
This commit is contained in:
parent
110445b739
commit
d2704c4929
|
@ -1,2 +1,4 @@
|
|||
recursive-include debian *
|
||||
recursive-include tests *.py
|
||||
include VERSION
|
||||
include README.txt
|
||||
|
|
107
setup.py
107
setup.py
|
@ -4,16 +4,20 @@
|
|||
Setup script for eopayment
|
||||
'''
|
||||
|
||||
import subprocess
|
||||
import distutils
|
||||
import distutils.core
|
||||
import setuptools
|
||||
from distutils.command.sdist import sdist
|
||||
from glob import glob
|
||||
from os.path import splitext, basename, join as pjoin
|
||||
import os
|
||||
from unittest import TextTestRunner, TestLoader
|
||||
import doctest
|
||||
|
||||
|
||||
class TestCommand(distutils.core.Command):
|
||||
user_options = [ ]
|
||||
user_options = []
|
||||
|
||||
def initialize_options(self):
|
||||
self._dir = os.getcwd()
|
||||
|
@ -25,7 +29,7 @@ class TestCommand(distutils.core.Command):
|
|||
'''
|
||||
Finds all the tests modules in tests/, and runs them.
|
||||
'''
|
||||
testfiles = [ ]
|
||||
testfiles = []
|
||||
for t in glob(pjoin(self._dir, 'tests', '*.py')):
|
||||
if not t.endswith('__init__.py'):
|
||||
testfiles.append('.'.join(
|
||||
|
@ -35,55 +39,62 @@ class TestCommand(distutils.core.Command):
|
|||
tests = TestLoader().loadTestsFromNames(testfiles)
|
||||
import eopayment
|
||||
tests.addTests(doctest.DocTestSuite(eopayment))
|
||||
t = TextTestRunner(verbosity = 4)
|
||||
t = TextTestRunner(verbosity=4)
|
||||
t.run(tests)
|
||||
|
||||
|
||||
class eo_sdist(sdist):
|
||||
|
||||
def run(self):
|
||||
print "creating VERSION file"
|
||||
if os.path.exists('VERSION'):
|
||||
os.remove('VERSION')
|
||||
version = get_version()
|
||||
version_file = open('VERSION', 'w')
|
||||
version_file.write(version)
|
||||
version_file.close()
|
||||
sdist.run(self)
|
||||
print "removing VERSION file"
|
||||
if os.path.exists('VERSION'):
|
||||
os.remove('VERSION')
|
||||
|
||||
|
||||
def get_version():
|
||||
import glob
|
||||
import re
|
||||
import os
|
||||
|
||||
version = None
|
||||
for d in glob.glob('*'):
|
||||
if not os.path.isdir(d):
|
||||
continue
|
||||
module_file = os.path.join(d, '__init__.py')
|
||||
if not os.path.exists(module_file):
|
||||
continue
|
||||
for v in re.findall("""__version__ *= *['"](.*)['"]""",
|
||||
open(module_file).read()):
|
||||
assert version is None
|
||||
version = v
|
||||
if version:
|
||||
break
|
||||
assert version is not None
|
||||
'''Use the VERSION, if absent generates a version with git describe, if not
|
||||
tag exists, take 0.0.0- and add the length of the commit log.
|
||||
'''
|
||||
if os.path.exists('VERSION'):
|
||||
with open('VERSION', 'r') as v:
|
||||
return v.read()
|
||||
if os.path.exists('.git'):
|
||||
import subprocess
|
||||
p = subprocess.Popen(['git','describe','--dirty','--match=v*'],
|
||||
stdout=subprocess.PIPE)
|
||||
p = subprocess.Popen(['git', 'describe', '--dirty',
|
||||
'--match=v*'], stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
result = p.communicate()[0]
|
||||
assert p.returncode == 0, 'git returned non-zero'
|
||||
new_version = result.split()[0][1:]
|
||||
assert not new_version.endswith('-dirty'), 'git workdir is not clean'
|
||||
assert new_version.split('-')[0] == version, '__version__ must match the last git annotated tag'
|
||||
version = new_version.replace('-', '.')
|
||||
return version
|
||||
if p.returncode == 0:
|
||||
return result.split()[0][1:].replace('-', '.').replace('.g', '+g')
|
||||
else:
|
||||
return '0.0.0+%s' % len(
|
||||
subprocess.check_output(
|
||||
['git', 'rev-list', 'HEAD']).splitlines())
|
||||
return '0.0.0'
|
||||
|
||||
distutils.core.setup(name='eopayment',
|
||||
version=get_version(),
|
||||
license='GPLv3 or later',
|
||||
description='Common API to use all French online payment credit card processing services',
|
||||
long_description=
|
||||
"eopayment is a Python module to interface with French's bank credit card\n"
|
||||
"online payment services. Supported services are ATOS/SIP, SystemPay, and\n"
|
||||
"SPPLUS.",
|
||||
url='http://dev.entrouvert.org/projects/eopayment/',
|
||||
author="Entr'ouvert",
|
||||
author_email="info@entrouvert.com",
|
||||
maintainer="Benjamin Dauvergne",
|
||||
maintainer_email="bdauvergne@entrouvert.com",
|
||||
packages=['eopayment'],
|
||||
install_requires=[
|
||||
'pycrypto >= 2.5'
|
||||
],
|
||||
cmdclass={'test': TestCommand})
|
||||
setuptools.setup(
|
||||
name='eopayment',
|
||||
version=get_version(),
|
||||
license='GPLv3 or later',
|
||||
description='Common API to use all French online payment credit card '
|
||||
'processing services',
|
||||
long_description='eopayment is a Python module to interface with '
|
||||
'French\'s bank credit card online payment services. Supported '
|
||||
'services are ATOS/SIP, SystemPay, and SPPLUS.',
|
||||
url='http://dev.entrouvert.org/projects/eopayment/',
|
||||
author="Entr'ouvert",
|
||||
author_email="info@entrouvert.com",
|
||||
maintainer="Benjamin Dauvergne",
|
||||
maintainer_email="bdauvergne@entrouvert.com",
|
||||
packages=['eopayment'],
|
||||
install_requires=[
|
||||
'pycrypto >= 2.5'
|
||||
],
|
||||
cmdclass={'test': TestCommand, 'sdist': eo_sdist})
|
||||
|
|
Loading…
Reference in New Issue