numpy

Форк
0
/
pavement.py 
185 строк · 5.0 Кб
1
r"""
2
This paver file is intended to help with the release process as much as
3
possible. It relies on virtualenv to generate 'bootstrap' environments as
4
independent from the user system as possible (e.g. to make sure the sphinx doc
5
is built against the built numpy, not an installed one).
6

7
Building changelog + notes
8
==========================
9

10
Assumes you have git and the binaries/tarballs in installers/::
11

12
    paver write_release
13
    paver write_note
14

15
This automatically put the checksum into README.rst, and writes the Changelog.
16

17
TODO
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
23
      the same underlying python for egg install in venv and for bdist_mpkg
24
"""
25
import os
26
import hashlib
27
import textwrap
28

29
# The paver package needs to be installed to run tasks
30
import paver
31
from 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
39
RELEASE_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
47
options(installers=Bunch(releasedir="release",
48
                         installersdir=os.path.join("release", "installers")),)
49

50

51
#-------------
52
# README stuff
53
#-------------
54

55
def _compute_hash(idirs, hashfunc):
56
    """Hash files using given hashfunc.
57

58
    Parameters
59
    ----------
60
    idirs : directory path
61
        Directory containing files to be hashed.
62
    hashfunc : hash function
63
        Function to be used to hash the files.
64

65
    """
66
    released = paver.path.path(idirs).listdir()
67
    checksums = []
68
    for fpath in sorted(released):
69
        with open(fpath, 'rb') as fin:
70
            fhash = hashfunc(fin.read())
71
            checksums.append(
72
                '%s  %s' % (fhash.hexdigest(), os.path.basename(fpath)))
73
    return checksums
74

75

76
def compute_md5(idirs):
77
    """Compute md5 hash of files in idirs.
78

79
    Parameters
80
    ----------
81
    idirs : directory path
82
        Directory containing files to be hashed.
83

84
    """
85
    return _compute_hash(idirs, hashlib.md5)
86

87

88
def compute_sha256(idirs):
89
    """Compute sha256 hash of files in idirs.
90

91
    Parameters
92
    ----------
93
    idirs : directory path
94
        Directory 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
99
    return _compute_hash(idirs, hashlib.sha256)
100

101

102
def write_release_task(options, filename='README'):
103
    """Append hashes of release files to release notes.
104

105
    This appends file hashes to the release notes and creates
106
    four README files of the result in various formats:
107

108
    - README.rst
109
    - README.rst.gpg
110
    - README.md
111
    - README.md.gpg
112

113
    The md file are created using `pandoc` so that the links are
114
    properly updated. The gpg files are kept separate, so that
115
    the unsigned files may be edited before signing if needed.
116

117
    Parameters
118
    ----------
119
    options :
120
        Set by ``task`` decorator.
121
    filename : str
122
        Filename of the modified notes. The file is written
123
        in the release directory.
124

125
    """
126
    idirs = options.installers.installersdir
127
    notes = paver.path.path(RELEASE_NOTES)
128
    rst_readme = paver.path.path(filename + '.rst')
129
    md_readme = paver.path.path(filename + '.md')
130

131
    # append hashes
132
    with open(rst_readme, 'w') as freadme:
133
        with open(notes) as fnotes:
134
            freadme.write(fnotes.read())
135

136
        freadme.writelines(textwrap.dedent(
137
            """
138
            Checksums
139
            =========
140

141
            MD5
142
            ---
143
            ::
144

145
            """))
146
        freadme.writelines([f'    {c}\n' for c in compute_md5(idirs)])
147

148
        freadme.writelines(textwrap.dedent(
149
            """
150
            SHA256
151
            ------
152
            ::
153

154
            """))
155
        freadme.writelines([f'    {c}\n' for c in compute_sha256(idirs)])
156

157
    # generate md file using pandoc before signing
158
    sh(f"pandoc -s -o {md_readme} {rst_readme}")
159

160
    # Sign files
161
    if hasattr(options, 'gpg_key'):
162
        cmd = f'gpg --clearsign --armor --default_key {options.gpg_key}'
163
    else:
164
        cmd = 'gpg --clearsign --armor'
165

166
    sh(cmd + f' --output {rst_readme}.gpg {rst_readme}')
167
    sh(cmd + f' --output {md_readme}.gpg {md_readme}')
168

169

170
@task
171
def write_release(options):
172
    """Write the README files.
173

174
    Two README files are generated from the release notes, one in ``rst``
175
    markup for the general release, the other in ``md`` markup for the github
176
    release notes.
177

178
    Parameters
179
    ----------
180
    options :
181
        Set by ``task`` decorator.
182

183
    """
184
    rdir = options.installers.releasedir
185
    write_release_task(options, os.path.join(rdir, 'README'))
186

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.