forked from robotframework/robotframework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tasks.py
372 lines (303 loc) · 13 KB
/
tasks.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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
"""Tasks to help Robot Framework packaging and other development.
Executed by Invoke <http://pyinvoke.org>. Install it with `pip install invoke`
and run `invoke --help` and `invode --list` for details how to execute tasks.
See BUILD.rst for packaging and releasing instructions.
"""
import os
import os.path
import re
import shutil
import sys
import time
import urllib
import zipfile
from invoke import task, run
assert os.getcwd() == os.path.dirname(os.path.abspath(__file__))
VERSION_RE = re.compile('^((2\.\d+)(\.\d+)?)((a|b|rc|.dev)\d+)?$')
VERSION_FILE = os.path.join('src', 'robot', 'version.py')
@task(default=True)
def help():
"""Show help, basically an alias for --help.
This task can be removed once the fix to this issue is released:
https://github.com/pyinvoke/invoke/issues/180
"""
run('invoke --help')
@task
def tag_release(version):
"""Tag specified release.
Updates version using `set_version`, creates tag, and pushes changes.
"""
version = set_version(version, push=True)
run("git tag -a {0} -m 'Release {0}'".format(version))
run("git push --tags")
@task
def set_version(version, push=False):
"""Set version in `src/robot/version.py`.
Version can have these values:
- Actual version number to use. See below for supported formats.
- String 'dev' to update version to latest development version
(e.g. 2.8 -> 2.8.1.dev, 2.8.1 -> 2.8.2.dev, 2.8a1 -> 2.8.dev) with
the current date added or updated.
- String 'keep' to keep using the previously set version.
Given version must be in one of these PEP-440 compatible formats:
- Stable version in 'X.Y' or 'X.Y.Z' format (e.g. 2.8, 2.8.6)
- Pre-releases with 'aN', 'bN' or 'rcN' postfix (e.g. 2.8a1, 2.8.6rc2)
- Development releases with '.devYYYYMMDD' postfix (e.g. 2.8.6.dev20141001)
or with '.dev' alone (e.g. 2.8.6.dev) in which case date is added
automatically.
Args:
version: Version to use. See above for supported values and formats.
push: Commit and push changes to the remote repository.
"""
if version and version != 'keep':
version = validate_version(version)
write_version_file(version)
write_pom_file(version)
version = get_version_from_file()
print 'Version:', version
if push:
git_commit([VERSION_FILE, 'pom.xml'],
'Updated version to {}'.format(version), push=True)
return version
def validate_version(version):
if version == 'dev':
version = get_dev_version()
if version.endswith('.dev'):
version += time.strftime('%Y%m%d')
if not VERSION_RE.match(version):
raise ValueError("Invalid version '{}'.".format(version))
return version
def get_dev_version():
previous = get_version_from_file()
major, minor, pre = VERSION_RE.match(previous).groups()[1:4]
if not pre:
minor = '.{}'.format(int(minor[1:]) + 1 if minor else 1)
return '{}{}.dev'.format(major, minor)
def write_version_file(version):
update_file(VERSION_FILE, "VERSION = '.*'", version)
def write_pom_file(version):
update_file('pom.xml', '<version>.*</version>', version)
def update_file(path, pattern, replacement):
replacement = pattern.replace('.*', replacement )
with open(path) as version_file:
content = ''.join(re.sub(pattern, replacement, line)
for line in version_file)
with open(path, 'w') as version_file:
version_file.write(content)
def get_version_from_file():
namespace = {}
execfile(VERSION_FILE, namespace)
return namespace['get_version']()
def git_commit(paths, message, push=False):
paths = paths if isinstance(paths, basestring) else ' '.join(paths)
run("git commit -m '{}' {}".format(message, paths))
if push:
run('git push')
@task
def clean(remove_dist=True, create_dirs=False):
"""Clean workspace.
By default deletes 'build' and 'dist' directories and removes '*.pyc'
and '$py.class' files.
Args:
remove_dist: Remove also 'dist' (default).
create_dirs: Re-create 'build' and 'dist' after removing them.
"""
directories = ['build', 'dist']
for name in directories:
if os.path.isdir(name) and (name != 'dist' or remove_dist):
shutil.rmtree(name)
if create_dirs and not os.path.isdir(name):
os.mkdir(name)
for directory, _, files in os.walk('.'):
for name in files:
if name.endswith(('.pyc', '$py.class')):
os.remove(os.path.join(directory, name))
@task
def sdist(deploy=False, remove_dist=False):
"""Create source distribution.
Args:
deploy: Register and upload sdist to PyPI.
remove_dist: Control is 'dist' directory initially removed or not.
"""
clean(remove_dist, create_dirs=True)
run('python setup.py sdist --force-manifest'
+ (' register upload' if deploy else ''))
announce()
def announce():
print
print 'Distributions:'
for name in os.listdir('dist'):
print os.path.join('dist', name)
@task
def wininst(remove_dist=False):
"""Create Windows installer.
Args:
remove_dist: Control is 'dist' directory initially removed or not.
"""
clean(remove_dist, create_dirs=True)
run('python setup.py bdist_wininst '
'--bitmap robot.bmp --install-script robot_postinstall.py')
announce()
@task
def jar(jython_version='2.5.3', remove_dist=False):
"""Create JAR distribution.
Downloads Jython JAR if needed.
Args:
remove_dist: Control is 'dist' directory initially removed or not.
jython_version: Jython version to use as a base. Must match version in
`jython-standalone-<version>.jar` found from Maven central.
Currently `2.5.3` by default.
"""
clean(remove_dist, create_dirs=True)
jython_jar = get_jython_jar(jython_version)
print 'Using {}'.format(jython_jar)
compile_java_files(jython_jar)
unzip_jar(jython_jar)
copy_robot_files()
compile_python_files(jython_jar)
create_robot_jar(get_version_from_file())
announce()
def get_jython_jar(version):
lib = 'ext-lib'
jar = os.path.join(lib, 'jython-standalone-{}.jar'.format(version))
if os.path.exists(jar):
return jar
url = ('http://search.maven.org/remotecontent?filepath=org/python/'
'jython-standalone/{0}/jython-standalone-{0}.jar').format(version)
print 'Jython not found, downloading it from {}.'.format(url)
if not os.path.exists(lib):
os.mkdir(lib)
urllib.urlretrieve(url, jar)
return jar
def compile_java_files(jython_jar, build_dir='build'):
root = os.path.join('src', 'java', 'org', 'robotframework')
files = [os.path.join(root, name) for name in os.listdir(root)
if name.endswith('.java')]
print 'Compiling {} Java files.'.format(len(files))
run('javac -d {target} -target 1.5 -source 1.5 -cp {cp} {files}'.format(
target=build_dir, cp=jython_jar, files=' '.join(files)))
def unzip_jar(path, target='build'):
zipfile.ZipFile(path).extractall(target)
def copy_robot_files(build_dir='build'):
source = os.path.join('src', 'robot')
target = os.path.join(build_dir, 'Lib', 'robot')
shutil.copytree(source, target, ignore=shutil.ignore_patterns('*.pyc'))
shutil.rmtree(os.path.join(target, 'htmldata', 'testdata'))
def compile_python_files(jython_jar, build_dir='build'):
run('java -jar {} -m compileall {}'.format(jython_jar, build_dir))
# Jython will not work without its py-files, but robot will
for directory, _, files in os.walk(os.path.join(build_dir, 'Lib', 'robot')):
for name in files:
if name.endswith('.py'):
os.remove(os.path.join(directory, name))
def create_robot_jar(version, source='build'):
write_manifest(version, source)
target = os.path.join('dist', 'robotframework-{}.jar'.format(version))
run('jar cvfM {} -C {} .'.format(target, source))
def write_manifest(version, build_dir='build'):
with open(os.path.join(build_dir, 'META-INF', 'MANIFEST.MF'), 'w') as mf:
mf.write('''\
Manifest-Version: 1.0
Main-Class: org.robotframework.RobotFramework
Specification-Version: 2
Implementation-Version: {version}
'''.format(version=version))
@task
def release_notes(version=get_version_from_file(), login=None, password=None):
"""Create release notes template based on issues on GitHub.
Requires PyGithub <https://github.com/jacquev6/PyGithub>. Install it with:
pip install PyGithub
Args:
version: Version to get the issues for. By default the current version.
login: GitHub login. If not given, anonymous login is used. GitHub
API has 60 request/hour limit in that case.
password: The password for GitHub login.
"""
issues = _get_issues(version, login, password)
_print_header("Robot Framework {}".format(version), level=1)
_print_intro(version)
_print_if_label("Most important enhancements", issues, "prio-critical", "prio-high")
_print_if_label("Backwards incompatible changes", issues, "bwic")
_print_if_label("Deprected features", issues, "depr")
_print_header("Acknowledgements")
print("*UPDATE* based on AUTHORS.txt.")
_print_issue_table(issues, version)
def _get_issues(version, login=None, password=None):
try:
from github import Github
except ImportError:
sys.exit("You need to install PyGithub:\n\tpip install PyGithub\n")
repo = Github(login_or_token=login, password=password).get_repo("robotframework/robotframework")
return sorted(Issue(issue) for issue in repo.get_issues(milestone=_get_milestone(repo, version), state="all"))
def _get_milestone(repo, milestone):
for m in repo.get_milestones(state="all"):
if m.title == milestone:
return m
raise AssertionError("Milestone {} not found from repository {}!".format(milestone, repo.name))
def _print_header(header, level=2):
if level > 1:
print
print "{} {}\n".format('#'*level, header)
def _print_if_label(header, issues, *labels):
filtered = [issue for issue in issues
if any(label in issue.labels for label in labels)]
if filtered:
_print_header(header)
print '*EXPLAIN* or remove these.\n'
for issue in filtered:
print "* {} {}".format(issue.id, issue.summary)
def _print_intro(version):
print """
Robot Framework {version} is a new release with *UPDATE* \
enhancements and bug fixes. It was released on {date}.
Questions and comments related to the release can be sent to the \
[robotframework-users](http://groups.google.com/group/robotframework-users) and \
possible bugs submitted to the \
[issue tracker](https://github.com/robotframework/robotframework/issues).
If you have pip just run `pip install --update robotframework`. Otherwise see \
[installation instructions](https://github.com/robotframework/robotframework/blob/master/INSTALL.rst).
""".format(version=version, date=time.strftime("%A %B %d, %Y")).strip()
def _print_issue_table(issues, version):
_print_header("Full list of fixes and enhancements")
print "ID | Type | Priority | Summary"
print "--- | ---- | -------- | -------"
for issue in issues:
print "{} | {} | {} | {} ".format(issue.id, issue.type, issue.priority, issue.summary)
print
print "Altogether {} issues.".format(len(issues)),
print "See on [issue tracker](https://github.com/robotframework/robotframework/issues?q=milestone%3A{}).".format(version)
@task
def print_issues(version=get_version_from_file(), login=None, password=None):
"""Get issues from GitHub issue tracker.
Requires PyGithub <https://github.com/jacquev6/PyGithub>. Install it with:
pip install PyGithub
Args:
version: Version to get the issues for. By default the current version.
login: GitHub login. If not given, anonymous login is used. GitHub
API has 60 request/hour limit in that case.
password: The password for GitHub login.
"""
issues = _get_issues(version, login, password)
print "{:4} {:11} {:8} {}".format("id", "type", "priority", "summary")
for issue in issues:
print "{:4} {:11} {:8} {}".format(issue.id, issue.type, issue.priority, issue.summary)
class Issue(object):
PRIORITIES = ["prio-critical", "prio-high", "prio-medium", "prio-low"]
def __init__(self, issue):
self.id = "#{}".format(issue.number)
self.summary = issue.title
self.labels = [label.name for label in issue.get_labels()]
self.type = self._get_label("bug", "enhancement")
self.priority = self._get_label(*self.PRIORITIES).split('-')[1]
@property
def order(self):
return (self.PRIORITIES.index('prio-' + self.priority),
0 if self.type == 'bug' else 1,
self.id)
def _get_label(self, *values):
for value in values:
if value in self.labels:
return value
return None
def __cmp__(self, other):
return cmp(self.order, other.order)