This repository has been archived by the owner on Nov 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
185 lines (123 loc) · 4.91 KB
/
fabfile.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
"""Fabfile for release management."""
import codecs
import glob
import os
import re
from fabric.api import local, abort, lcd
import tests
HERE = os.path.dirname(__file__)
ROOT = HERE
# =============================================================================
# internal helpers
# =============================================================================
def _readfile(fname, strip="\n"):
"""Shortcut for reading a text file."""
with codecs.open(fname, 'r', 'UTF8') as fp:
content = fp.read()
return content.strip(strip) if strip else content
def _contains(fname, rx, reflags=0):
"""Check if content of `fname` matches (contains) `rx`."""
content = _readfile(fname)
return re.search(rx, content, reflags)
def _needcleanworkingcopy():
"""Aborts if working copy is dirty."""
if local("hg status -n", capture=True):
abort("dirty working copy")
# =============================================================================
# wiki tools
# =============================================================================
WIKI = os.path.join(ROOT, "wiki") # clone in sub-directory `wiki`
WIKITESTPAGE = """
#summary Generated test illustration page
#labels Test, Generated
*Note*: The Markdown and wiki source shown here might not be displayed
perfectly. Especially code block markers `{{{` and `}}}` are always flushed
left completely. If in doubt, look at the source of this Wiki page or check the
original test files.
Converter command used for this test:
{{{
$ markowik MDFILE WIKIFILE %(options)s
}}}
Markowik revision: [http://code.google.com/p/markowik/source/browse/?r=%(revision)s %(revision)s]
= <font color="darkred">Markdown Source</font> =
{{{
%(md)s
}}}
= <font color="darkred">Wiki Source</font> =
{{{
%(wiki)s
}}}
= <font color="darkred">Wiki View</font> =
%(wiki)s
""".strip()
def wiki_render():
"""Render wiki test pages."""
_needcleanworkingcopy()
context = {'revision': local("hg id -i", capture=True)}
for testpage in glob.glob(os.path.join(WIKI, "Test*.wiki")):
os.remove(testpage)
for name, mdfile, wikifile, cfgfile in tests.iterfiles("md", "wiki", "cfg"):
name = "".join(x.capitalize() for x in name.split("-"))
pagefile = os.path.join(WIKI, "Test%s.wiki" % name)
context['options'] = " ".join(tests.readoptions(cfgfile))
context['md'] = _readfile(mdfile)
context['wiki'] = _readfile(wikifile)
with codecs.open(pagefile, 'w', 'UTF8') as fp:
fp.write(WIKITESTPAGE % context)
def wiki_publish():
"""Publish wiki test pages."""
dirty = lambda: local('hg status -n -I "Test*.wiki"', capture=True)
with lcd(WIKI):
if dirty():
local('hg commit -A -m "Automatic update of test pages" -I "Test*.wiki"')
local("hg fetch")
local("hg push -r .")
def wiki():
"""Render and publish wiki test pages."""
wiki_render()
wiki_publish()
# =============================================================================
# release tools
# =============================================================================
def push():
"""Push master branch."""
_needcleanworkingcopy()
hgignore = _readfile(".hgignore").split("\n")[2:]
gitignore = _readfile(".gitignore").split("\n")
if hgignore != gitignore:
abort("hg and git ignore files differ")
local("hg push -r master google")
local("hg push -r master bitbucket")
local("hg push -r master github")
def release_check(version):
"""Various checks to be done prior a release."""
# --- check README --------------------------------------------------------
from docutils.core import publish_cmdline
readme = os.path.join(ROOT, "README.rst")
publish_cmdline(argv=["--halt", "2", readme, os.devnull])
# --- version numbers -----------------------------------------------------
rx = r'\n--+\nChanges\n--+\n\nVersion %s\n~~+\n\n' % version
if not _contains(readme, rx):
abort("bad version in README.rst")
setup = os.path.join(ROOT, "setup.py")
rx = r'''\nversion *= *['"]%s['"]\n''' % version
if not _contains(setup, rx):
abort("bad version in setup.py")
# --- run tests -----------------------------------------------------------
local(os.path.join(ROOT, "bin", "tests"))
# --- check working copy --------------------------------------------
_needcleanworkingcopy()
out = local("hg bookmarks", capture=True)
if not re.match(r'\s*\* master\s', out):
abort("working copy is not at master bookmark")
def release(version):
"""Make a release."""
local("bin/buildout")
release_check(version)
local("rm -rf %s" % os.path.join(ROOT, "build"))
local("rm -rf %s" % os.path.join(ROOT, "dist"))
local("bin/buildout setup %s clean build sdist" % ROOT) # test build
local("hg tag %s" % version)
wiki()
local("bin/buildout setup %s register sdist upload" % ROOT)
push()