-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtasks.py
More file actions
120 lines (103 loc) · 3.03 KB
/
tasks.py
File metadata and controls
120 lines (103 loc) · 3.03 KB
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
"""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 shutil
from invoke import task
POSIX = os.name == "posix"
@task
def black(command, checkonly=False):
"""Runs black (autoformatter) on all .py files recursively
if checkonly=True, only checks if would change files
"""
print(
"""
Running Black the Python code formatter
=======================================
"""
)
cmd = "black --check --diff ." if checkonly else "black ."
command.run(cmd, echo=True, pty=POSIX)
@task
def isort(command, checkonly=False):
"""Runs isort (import sorter) on all .py files recursively
if checkonly=True, only checks if would change files
"""
print(
"""
Running isort the Python code import sorter
===========================================
"""
)
cmd = "isort --check-only --diff ." if checkonly else "isort ."
command.run(cmd, echo=True, pty=POSIX)
@task
def lint(
command,
):
"""Runs flake8 plugin flakeheaven (linter) on all .py files recursively"""
print(
"""
Running flakeheaven, a Python code linter
===================================
"""
)
command.run("flakeheaven lint", echo=True, pty=POSIX)
@task
def style(command, checkonly=False):
"""Runs black, isort, and flake8
if checkonly=True, only checks if would change files
"""
black(command, checkonly=checkonly)
isort(command, checkonly=checkonly)
lint(command)
# Only prints if doesn't exit from the above not failing out
print(
"""
All Style Checks Passed Successfully
====================================
"""
)
@task(aliases=["tests"])
def test(command, options=""):
"""Runs pytest to identify failing tests and doctests"""
print(
"""
Running pytest the test framework
=================================
"""
)
command.run(f"python -m pytest {options} .", echo=True, pty=POSIX)
@task
def docs(command, warn_is_error=False):
"""Runs Sphinx to build the docs locally for testing"""
print(
"""
Running Sphinx to test the docs building
========================================
"""
)
options = "-W " if warn_is_error else ""
shutil.rmtree("docs/_build", ignore_errors=True)
shutil.rmtree("docs/_autosummary", ignore_errors=True)
shutil.rmtree("docs/jupyter_execute", ignore_errors=True)
command.run(f"sphinx-build {options}-b html docs docs/_build/package", echo=True, pty=POSIX)
command.run("PROJECT=apps sphinx-build -b html docs docs/_build/apps")
@task(pre=[black, isort, lint, test, 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 Checks Passed Successfully
==========================================
"""
)