-
Notifications
You must be signed in to change notification settings - Fork 76
/
manage.py
executable file
·183 lines (144 loc) · 4.95 KB
/
manage.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: sw=4:ts=4:expandtab
""" A script to manage development tasks """
from os import path as p
from subprocess import call, check_call, CalledProcessError
from manager import Manager
manager = Manager()
BASEDIR = p.dirname(__file__)
DEF_WHERE = ["riko", "tests", "examples", "setup.py", "manage.py"]
def _upload():
"""Upload distribution files"""
dist = p.join(BASEDIR, 'dist', '*')
arg = '--repository-url'
url = 'https://upload.pypi.org/legacy/'
check_call(['twine', 'upload', arg, url, dist])
def _sdist():
"""Create a source distribution package"""
check_call(p.join(BASEDIR, 'helpers', 'srcdist'))
def _wheel():
"""Create a wheel package"""
check_call(p.join(BASEDIR, 'helpers', 'wheel'))
def _clean():
"""Remove Python file and build artifacts"""
check_call(p.join(BASEDIR, 'helpers', 'clean'))
@manager.command
def check():
"""Check staged changes for lint errors"""
exit(call(p.join(BASEDIR, 'helpers', 'check-stage')))
@manager.arg('where', 'w', help='Modules to check', default='meza')
@manager.arg('strict', 's', help='Check with pylint')
@manager.arg('compatibility', 'c', help='Check with pylint porting checker')
@manager.command
def lint(where=None, strict=False, compatibility=False):
"""Check style with linters"""
_where = where or ' '.join(DEF_WHERE)
command = f"pylint --rcfile=tests/standard.rc -rn -fparseable {_where}"
try:
check_call(['flake8'] + _where.split(' '))
if strict:
check_call(command, shell=True)
if compatibility:
check_call(f"{command} --py3k", shell=True)
except CalledProcessError as e:
exit(e.returncode)
@manager.command
def pipme():
"""Install requirements.txt"""
exit(call('pip', 'install', '-r', 'requirements.txt'))
@manager.arg('where', 'w', help='requirements file', default=None)
@manager.command
def require(where=None):
"""Create requirements.txt"""
prefix = '%s-' % where if where else ''
cmd = 'pip freeze -l | grep -xFf %srequirements.txt' % prefix
exit(check_call(cmd, shell=True))
@manager.arg('source', 's', help='the tests to run', default=None)
@manager.arg('where', 'w', help='test path', default=None)
@manager.arg(
'stop', 'x', help='Stop after first error', type=bool, default=False)
@manager.arg(
'failed', 'f', help='Run failed tests', type=bool, default=False)
@manager.arg(
'cover', 'c', help='Add coverage report', type=bool, default=False)
@manager.arg('tox', 't', help='Run tox tests', type=bool, default=False)
@manager.arg('detox', 'd', help='Run detox tests', type=bool, default=False)
@manager.arg(
'verbose', 'v', help='Use detailed errors', type=bool, default=False)
@manager.arg(
'parallel', 'p', help='Run tests in parallel in multiple processes',
type=bool, default=False)
@manager.arg(
'debug', 'D', help='Use nose.loader debugger', type=bool, default=False)
@manager.command
def test(source=None, where=None, stop=False, **kwargs):
"""Run nose, tox, and script tests"""
opts = '-xv' if stop else '-v'
opts += ' --with-coverage' if kwargs.get('cover') else ''
opts += ' --failed' if kwargs.get('failed') else ' --with-id'
opts += ' --processes=-1' if kwargs.get('parallel') else ''
opts += ' --detailed-errors' if kwargs.get('verbose') else ''
opts += ' --debug=nose.loader' if kwargs.get('debug') else ''
opts += ' -w {}'.format(where) if where else ''
opts += ' {}'.format(source) if source else ''
try:
if kwargs.get('tox'):
check_call('tox')
elif kwargs.get('detox'):
check_call('detox')
else:
check_call(('nosetests {}'.format(opts)).split(' '))
if not source:
check_call(['python', p.join(BASEDIR, 'tests', 'test.py')])
except CalledProcessError as e:
exit(e.returncode)
@manager.command
def release():
"""Package and upload a release"""
try:
_clean()
_sdist()
_wheel()
_upload()
except CalledProcessError as e:
exit(e.returncode)
@manager.command
def build():
"""Create a source distribution and wheel package"""
try:
_clean()
_sdist()
_wheel()
except CalledProcessError as e:
exit(e.returncode)
@manager.command
def upload():
"""Upload distribution files"""
try:
_upload()
except CalledProcessError as e:
exit(e.returncode)
@manager.command
def sdist():
"""Create a source distribution package"""
try:
_sdist()
except CalledProcessError as e:
exit(e.returncode)
@manager.command
def wheel():
"""Create a wheel package"""
try:
_wheel()
except CalledProcessError as e:
exit(e.returncode)
@manager.command
def clean():
"""Remove Python file and build artifacts"""
try:
_clean()
except CalledProcessError as e:
exit(e.returncode)
if __name__ == '__main__':
manager.main()