-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtasks.py
73 lines (52 loc) · 1.44 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
"""Script for common command line tasks for this project."""
import os
# Invoke always requires a context parameter, even if it ends up going
# unused. As of this writing, there are a handful of tasks that don't
# use their context parameters.
# pylint: disable=unused-argument
# Built-in libraries:
import sys
# Third-party dependencies:
from dotenv import dotenv_values
from dotenv import load_dotenv
from invoke import task
# Set environment variables.
load_dotenv()
# Environment variable files:
ENV_TEMPLATE = ".env.template"
ENV_ACTUAL = ".env"
# Configs:
TEMPLATE_CONF = dotenv_values(ENV_TEMPLATE)
ACTUAL_CONF = dotenv_values(ENV_ACTUAL)
@task
def fmt(c):
"""Format code."""
c.run("black .")
c.run("mdformat README.md")
c.run("mdformat doc")
@task
def fmtcheck(c):
"""Checks if the code is formatted properly."""
c.run("black --check .")
@task
def lint(c):
"""Run the linter."""
c.run("pylint src")
c.run("pylint tasks.py")
@task
def types(c):
"""Check types."""
c.run("mypy .")
@task
def envsame(c):
"""Ensure environment variable keys match."""
if TEMPLATE_CONF.keys() != ACTUAL_CONF.keys():
print(".env keys do not match. Check your .env files.")
sys.exit(1)
@task
def test(c):
"""Run test suite."""
c.run(f"cd {os.getenv('AFFILS_WORKING_DIR')}/src && python manage.py test")
@task(pre=[fmt, lint, types, envsame, test])
def check(c):
"""Run all code checks."""