numpy
/
pavement.py
185 строк · 5.0 Кб
1r"""
2This paver file is intended to help with the release process as much as
3possible. It relies on virtualenv to generate 'bootstrap' environments as
4independent from the user system as possible (e.g. to make sure the sphinx doc
5is built against the built numpy, not an installed one).
6
7Building changelog + notes
8==========================
9
10Assumes you have git and the binaries/tarballs in installers/::
11
12paver write_release
13paver write_note
14
15This automatically put the checksum into README.rst, and writes the Changelog.
16
17TODO
18====
19- the script is messy, lots of global variables
20- make it more easily customizable (through command line args)
21- missing targets: install & test, sdist test, debian packaging
22- fix bdist_mpkg: we build the same source twice -> how to make sure we use
23the same underlying python for egg install in venv and for bdist_mpkg
24"""
25import os
26import hashlib
27import textwrap
28
29# The paver package needs to be installed to run tasks
30import paver
31from paver.easy import Bunch, options, task, sh
32
33
34#-----------------------------------
35# Things to be changed for a release
36#-----------------------------------
37
38# Path to the release notes
39RELEASE_NOTES = 'doc/source/release/2.2.0-notes.rst'
40
41
42#-------------------------------------------------------
43# Hardcoded build/install dirs, virtualenv options, etc.
44#-------------------------------------------------------
45
46# Where to put the release installers
47options(installers=Bunch(releasedir="release",
48installersdir=os.path.join("release", "installers")),)
49
50
51#-------------
52# README stuff
53#-------------
54
55def _compute_hash(idirs, hashfunc):
56"""Hash files using given hashfunc.
57
58Parameters
59----------
60idirs : directory path
61Directory containing files to be hashed.
62hashfunc : hash function
63Function to be used to hash the files.
64
65"""
66released = paver.path.path(idirs).listdir()
67checksums = []
68for fpath in sorted(released):
69with open(fpath, 'rb') as fin:
70fhash = hashfunc(fin.read())
71checksums.append(
72'%s %s' % (fhash.hexdigest(), os.path.basename(fpath)))
73return checksums
74
75
76def compute_md5(idirs):
77"""Compute md5 hash of files in idirs.
78
79Parameters
80----------
81idirs : directory path
82Directory containing files to be hashed.
83
84"""
85return _compute_hash(idirs, hashlib.md5)
86
87
88def compute_sha256(idirs):
89"""Compute sha256 hash of files in idirs.
90
91Parameters
92----------
93idirs : directory path
94Directory containing files to be hashed.
95
96"""
97# better checksum so gpg signed README.rst containing the sums can be used
98# to verify the binaries instead of signing all binaries
99return _compute_hash(idirs, hashlib.sha256)
100
101
102def write_release_task(options, filename='README'):
103"""Append hashes of release files to release notes.
104
105This appends file hashes to the release notes and creates
106four README files of the result in various formats:
107
108- README.rst
109- README.rst.gpg
110- README.md
111- README.md.gpg
112
113The md file are created using `pandoc` so that the links are
114properly updated. The gpg files are kept separate, so that
115the unsigned files may be edited before signing if needed.
116
117Parameters
118----------
119options :
120Set by ``task`` decorator.
121filename : str
122Filename of the modified notes. The file is written
123in the release directory.
124
125"""
126idirs = options.installers.installersdir
127notes = paver.path.path(RELEASE_NOTES)
128rst_readme = paver.path.path(filename + '.rst')
129md_readme = paver.path.path(filename + '.md')
130
131# append hashes
132with open(rst_readme, 'w') as freadme:
133with open(notes) as fnotes:
134freadme.write(fnotes.read())
135
136freadme.writelines(textwrap.dedent(
137"""
138Checksums
139=========
140
141MD5
142---
143::
144
145"""))
146freadme.writelines([f' {c}\n' for c in compute_md5(idirs)])
147
148freadme.writelines(textwrap.dedent(
149"""
150SHA256
151------
152::
153
154"""))
155freadme.writelines([f' {c}\n' for c in compute_sha256(idirs)])
156
157# generate md file using pandoc before signing
158sh(f"pandoc -s -o {md_readme} {rst_readme}")
159
160# Sign files
161if hasattr(options, 'gpg_key'):
162cmd = f'gpg --clearsign --armor --default_key {options.gpg_key}'
163else:
164cmd = 'gpg --clearsign --armor'
165
166sh(cmd + f' --output {rst_readme}.gpg {rst_readme}')
167sh(cmd + f' --output {md_readme}.gpg {md_readme}')
168
169
170@task
171def write_release(options):
172"""Write the README files.
173
174Two README files are generated from the release notes, one in ``rst``
175markup for the general release, the other in ``md`` markup for the github
176release notes.
177
178Parameters
179----------
180options :
181Set by ``task`` decorator.
182
183"""
184rdir = options.installers.releasedir
185write_release_task(options, os.path.join(rdir, 'README'))
186