forked from python-versioneer/python-versioneer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·184 lines (159 loc) · 6.29 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env python
import os, base64, tempfile, io
from os import path
from setuptools import setup, Command
from distutils.command.build_scripts import build_scripts
from setuptools.dist import Distribution as _Distribution
LONG="""
Versioneer is a tool to automatically update version strings (in setup.py and
the conventional 'from PROJECT import _version' pattern) by asking your
version-control system about the current tree.
"""
# as nice as it'd be to versioneer ourselves, that sounds messy.
VERSION = "0.15+dev"
def ver(s):
return s.replace("@VERSIONEER-VERSION@", VERSION)
def get(fn, add_ver=False, unquote=False, do_strip=False, do_readme=False):
with open(fn) as f:
text = f.read()
# If we're in Python <3 and have a separate Unicode type, we would've
# read a non-unicode string. Else, all strings will be unicode strings.
try:
__builtins__.unicode
except AttributeError:
pass
else:
text = text.decode('ASCII')
if add_ver:
text = ver(text)
if unquote:
text = text.replace("%", "%%")
if do_strip:
lines = [line for line in text.split("\n")
if not line.endswith("# --STRIP DURING BUILD")]
text = "\n".join(lines)
if do_readme:
text = text.replace("@README@", get("README.md"))
return text
def u(s): # so u("foo") yields unicode on all of py2.6/py2.7/py3.2/py3.3
return s.encode("ascii").decode("ascii")
def get_vcs_list():
project_path = path.join(path.abspath(path.dirname(__file__)), 'src')
return [filename
for filename
in os.listdir(project_path)
if path.isdir(path.join(project_path, filename))]
def generate_long_version_py(VCS):
s = io.StringIO()
s.write(get("src/%s/long_header.py" % VCS, add_ver=True, do_strip=True))
for piece in ["src/subprocess_helper.py",
"src/from_parentdir.py",
"src/%s/from_keywords.py" % VCS,
"src/%s/from_vcs.py" % VCS,
"src/render.py",
"src/%s/long_get_versions.py" % VCS]:
s.write(get(piece, unquote=True, do_strip=True))
return s.getvalue()
def generate_versioneer_py():
s = io.StringIO()
s.write(get("src/header.py", add_ver=True, do_readme=True))
s.write(get("src/subprocess_helper.py", do_strip=True))
for VCS in get_vcs_list():
s.write(u("LONG_VERSION_PY['%s'] = '''\n" % VCS))
s.write(generate_long_version_py(VCS))
s.write(u("'''\n"))
s.write(get("src/%s/from_keywords.py" % VCS, do_strip=True))
s.write(get("src/%s/from_vcs.py" % VCS, do_strip=True))
s.write(get("src/%s/install.py" % VCS, do_strip=True))
s.write(get("src/from_parentdir.py", do_strip=True))
s.write(get("src/from_file.py", add_ver=True, do_strip=True))
s.write(get("src/render.py", do_strip=True))
s.write(get("src/get_versions.py", do_strip=True))
s.write(get("src/cmdclass.py", do_strip=True))
s.write(get("src/setupfunc.py", do_strip=True))
return s.getvalue().encode("utf-8")
class make_versioneer(Command):
description = "create standalone versioneer.py"
user_options = []
boolean_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
with open("versioneer.py", "w") as f:
f.write(generate_versioneer_py().decode("utf8"))
return 0
class make_long_version_py_git(Command):
description = "create standalone _version.py (for git)"
user_options = []
boolean_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
assert os.path.exists("versioneer.py")
long_version = generate_long_version_py("git")
with open("git_version.py", "w") as f:
f.write(long_version %
{"DOLLAR": "$",
"STYLE": "pep440",
"TAG_PREFIX": "tag-",
"PARENTDIR_PREFIX": "parentdir_prefix",
"VERSIONFILE_SOURCE": "versionfile_source",
})
return 0
class my_build_scripts(build_scripts):
def run(self):
v = generate_versioneer_py()
v_b64 = base64.b64encode(v).decode("ascii")
lines = [v_b64[i:i+60] for i in range(0, len(v_b64), 60)]
v_b64 = "\n".join(lines)+"\n"
with open("src/installer.py") as f:
s = f.read()
s = ver(s.replace("@VERSIONEER-INSTALLER@", v_b64))
tempdir = tempfile.mkdtemp()
installer = os.path.join(tempdir, "versioneer")
with open(installer, "w") as f:
f.write(s)
self.scripts = [installer]
rc = build_scripts.run(self)
os.unlink(installer)
os.rmdir(tempdir)
return rc
# python's distutils treats module-less packages as binary-specific (not
# "pure"), so "setup.py bdist_wheel" creates binary-specific wheels. Override
# this so we get cross-platform wheels instead. More info at:
# https://bitbucket.org/pypa/wheel/issue/116/packages-with-only-filesdata_files-get
class Distribution(_Distribution):
def is_pure(self): return True
setup(
name = "versioneer",
license = "public domain",
version = VERSION,
description = "Easy VCS-based management of project version strings",
author = "Brian Warner",
author_email = "[email protected]",
url = "https://github.com/warner/python-versioneer",
# "fake" is replaced with versioneer-installer in build_scripts. We need
# a non-empty list to provoke "setup.py build" into making scripts,
# otherwise it skips that step.
scripts = ["fake"],
long_description = LONG,
distclass=Distribution,
cmdclass = { "build_scripts": my_build_scripts,
"make_versioneer": make_versioneer,
"make_long_version_py_git": make_long_version_py_git,
},
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
],
)