forked from airspeed-velocity/asv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·159 lines (125 loc) · 3.96 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env python
import ez_setup
ez_setup.use_setuptools()
from setuptools import setup
from setuptools.command.test import test as TestCommand
import os
import subprocess
import sys
# A py.test test command
class PyTest(TestCommand):
user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]
def initialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = []
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = ['test']
self.test_suite = True
def run_tests(self):
import pytest
errno = pytest.main(self.test_args)
sys.exit(errno)
basedir = os.path.abspath(os.path.dirname(__file__))
def get_git_hash():
"""
Get version from asv/__init__.py and generate asv/_version.py
"""
# Obtain git revision
githash = ""
if os.path.isdir(os.path.join(basedir, '.git')):
try:
proc = subprocess.Popen(
['git', '-C', basedir, 'rev-parse', 'HEAD'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
rev, err = proc.communicate()
if proc.returncode == 0:
githash = rev.strip().decode('ascii')
except OSError:
pass
return githash
def get_git_revision():
"""
Get the number of revisions since the last tag.
"""
revision = "0"
if os.path.isdir(os.path.join(basedir, '.git')):
try:
proc = subprocess.Popen(
['git', '-C', basedir, 'rev-list', '--count', 'HEAD'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
rev, err = proc.communicate()
if proc.returncode == 0:
revision = rev.strip().decode('ascii')
except OSError:
pass
return revision
def write_version_file(filename, version, revision):
# Write revision file (only if it needs to be changed)
content = '''
__version__ = "{0}"
__githash__ = "{1}"
__release__ = {2}
'''.format(version, revision, 'dev' in version)
old_content = None
if os.path.isfile(filename):
with open(filename, 'r') as f:
old_content = f.read()
if content != old_content:
with open(filename, 'w') as f:
f.write(content)
version = '0.2.dev'
git_hash = get_git_hash()
# Indicates if this version is a release version
release = 'dev' not in version
if not release:
version = '{0}{1}+{2}'.format(
version, get_git_revision(), git_hash[:8])
write_version_file(
os.path.join(basedir, 'asv', '_version.py'), version, git_hash)
# Install entry points for making releases with zest.releaser
entry_points = {}
for hook in [('releaser', 'middle'), ('postreleaser', 'before')]:
hook_ep = 'zest.releaser.' + '.'.join(hook)
hook_name = 'asv.release.' + '.'.join(hook)
hook_func = 'asv._release:' + '_'.join(hook)
entry_points[hook_ep] = ['%s = %s' % (hook_name, hook_func)]
entry_points['console_scripts'] = ['asv = asv.main:main']
setup(
name="asv",
version=version,
packages=['asv',
'asv.commands',
'asv.plugins',
'asv.extern',
'asv._release'],
entry_points=entry_points,
install_requires=[
str('six>=1.4')
],
extras_require={
str('hg'): ["python-hglib>=1.5"]
},
package_data={
str('asv'): [
'www/*.html',
'www/*.js',
'www/*.css',
'www/*.png',
'www/*.ico',
'www/flot/*.js',
'template/__init__.py',
'template/asv.conf.json',
'template/benchmarks/*.py'
]
},
zip_safe=False,
# py.test testing
tests_require=['pytest'],
cmdclass={'test': PyTest},
author="Michael Droettboom",
author_email="mdroe@stsci.edu",
description="Airspeed Velocity: A simple Python history benchmarking tool",
license="BSD",
url="http://github.com/spacetelescope/asv"
)