-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtasks.py
140 lines (120 loc) · 3.02 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
"""Module of Invoke tasks regarding CODE QUALITY to be invoked from the command line. Try
invoke --list
from the command line for a list of all available commands.
"""
import os
import sys
from invoke import task
is_python_37 = sys.version_info[0] == 3 and sys.version_info[1] == 7
greater_than_36 = sys.version_info > (3, 6)
POSIX = os.name == "posix"
@task
def black(
command,
):
"""Runs black (autoformatter) on all .py files recursively"""
if sys.version_info > (3, 6):
print(
"""
Running Black the Python code formatter
=======================================
"""
)
command.run("black .", echo=True, pty=POSIX)
else:
print(
"""
Black formatting should be ran on Python 3.7 or higher, skipping
================================================================
"""
)
@task
def isort(
command,
):
"""Runs isort (import sorter) on all .py files recursively"""
if POSIX or sys.version_info > (3,):
print(
"""
Running isort the Python code import sorter
===========================================
"""
)
command.run("isort .", echo=True, pty=POSIX)
else:
print(
"""
On Windows, isort import sorter should be ran on Python 3, skipping
===================================================================
"""
)
@task
def lint(
command,
):
"""Runs flake8 (linter) on all .py files recursively"""
print(
"""
Running flake8 a Python code linter
===================================
"""
)
command.run("flake8", echo=True, pty=POSIX)
@task(pre=[black, isort, lint])
def style(
command,
):
"""Runs black, isort, and flake8
Arguments:
command {[type]} -- [description]
"""
# If we get to this point all tests listed in 'pre' have passed
# unless we have run the task with the --warn flag
if not command.config.run.warn:
print(
"""
All Style Checks Passed Successfully
====================================
"""
)
@task
def pytest(
command,
):
"""Runs pytest to identify failing tests and doctests"""
print(
"""
Running pytest the test framework
=================================
"""
)
command.run("python -m pytest .", echo=True, pty=POSIX)
@task
def docs(
command,
):
"""Runs Sphinx to build the docs locally for testing"""
print(
"""
Running Sphinx to test the docs building
========================================
"""
)
command.run("sphinx-build -b html docs docs/_build/html", echo=True, pty=POSIX)
@task(pre=[black, isort, lint, pytest, docs])
def all(
command,
):
"""Runs black, isort, flake8, and pytest
Arguments:
command {[type]} -- [description]
"""
# If we get to this point all tests listed in 'pre' have passed
# unless we have run the task with the --warn flag
if not command.config.run.warn:
print(
"""
All Style Checks Tests Passed Successfully
==========================================
"""
)