forked from desihub/desitarget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·79 lines (68 loc) · 2.13 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
#!/usr/bin/env python
import glob
import os
import re
from subprocess import Popen, PIPE
from setuptools import setup, Command, find_packages
def update_version_py():
if not os.path.isdir(".git"):
print "This is not a git repository."
return
try:
p = Popen(["git", "describe", "--tags", "--dirty", "--always"], stdout=PIPE)
except EnvironmentError:
print "unable to run git, leaving py/desitarget/_version.py alone"
return
out = p.communicate()[0]
ver = out.rstrip()
if p.returncode != 0:
print "unable to run git, leaving py/desitarget/_version.py alone"
return
f = open("py/desitarget/_version.py", "w")
f.write( '__version__ = \'{}\''.format( ver ) )
f.close()
print "Set py/desitarget/_version.py to {}".format( ver )
def get_version():
if not os.path.isfile("py/desitarget/_version.py"):
print 'Creating initial version file'
update_version_py()
ver = 'unknown'
f = open("py/desitarget/_version.py", "r")
for line in f.readlines():
mo = re.match("__version__ = '(.*)'", line)
if mo:
ver = mo.group(1)
f.close()
return ver
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()
ver = get_version()
print "Version is now {}".format( ver )
current_version = get_version()
setup (
name='desitarget',
provides='desitarget',
version=current_version,
description='DESI Targeting',
author='DESI Collaboration',
author_email='[email protected]',
url='https://github.com/desihub/desitarget',
package_dir={'':'py'},
packages=find_packages('py'),
scripts=[ fname for fname in glob.glob(os.path.join('bin', '*')) ],
license='BSD',
requires=['Python (>2.7.0)', ],
use_2to3=True,
zip_safe=False,
cmdclass={'version': Version},
test_suite='desitarget.test.test_suite',
package_data = {'desitarget': ['targetmask.yaml',]}
)