-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
121 lines (95 loc) · 3.12 KB
/
setup.py
File metadata and controls
121 lines (95 loc) · 3.12 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
121
#!/usr/bin/env python3
"""
NetWeaver Project Setup Script
Runs data pipeline and training in sequence:
1. Data preprocessing (data_pipeline.py)
2. Model training (train.py)
Usage:
python setup.py
"""
import os
import sys
import subprocess
from pathlib import Path
def get_project_root():
"""Get the root directory of the project."""
return Path(__file__).resolve().parent
def run_command(cmd, description):
"""
Execute a command and handle errors.
Args:
cmd (list): Command to execute
description (str): Description of the command
Returns:
bool: True if successful, False otherwise
"""
print(f"\n{'='*50}")
print(f"{description}")
print(f"{'='*50}\n")
try:
result = subprocess.run(cmd, check=True)
print(f"\n✅ {description} completed successfully!\n")
return True
except subprocess.CalledProcessError as e:
print(f"\n❌ {description} failed with error code {e.returncode}\n")
return False
except Exception as e:
print(f"\n❌ {description} failed: {str(e)}\n")
return False
def main():
"""Main setup execution."""
print("="*50)
print("NetWeaver Project Setup")
print("="*50)
project_root = get_project_root()
print(f"\nProject root: {project_root}\n")
src_dir = project_root / "src"
# Verify src directory exists
if not src_dir.exists():
print(f"❌ Error: src directory not found at {src_dir}")
sys.exit(1)
# Step 1: Run data pipeline
print("\nStep 1: Running Data Pipeline...")
pipeline_cmd = [sys.executable, "data_pipeline.py"]
if not run_command(pipeline_cmd, "Data Pipeline", cwd=src_dir):
sys.exit(1)
# Step 2: Run training
print("\nStep 2: Starting Model Training...")
train_cmd = [sys.executable, "train.py"]
if not run_command(train_cmd, "Model Training", cwd=src_dir):
sys.exit(1)
# Success
print("="*50)
print("Setup Complete!")
print("="*50)
print("\n🎉 All steps completed successfully!")
print("\nResults saved in:")
print(f" - Models: {project_root}/results/saved_models/")
print(f" - Results: {project_root}/results/train/")
def run_command(cmd, description, cwd=None):
"""
Execute a command in a specific directory.
Args:
cmd (list): Command to execute
description (str): Description of the command
cwd (Path): Working directory
Returns:
bool: True if successful, False otherwise
"""
print(f"\n{'='*50}")
print(f"{description}")
print(f"{'='*50}\n")
if cwd is None:
cwd = get_project_root()
try:
result = subprocess.run(cmd, cwd=str(cwd), check=True)
print(f"\n✅ {description} completed successfully!\n")
return True
except subprocess.CalledProcessError as e:
print(f"\n❌ {description} failed with error code {e.returncode}\n")
return False
except Exception as e:
print(f"\n❌ {description} failed: {str(e)}\n")
return False
if __name__ == "__main__":
main()