-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtasks.py
115 lines (91 loc) · 2.36 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
"""
Project Tasks that can be invoked using using the program "invoke" or "inv"
"""
import os
from invoke import task
# disable the check for unused-arguments to ignore unused ctx parameter in tasks
# pylint: disable=unused-argument
IS_WINDOWS = os.name == "nt"
if IS_WINDOWS:
# setting 'shell' is a work around for issue #345 of invoke
RUN_ARGS = {"pty": False, "shell": r"C:\Windows\System32\cmd.exe"}
else:
RUN_ARGS = {"pty": True}
def get_files():
"""
Get the files to run analysis on
"""
files = [
"dploy",
"tests",
"tasks.py",
]
files_string = " ".join(files)
return files_string
@task
def setup(ctx):
"""
Install python requirements
"""
ctx.run("python -m pip install -r requirements.txt", **RUN_ARGS)
@task
def clean(ctx):
"""
Clean repository using git
"""
ctx.run("git clean --interactive", **RUN_ARGS)
@task
def lint(ctx):
"""
Run pylint on this module
"""
cmds = ["pylint --output-format=parseable", "flake8"]
base_cmd = "python -m {cmd} {files}"
for cmd in cmds:
ctx.run(base_cmd.format(cmd=cmd, files=get_files()), **RUN_ARGS)
@task
def reformat_check(ctx):
"""
Run formatting check
"""
cmd = "black --check"
base_cmd = "python -m {cmd} {files}"
ctx.run(base_cmd.format(cmd=cmd, files=get_files()), **RUN_ARGS)
@task
def reformat(ctx):
"""
Run formatting
"""
cmd = "black"
base_cmd = "python -m {cmd} {files}"
ctx.run(base_cmd.format(cmd=cmd, files=get_files()), **RUN_ARGS)
@task
def metrics(ctx):
"""
Run radon code metrics on this module
"""
cmd = "radon {metric} --min B {files}"
metrics_to_run = ["cc", "mi"]
for metric in metrics_to_run:
ctx.run(cmd.format(metric=metric, files=get_files()), **RUN_ARGS)
@task()
def test(ctx):
"""
Test Task
"""
# Use py.test instead of the recommended pytest so it works on Python 3.3
cmd = "py.test --cov-report term-missing --cov=dploy --color=no"
ctx.run(cmd, **RUN_ARGS)
# pylint: disable=redefined-builtin
@task(test, lint, reformat_check)
def all(default=True):
"""
All tasks minus
"""
@task(clean)
def build(ctx):
"""
Task to build an executable using pyinstaller
"""
cmd = "pyinstaller -n dploy --onefile " + os.path.join("dploy", "__main__.py")
ctx.run(cmd, **RUN_ARGS)