-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·98 lines (88 loc) · 3.1 KB
/
setup.py
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
94
95
96
97
98
#!/usr/bin/env python
# This is largely taken from the python-ecdsa project,
# https://github.com/warner/python-ecdsa.
import os, sys, subprocess, re
from distutils.core import setup, Command, Extension
from distutils.command.sdist import sdist as _sdist
from distutils.command.install import install as _install
VERSION_PY_FILENAME = 'qca/_version.py'
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__ = '{}'
"""
def update_version_py():
"""Update version file with version from Git.
Constructs semver.org compatible version strings, provided that the Git tag
is already a semver.org compatible version. The number of commits since the
last tag and the abbreviated commit hash are appended as a pre-release
version. An example: 2.0.0-25.gf52f551.
"""
ver = 'unknown'
try:
p = subprocess.Popen(["git", "describe", "--dirty", "--always"],
stdout=subprocess.PIPE)
stdout = p.communicate()[0]
if p.returncode != 0:
print('unable to run git')
else:
# Git describe returns one or more strings separated by a dash
s = stdout.strip()
fs = s.split('-')
ver = fs[0]
if len(fs) > 1:
ver += '-' + '.'.join(fs[1:])
except EnvironmentError:
print('unable to run git')
if os.path.exists(VERSION_PY_FILENAME) and ver == 'unknown':
return
f = open(VERSION_PY_FILENAME, "w")
f.write(VERSION_PY.format(ver))
f.close()
print('set {} to "{}"'.format(VERSION_PY_FILENAME, ver))
def get_version():
try:
f = open(VERSION_PY_FILENAME)
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()
print 'Version is now', get_version()
class sdist(_sdist):
def run(self):
update_version_py()
# unless we update this, the sdist command will keep using the old
# version
self.distribution.metadata.version = get_version()
return _sdist.run(self)
class install(_install):
def run(self):
update_version_py()
# unless we update this, the sdist command will keep using the old
# version
self.distribution.metadata.version = get_version()
return _install.run(self)
setup(name='qca',
version=get_version(),
description='QCA exact diagonalization.',
author='Burkhard Ritter',
author_email='burkhard@ualberta.ca',
url='',
packages=['qca','qca.test'],
package_data={'qca': ['_qca.so']},
cmdclass={ 'version': Version, 'sdist': sdist, 'install': install}
)