forked from Parallels/rq-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
128 lines (93 loc) · 3.35 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
"""Common development operations."""
import os
import os.path
from fabric.api import abort, env, hide, lcd, local, quiet, settings, task
def _relative_to_fabfile(*path):
return os.path.join(os.path.dirname(env.real_fabfile), *path)
@task
def todo(*args):
"""List the TODOs and FIXMEs in the code and documentation."""
with lcd(_relative_to_fabfile()):
local(
'grin -e ".pyc,.pyo" "FIXME|TODO" *')
local(
'grind -0 \'*.feature\' | '
'grin -I \'*.feature\' -0 -f - "FIXME|TODO"')
@task
def style():
"""Use flake8 to check Python style, PEP8, and McCabe complexity.
See http://pypi.python.org/pypi/flake8/
.. note::
* Files with the following header are skipped::
# flake8: noqa
* Lines that end with a ``# NOQA`` comment will not issue a warning.
"""
with lcd(_relative_to_fabfile('rq_dashboard')):
local(
'flake8 '
'--exclude=".svn,CVS,.bzr,.hg,.git,__pycache__,._*" '
'--max-complexity=9 .')
@task
def isort():
"""Use isort to automatically (re-)order the import statements on the top of files"""
with lcd(_relative_to_fabfile()):
local('isort **/*.py')
@task
def clean():
"""Remove all generated files (.pyc, .coverage, .egg, etc)."""
with lcd(_relative_to_fabfile()):
local('find -name "*.pyc" | xargs rm -f')
local('find -name .coverage | xargs rm -f')
local('find -name .DS_Store | xargs rm -f') # Created by OSX
local('find -name ._DS_Store | xargs rm -f') # Created by OSX
local('find -name "._*.*" | xargs rm -f') # E.g. created by Caret
local('rm -f .coverage.*')
local('rm -rf build')
local('rm -rf dist')
def _latest_git_tag():
return local('git tag | sort -nr | head -n1', capture=True)
def _git_head_sha():
return local('git rev-parse HEAD', capture=True)
def _git_tag_sha():
return local(
'git tag | sort -nr | head -n1 | xargs git rev-parse', capture=True)
def _abort_if_tag_is_not_at_head():
"""Confirm committed to git with appropriate tags."""
latest_tag = _latest_git_tag()
head_sha = _git_head_sha()
tag_sha = _git_tag_sha()
print 'Latest git tag: {}'.format(latest_tag)
if head_sha != tag_sha:
abort('Latest git tag is not at HEAD!')
@task
def build():
"""Check Git, clean, test, and build sdist and wheel."""
clean()
style()
# TODO tests()
local('python setup.py sdist bdist_wheel')
@task
def upload(index_server='pypitest'):
"""Submit build package to index server as found in `~/.pypirc`.
The default is to PyPI test. Typically `~/.pypirc` will contain:
[distutils]
index-servers=
pypi
pypitest
[pypitest]
repository = https://testpypi.python.org/pypi
username = <username>
password = <password>
[pypi]
repository = https://pypi.python.org/pypi
username = <username>
password = <password>
"""
_abort_if_tag_is_not_at_head()
with lcd(_relative_to_fabfile()):
# TODO switch to twine once the following bug has been fixed:
# https://bugs.launchpad.net/pkginfo/+bug/1437570
local(
'python setup.py sdist bdist_wheel upload '
' -r {} --show-response'.format(index_server)
)