~javiljoen/yatte

yatte/tasks.py -rw-r--r-- 1.3 KiB
d070de94JA Viljoen Clean up documentation 5 months ago
                                                                                
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
import shutil
import sys
from logging import warning

from yatte import task
from yatte.utils import run, runp


@task("setup")
def setup():
    "Set up development environment."
    install_dependencies()
    run("flit install -s")


@task("deps")
def install_dependencies():
    "Install development dependencies."
    run("pip install -r requirements.txt")
    check_installed("scdoc")


@task("lint")
def run_linters():
    """Run linters."""
    cmds = [
        "isort --check .",
        "black --check .",
        "flake8 .",
    ]
    runp(cmds)


@task("test")
def run_tests():
    """Run tests."""
    run("pytest -q .")


@task("check")
def check():
    """lint + test"""
    cmds = [
        "isort --check .",
        "black --check .",
        "flake8 .",
        "pytest -q .",
    ]
    runp(cmds)


@task("fmt")
def format():
    """Run formatters."""
    run("isort .")
    run("black .")


sys.path.insert(0, "docs")
import doctasks  # noqa: E402 F401


@task("upload")
def pypi():
    """Publish package to PyPI."""
    run("flit publish")


@task("clean")
def clean():
    """Remove build/test artefacts."""
    run("rm -rf .pytest_cache")
    run("rm -rf dist")
    run("rm -rf docs/_built")


# Helper functions


def check_installed(cmd):
    if shutil.which(cmd) is None:
        warning("%r is required for some tasks but is not installed.", cmd)