1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#!/usr/bin/env python
import re, sys, subprocess
from distutils.core import setup, Command
from distutils.command.sdist import sdist as _sdist
class Test(Command):
description = "run unit tests"
user_options = []
boolean_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
for t in ["ecdsa/numbertheory.py",
"ecdsa/ellipticcurve.py",
"ecdsa/ecdsa.py",
"ecdsa/test_pyecdsa.py",
]:
rc = self.do_test(t)
if rc != 0:
sys.exit(rc)
def do_test(self, which):
print "======= running %s" % which
p = subprocess.Popen([sys.executable, which])
rc = p.wait()
if rc != 0:
print >>sys.stderr, "Test (%s) FAILED" % which
print "== finished %s" % which
return rc
VERSION_PY = """
# This file is originally generated from Git information by running 'setup.py
# version'. Distribution tarballs contain a pre-generated copy of this file.
__version__ = '%s'
"""
def update_version_py():
try:
ver = subprocess.Popen(["git", "describe", "--dirty", "--always"],
stdout=subprocess.PIPE,
).communicate()[0]
# we use tags like "python-ecdsa-0.5", so strip the prefix
assert ver.startswith("python-ecdsa-")
ver = ver[len("python-ecdsa-"):].strip()
f = open("ecdsa/_version.py", "w")
f.write(VERSION_PY % ver)
f.close()
print "set ecdsa/_version.py to '%s'" % ver
except IndexError:
print "unable to run git, leaving ecdsa/_version.py alone"
def get_version():
try:
f = open("ecdsa/_version.py")
except EnvironmentError:
return None
for line in f.readlines():
mo = re.match("__version__ = '([^']+)'", line)
if mo:
ver = mo.group(1)
return ver
return None
class Version(Command):
description = "update _version.py from Git repo"
user_options = []
boolean_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
update_version_py()
class sdist(_sdist):
def run(self):
update_version_py()
return _sdist.run(self)
setup(name="ecdsa",
version=get_version(),
description="ECDSA cryptographic signature library (pure python)",
author="Brian Warner",
author_email="warner-pyecdsa@lothar.com",
url="http://github.com/warner/python-ecdsa",
packages=["ecdsa"],
license="MIT",
cmdclass={ "test": Test, "version": Version, "sdist": sdist },
)
|