-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtasks.py
84 lines (62 loc) · 2.31 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
import os
from invoke import Context, task
WINDOWS = os.name == "nt"
PROJECT_NAME = "catsvsdogs"
PYTHON_VERSION = "3.11"
# Setup commands
@task
def create_environment(ctx: Context) -> None:
"""Create a new conda environment for project."""
ctx.run(
f"conda create --name {PROJECT_NAME} python={PYTHON_VERSION} pip --no-default-packages --yes",
echo=True,
pty=not WINDOWS,
)
@task
def requirements(ctx: Context) -> None:
"""Install project requirements."""
ctx.run("pip install -U pip setuptools wheel", echo=True, pty=not WINDOWS)
ctx.run("pip install -r requirements.txt", echo=True, pty=not WINDOWS)
ctx.run("pip install -e .", echo=True, pty=not WINDOWS)
@task(requirements)
def dev_requirements(ctx: Context) -> None:
"""Install development requirements."""
ctx.run('pip install -e .["dev"]', echo=True, pty=not WINDOWS)
# Project commands
@task
def preprocess_data(ctx: Context) -> None:
"""Preprocess data."""
ctx.run(f"python src/{PROJECT_NAME}/data.py", echo=True, pty=not WINDOWS)
@task
def train(ctx: Context) -> None:
"""Train model."""
ctx.run(f"python src/{PROJECT_NAME}/train.py", echo=True, pty=not WINDOWS)
@task
def evaluate(ctx: Context) -> None:
"""Evaluate model."""
ctx.run(f"python src/{PROJECT_NAME}/evaluate.py", echo=True, pty=not WINDOWS)
@task
def test(ctx: Context) -> None:
"""Run tests."""
ctx.run("coverage run -m pytest tests/", echo=True, pty=not WINDOWS)
ctx.run("coverage report -m", echo=True, pty=not WINDOWS)
@task
def docker_build(ctx: Context, progress: str = "plain") -> None:
"""Build docker images."""
ctx.run(
f"docker build -t train:latest . -f dockerfiles/train.dockerfile --progress={progress}",
echo=True,
pty=not WINDOWS,
)
ctx.run(
f"docker build -t api:latest . -f dockerfiles/api.dockerfile --progress={progress}", echo=True, pty=not WINDOWS
)
# Documentation commands
@task(dev_requirements)
def build_docs(ctx: Context) -> None:
"""Build documentation."""
ctx.run("mkdocs build --config-file docs/mkdocs.yaml --site-dir build", echo=True, pty=not WINDOWS)
@task(dev_requirements)
def serve_docs(ctx: Context) -> None:
"""Serve documentation."""
ctx.run("mkdocs serve --config-file docs/mkdocs.yaml", echo=True, pty=not WINDOWS)