-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.py
More file actions
69 lines (46 loc) · 1.73 KB
/
Copy pathscripts.py
File metadata and controls
69 lines (46 loc) · 1.73 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
"""Makefile-like commands for the project."""
import subprocess
import sys
from pathlib import Path
def install():
"""Install dependencies."""
subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
def install_dev():
"""Install development dependencies."""
subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements-dev.txt"])
def test():
"""Run tests."""
subprocess.run([sys.executable, "-m", "pytest", "tests/", "-v"])
def lint():
"""Run linting."""
subprocess.run([sys.executable, "-m", "flake8", "src/", "tests/"])
def format_code():
"""Format code with black."""
subprocess.run([sys.executable, "-m", "black", "src/", "tests/"])
def clean():
"""Clean up generated files."""
import shutil
patterns = ["**/__pycache__", "**/*.pyc", "**/*.pyo", "**/.*_cache"]
for pattern in patterns:
for path in Path(".").glob(pattern):
if path.is_dir():
shutil.rmtree(path)
else:
path.unlink()
def train():
"""Train the MNIST model."""
subprocess.run([sys.executable, "-m", "src.index", "mnist", "train"])
def predict():
"""Run MNIST predictions."""
subprocess.run([sys.executable, "-m", "src.index", "mnist", "predict"])
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python scripts.py <command>")
print("Commands: install, install-dev, test, lint, format, clean, train, predict")
sys.exit(1)
command = sys.argv[1].replace("-", "_")
if hasattr(sys.modules[__name__], command):
getattr(sys.modules[__name__], command)()
else:
print(f"Unknown command: {sys.argv[1]}")
sys.exit(1)