-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsetup.py
More file actions
117 lines (99 loc) · 2.95 KB
/
setup.py
File metadata and controls
117 lines (99 loc) · 2.95 KB
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
import os
import subprocess
import re
import sys
from setuptools import find_packages, setup, Command
root = os.path.dirname(__file__)
VERSION_PY_PATH = os.path.join(root, 'chiptools', 'core', '_version.py')
VERSION_PY = """
# This file was generated by running 'setup.py version'
# Any edits you make to this file will be lost!
__version__ = '%(major)s.%(minor)s.%(commit)s'
"""
def matchVal(x, grouipid=1):
return 0 if x is None else x.group(grouipid)
def getGitVersion():
if not os.path.isdir('.git'):
print("This is not a GIT repository")
return
try:
process = subprocess.Popen(
['git', 'describe', '--tags', '--dirty', '--always'],
stdout=subprocess.PIPE
)
except EnvironmentError:
print(
'Unable to run git, leaving {0} alone.'.format([VERSION_PY_PATH])
)
stdout = process.communicate()[0]
version = str(stdout.strip().decode('utf-8'))
if process.returncode != 0:
print(
'Unable to run git, leaving {0} alone.'.format([VERSION_PY_PATH])
)
return
major = matchVal(re.search('v(\\d+)\\.', version))
minor = matchVal(re.search('v\\d+\\.(\\d+)', version))
commit = matchVal(re.search('v\\d+\\.\\d+-(\\d+)-', version))
with open(VERSION_PY_PATH, 'w') as f:
f.write(
VERSION_PY % dict(
major=major,
minor=minor,
commit=commit,
)
)
print('Set {0} to {1}'.format(VERSION_PY_PATH, version))
class Version(Command):
description = "update _version.py from the Git repository"
user_options = []
boolean_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
getGitVersion()
print("Version is now", getVersion())
def getVersion():
try:
with open(VERSION_PY_PATH) as f:
for line in f.readlines():
match = re.match("__version__ = '([^']+)'", line)
if match:
ver = match.group(1)
return ver
except EnvironmentError:
return None
requires = []
extras_require = {
# Environment Marker works for wheel 0.24 or later
':sys_platform=="win32"': [
'colorama',
],
}
# for sdist installation with pip-1.5.6
if sys.platform == 'win32':
requires.append('colorama')
setup(
name="ChipTools",
version=getVersion(),
description=(
"ChipTools is a utility to automate FPGA build and verification"
),
author="Peter Bennett",
author_email="pab850@gmail.com",
zip_safe=False,
include_package_data=True,
platforms='any',
packages=find_packages(exclude=['tests']),
entry_points={
'console_scripts': [
'chiptools=chiptools.chiptools_main:main',
],
},
license="",
cmdclass={"version": Version},
extras_require=extras_require,
install_requires=requires,
)