-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·87 lines (78 loc) · 2.76 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
#!/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
VERSION_PY_FILENAME = 'coma/_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__ = '{}'
"""
NOT_IN_PATH_MESSAGE = '''
Installed the coma script to "{}".
However, this directory does not seem to be in your path. To
conveniently call the coma script on the command line, add
export PATH="{}:$PATH"
to your "~/.bashrc" and restart your terminal.'''
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()
setup(name='coma',
version=get_version(),
description='The computational condensed matter physics programming toolkit.',
author='Burkhard Ritter',
author_email='[email protected]',
license='BSD',
url='https://bitbucket.org/meznom/coma',
packages=['coma','coma.test'],
cmdclass={'version': Version}
)