forked from numpy/numpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pavement.py
251 lines (191 loc) · 6.6 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
r"""
This paver file is intended to help with the release process as much as
possible. It relies on virtualenv to generate 'bootstrap' environments as
independent from the user system as possible (e.g. to make sure the sphinx doc
is built against the built numpy, not an installed one).
Building changelog + notes
==========================
Assumes you have git and the binaries/tarballs in installers/::
paver write_release
paver write_note
This automatically put the checksum into README.rst, and writes the Changelog.
TODO
====
- the script is messy, lots of global variables
- make it more easily customizable (through command line args)
- missing targets: install & test, sdist test, debian packaging
- fix bdist_mpkg: we build the same source twice -> how to make sure we use
the same underlying python for egg install in venv and for bdist_mpkg
"""
import os
import sys
import shutil
import hashlib
import textwrap
# The paver package needs to be installed to run tasks
import paver
from paver.easy import Bunch, options, task, sh
#-----------------------------------
# Things to be changed for a release
#-----------------------------------
# Path to the release notes
RELEASE_NOTES = 'doc/source/release/1.23.0-notes.rst'
#-------------------------------------------------------
# Hardcoded build/install dirs, virtualenv options, etc.
#-------------------------------------------------------
# Where to put the release installers
options(installers=Bunch(releasedir="release",
installersdir=os.path.join("release", "installers")),)
#------------------------
# Get the release version
#------------------------
sys.path.insert(0, os.path.dirname(__file__))
try:
from setup import FULLVERSION
finally:
sys.path.pop(0)
#--------------------------
# Source distribution stuff
#--------------------------
def tarball_name(ftype='gztar'):
"""Generate source distribution name
Parameters
----------
ftype : {'zip', 'gztar'}
Type of archive, default is 'gztar'.
"""
root = f'numpy-{FULLVERSION}'
if ftype == 'gztar':
return root + '.tar.gz'
elif ftype == 'zip':
return root + '.zip'
raise ValueError(f"Unknown type {type}")
@task
def sdist(options):
"""Make source distributions.
Parameters
----------
options :
Set by ``task`` decorator.
"""
# 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')
# To be sure to bypass paver when building sdist... paver + numpy.distutils
# do not play well together.
# Cython is run over all Cython files in setup.py, so generated C files
# will be included.
sh('python3 setup.py sdist --formats=gztar,zip')
# Copy the superpack into installers dir
idirs = options.installers.installersdir
if not os.path.exists(idirs):
os.makedirs(idirs)
for ftype in ['gztar', 'zip']:
source = os.path.join('dist', tarball_name(ftype))
target = os.path.join(idirs, tarball_name(ftype))
shutil.copy(source, target)
#-------------
# README stuff
#-------------
def _compute_hash(idirs, hashfunc):
"""Hash files using given hashfunc.
Parameters
----------
idirs : directory path
Directory containing files to be hashed.
hashfunc : hash function
Function to be used to hash the files.
"""
released = paver.path.path(idirs).listdir()
checksums = []
for fpath in sorted(released):
with open(fpath, 'rb') as fin:
fhash = hashfunc(fin.read())
checksums.append(
'%s %s' % (fhash.hexdigest(), os.path.basename(fpath)))
return checksums
def compute_md5(idirs):
"""Compute md5 hash of files in idirs.
Parameters
----------
idirs : directory path
Directory containing files to be hashed.
"""
return _compute_hash(idirs, hashlib.md5)
def compute_sha256(idirs):
"""Compute sha256 hash of files in idirs.
Parameters
----------
idirs : directory path
Directory containing files to be hashed.
"""
# better checksum so gpg signed README.rst containing the sums can be used
# to verify the binaries instead of signing all binaries
return _compute_hash(idirs, hashlib.sha256)
def write_release_task(options, filename='README'):
"""Append hashes of release files to release notes.
This appends file hashes to the release notes and creates
four README files of the result in various formats:
- README.rst
- README.rst.gpg
- README.md
- README.md.gpg
The md file are created using `pandoc` so that the links are
properly updated. The gpg files are kept separate, so that
the unsigned files may be edited before signing if needed.
Parameters
----------
options :
Set by ``task`` decorator.
filename : string
Filename of the modified notes. The file is written
in the release directory.
"""
idirs = options.installers.installersdir
notes = paver.path.path(RELEASE_NOTES)
rst_readme = paver.path.path(filename + '.rst')
md_readme = paver.path.path(filename + '.md')
# append hashes
with open(rst_readme, 'w') as freadme:
with open(notes) as fnotes:
freadme.write(fnotes.read())
freadme.writelines(textwrap.dedent(
"""
Checksums
=========
MD5
---
::
"""))
freadme.writelines([f' {c}\n' for c in compute_md5(idirs)])
freadme.writelines(textwrap.dedent(
"""
SHA256
------
::
"""))
freadme.writelines([f' {c}\n' for c in compute_sha256(idirs)])
# generate md file using pandoc before signing
sh(f"pandoc -s -o {md_readme} {rst_readme}")
# Sign files
if hasattr(options, 'gpg_key'):
cmd = f'gpg --clearsign --armor --default_key {options.gpg_key}'
else:
cmd = 'gpg --clearsign --armor'
sh(cmd + f' --output {rst_readme}.gpg {rst_readme}')
sh(cmd + f' --output {md_readme}.gpg {md_readme}')
@task
def write_release(options):
"""Write the README files.
Two README files are generated from the release notes, one in ``rst``
markup for the general release, the other in ``md`` markup for the github
release notes.
Parameters
----------
options :
Set by ``task`` decorator.
"""
rdir = options.installers.releasedir
write_release_task(options, os.path.join(rdir, 'README'))