-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.py
More file actions
178 lines (144 loc) · 4.96 KB
/
Copy pathtemplate.py
File metadata and controls
178 lines (144 loc) · 4.96 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
from pathlib import Path
import json
import sys
# Project name
project_name = "us_visa_approval_prediction"
# List of all files and directories to create
files_to_create = [
# --- Root package ---
f"{project_name}/__init__.py",
# --- Components (data & model pipeline steps) ---
f"{project_name}/components/__init__.py",
f"{project_name}/components/data_ingestion.py",
f"{project_name}/components/data_validation.py",
f"{project_name}/components/data_transformation.py",
f"{project_name}/components/model_trainer.py",
f"{project_name}/components/model_evaluation.py",
f"{project_name}/components/model_pusher.py",
# --- Configuration ---
f"{project_name}/configuration/__init__.py",
f"{project_name}/configuration/db_connection.py",
f"{project_name}/configuration/gdrive_connection.py",
# --- Constants ---
f"{project_name}/constants/__init__.py",
# --- Data Access ---
f"{project_name}/data_access/__init__.py",
f"{project_name}/data_access/data.py",
# --- Cloud Storage ---
f"{project_name}/cloud_storage/__init__.py",
f"{project_name}/cloud_storage/gdrive_storage.py",
# --- Entities (config/artifacts/estimator) ---
f"{project_name}/entity/__init__.py",
f"{project_name}/entity/config_entity.py",
f"{project_name}/entity/artifact_entity.py",
f"{project_name}/entity/estimator.py",
f"{project_name}/entity/gdrive_estimator.py",
# --- Logging ---
f"{project_name}/logger/__init__.py",
# --- Exception ---
f"{project_name}/exception/__init__.py",
# --- Pipelines ---
f"{project_name}/pipeline/__init__.py",
f"{project_name}/pipeline/training_pipeline.py",
f"{project_name}/pipeline/prediction_pipeline.py",
# --- Utilities ---
f"{project_name}/utils/__init__.py",
f"{project_name}/utils/main_utils.py",
# --- Tests ---
f"{project_name}/tests/__init__.py",
f"{project_name}/tests/test_data_ingestion.py",
f"{project_name}/tests/test_data_transformation.py",
f"{project_name}/tests/test_model_trainer.py",
f"{project_name}/tests/test_db_connection.py",
f"{project_name}/tests/test_training_pipeline.py",
# --- Notebooks ---
f"{project_name}/notebooks/01_exploration.ipynb",
f"{project_name}/notebooks/02_eda.ipynb",
f"{project_name}/notebooks/03_feature_engineering_and_model_training.ipynb",
f"{project_name}/notebooks/04_evidently_data_drift_detection.ipynb",
# --- Application entry points ---
f"app.py",
f"demo.py",
# --- Project setup ---
f"requirements.txt",
f"Dockerfile",
f".dockerignore",
f"setup.py",
# --- Config files ---
f"{project_name}/config/model.yaml",
f"{project_name}/config/schema.yaml",
# --- Data directories with placeholder files ---
f"{project_name}/data/raw/.gitkeep",
f"{project_name}/data/interim/.gitkeep",
f"{project_name}/data/processed/.gitkeep",
# --- Documents directories with placeholder files ---
f"documents/.gitkeep",
# --- Environment file ---
f".env",
# --- Frontend ---
f"templates/index.html",
f"static/css/style.css",
]
# Create all files and parent directories
for file_path in files_to_create:
path = Path(file_path)
path.parent.mkdir(parents=True, exist_ok=True)
# Check if file exists and has content
if path.exists() and path.stat().st_size > 0:
print(f"{path.name} is already present in {path.parent} and has some content. Skipping creation.")
continue
# Create file based on type
if path.suffix == ".py":
path.write_text(f"# {path.name}\n")
elif path.suffix == ".ipynb":
notebook_content = {"cells": [], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
path.write_text(json.dumps(notebook_content, indent=2))
elif path.name == ".env":
env_template = """# Environment Variables
# MongoDB connection
DB_NAME=
COLLECTION_NAME=
CONNECTION_URL=
# Token
TOKEN_URL=
TRAIN_PASS=
"""
path.write_text(env_template.strip())
else:
path.touch() # empty file for txt, yaml, Dockerfile, .gitkeep, etc.
# Ensure .gitignore contains rules for data & .env
gitignore_path = Path(".gitignore")
gitignore_rules = """
# Ignore data files but keep folder structure
data/*
!data/**/.gitkeep
# Ignore environment files
.env
# Python common ignores
.vscode
venv/
__pycache__/
*.pyc
*.pyo
*.pyd
*.db
*.sqlite3
*.log
.env
.venv
*.egg-info/
dist/
build/
.ipynb_checkpoints/
catboost_info/
artifact/
credentials.json
token.pickle
"""
if not gitignore_path.exists() or ".env" not in gitignore_path.read_text():
gitignore_path.write_text(gitignore_rules.strip())
# Create .python-version with current Python version
python_version = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
python_version_path = Path(".python-version")
python_version_path.write_text(python_version)
print(f"Project '{project_name}' structure processed successfully with .env and .python-version ({python_version})!")