forked from scipy/scipy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pavement.py
288 lines (232 loc) · 8.52 KB
/
pavement.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
"""
This paver file is intended to help with the release process, and build sdist,
documentation, release notes, and generate checksums for them.
For details on the release process, see
http://scipy.github.io/devdocs/dev/core-dev/index.html#making-a-scipy-release
Building changelog + notes
==========================
Assumes you have git and the binaries/tarballs in installers/::
paver write_release_and_log
This automatically puts the checksum into NOTES.txt and writes the Changelog,
which can be uploaded to Github Releases.
"""
import os
import sys
import subprocess
import re
import shutil
import warnings
from hashlib import md5
from hashlib import sha256
try:
from paver.tasks import VERSION as _PVER
if not _PVER >= '1.0':
raise RuntimeError("paver version >= 1.0 required (was %s)" % _PVER)
except ImportError as e:
raise RuntimeError("paver version >= 1.0 required") from e
import paver
import paver.doctools
import paver.path
from paver.easy import options, Bunch, task, needs, dry, sh, call_task, cmdopts
sys.path.insert(0, os.path.dirname(__file__))
try:
setup_py = __import__("setup")
FULLVERSION = setup_py.VERSION
# This is duplicated from setup.py
if os.path.exists('.git'):
GIT_REVISION = setup_py.git_version()
else:
GIT_REVISION = "Unknown"
if not setup_py.ISRELEASED:
if GIT_REVISION == "Unknown":
FULLVERSION += '.dev0+Unknown'
else:
FULLVERSION += '.dev0+' + GIT_REVISION[:7]
finally:
sys.path.pop(0)
try:
# Ensure sensible file permissions
os.umask(0o022)
except AttributeError:
# No umask on non-posix
pass
#-----------------------------------
# Things to be changed for a release
#-----------------------------------
# Source of the release notes
RELEASE = 'doc/release/1.7.0-notes.rst'
# Start/end of the log (from git)
LOG_START = 'v1.6.0'
LOG_END = 'master'
#-------------------------------------------------------
# Hardcoded build/install dirs, virtualenv options, etc.
#-------------------------------------------------------
# Default Python version
PYVER="3.6"
# Paver options object, holds all default dirs
options(bootstrap=Bunch(bootstrap_dir="bootstrap"),
virtualenv=Bunch(packages_to_install=["sphinx==1.8.5", "numpydoc"],
no_site_packages=False),
sphinx=Bunch(builddir="build", sourcedir="source", docroot='doc'),
superpack=Bunch(builddir="build-superpack",
bindir=os.path.join("build-superpack","binaries")),
installers=Bunch(releasedir="release",
installersdir=os.path.join("release", "installers")),
doc=Bunch(doc_root="doc",
sdir=os.path.join("doc", "source"),
bdir=os.path.join("doc", "build"),
bdir_latex=os.path.join("doc", "build", "latex"),
destdir_pdf=os.path.join("build_doc", "pdf")),
html=Bunch(builddir=os.path.join("build", "html")),
dmg=Bunch(python_version=PYVER),
bdist_wininst_simple=Bunch(python_version=PYVER),)
#--------------------
# Documentation tasks
#--------------------
@task
def html(options):
"""Build SciPy documentation and put it into build/docs"""
# Don't use paver html target because of scipy bootstrapping problems
subprocess.check_call(["make", "html"], cwd="doc")
builtdocs = paver.path.path("doc") / options.sphinx.builddir / "html"
options.html.builddir.rmtree()
builtdocs.copytree(options.html.builddir)
@task
def latex():
"""Build SciPy documentation in latex format."""
subprocess.check_call(["make", "latex"], cwd="doc")
@task
@needs('latex')
def pdf():
bdir_latex = options.doc.bdir_latex
destdir_pdf = options.doc.destdir_pdf
def build_pdf():
subprocess.check_call(["make", "all-pdf"], cwd=str(bdir_latex))
dry("Build pdf doc", build_pdf)
if os.path.exists(destdir_pdf):
shutil.rmtree(destdir_pdf)
os.makedirs(destdir_pdf)
ref = os.path.join(bdir_latex, "scipy-ref.pdf")
shutil.copy(ref, os.path.join(destdir_pdf, "reference.pdf"))
def tarball_name(type='gztar'):
root = 'scipy-%s' % FULLVERSION
if type == 'gztar':
return root + '.tar.gz'
elif type == 'xztar':
return root + '.tar.xz'
elif type == 'tar':
return root + '.tar'
elif type == 'zip':
return root + '.zip'
raise ValueError("Unknown type %s" % type)
@task
def sdist():
# First, clean the repo and update submodules (for up-to-date doc html theme
# and Sphinx extensions)
sh('git clean -xdf')
sh('git submodule init')
sh('git submodule update')
# Fix file permissions
sh('chmod -R a+rX *')
# To be sure to bypass paver when building sdist... paver + scipy.distutils
# do not play well together.
# Cython is run over all Cython files in setup.py, so generated C files
# will be included.
sh('python setup.py sdist --formats=gztar,zip')
sh('python setup.py sdist --formats=tar')
if os.path.exists(os.path.join('dist', tarball_name("xztar"))):
os.unlink(os.path.join('dist', tarball_name("xztar")))
sh('xz %s' % os.path.join('dist', tarball_name("tar")), ignore_error=True)
# Copy the sdists into installers dir
if not os.path.exists(options.installers.installersdir):
os.makedirs(options.installers.installersdir)
if not os.path.exists(os.path.join('dist', tarball_name("xztar"))):
warnings.warn("Could not create tar.xz! Do you have xz installed?")
else:
t = 'xztar'
source = os.path.join('dist', tarball_name(t))
target = os.path.join(options.installers.installersdir, tarball_name(t))
shutil.copy(source, target)
for t in ['gztar', 'zip']:
source = os.path.join('dist', tarball_name(t))
target = os.path.join(options.installers.installersdir, tarball_name(t))
shutil.copy(source, target)
@task
def release(options):
"""sdists, release notes and changelog. Docs and wheels are built in
separate steps (see doc/source/dev/releasing.rst).
"""
# Source tarballs
sdist()
# README (gpg signed) and Changelog
write_release_and_log()
#----------------------------
# Release notes and Changelog
#----------------------------
def compute_md5(idirs):
released = paver.path.path(idirs).listdir()
checksums = []
for fn in sorted(released):
with open(fn, 'rb') as f:
m = md5(f.read())
checksums.append('%s %s' % (m.hexdigest(), os.path.basename(f)))
return checksums
def compute_sha256(idirs):
# better checksum so gpg signed README.txt containing the sums can be used
# to verify the binaries instead of signing all binaries
released = paver.path.path(idirs).listdir()
checksums = []
for fn in sorted(released):
with open(fn, 'rb') as f:
m = sha256(f.read())
checksums.append('%s %s' % (m.hexdigest(), os.path.basename(f)))
return checksums
def write_release_task(options, filename='NOTES.txt'):
idirs = options.installers.installersdir
source = paver.path.path(RELEASE)
target = paver.path.path(filename)
if target.exists():
target.remove()
tmp_target = paver.path.path(filename + '.tmp')
source.copy(tmp_target)
with open(str(tmp_target), 'a') as ftarget:
ftarget.writelines("""
Checksums
=========
MD5
~~~
""")
ftarget.writelines(['%s\n' % c for c in compute_md5(idirs)])
ftarget.writelines("""
SHA256
~~~~~~
""")
ftarget.writelines(['%s\n' % c for c in compute_sha256(idirs)])
# Sign release; on some platforms gpg2 may actually
# be named gpg
cmd = ['gpg2', '--clearsign', '--armor']
if hasattr(options, 'gpg_key'):
cmd += ['--default-key', options.gpg_key]
cmd += ['--output', str(target), str(tmp_target)]
subprocess.check_call(cmd)
print("signed %s" % (target,))
tmp_target.remove()
def write_log_task(filename='Changelog'):
st = subprocess.Popen(
['git', 'log', '%s..%s' % (LOG_START, LOG_END)],
stdout=subprocess.PIPE)
out = st.communicate()[0].decode()
with open(filename, 'w') as a:
a.writelines(out)
@task
@cmdopts([('gpg_key=', 'g', 'GPG key to use for signing')])
def write_release(options):
write_release_task(options)
@task
def write_log():
write_log_task()
@task
@cmdopts([('gpg_key=', 'g', 'GPG key to use for signing')])
def write_release_and_log(options):
write_release_task(options, os.path.join(options.installers.releasedir, 'README'))
write_log_task(os.path.join(options.installers.releasedir, 'Changelog'))