-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_project.sh
executable file
·198 lines (171 loc) · 5.8 KB
/
init_project.sh
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash
###############################################################################
# init_project.sh
#
# Description:
# This script initializes the directory structure and boilerplate files
# for a FastAPI-based Technician Booking System, using:
# - Python 3.10
# - Poetry (for dependency management)
# - Hugging Face Transformers integration
# It also creates an example .env file with placeholders for your
# Hugging Face API Key and model name.
#
# Usage:
# bash init_project.sh
#
# Author:
# Ericson Willians <ericsonwillians@protonmail.com>
###############################################################################
# Exit immediately if a command exits with a non-zero status
set -e
# Uncomment this for debugging
# set -x
#------------------------------------------------------------------------------#
# Helper Functions
#------------------------------------------------------------------------------#
log() {
echo "[INFO] $1"
}
error_exit() {
echo "[ERROR] $1" >&2
exit 1
}
#------------------------------------------------------------------------------#
# Preliminary Checks
#------------------------------------------------------------------------------#
# Validate script is being run from a suitable location:
# (Not strictly required, but helpful if you want to ensure a fresh directory.)
if [[ -d "./app" || -d "./tests" || -d "./scripts" || -f "./pyproject.toml" ]]; then
log "Some project files or directories already exist. Proceeding carefully."
else
log "Initializing a new FastAPI + Poetry + HuggingFace project structure."
fi
#------------------------------------------------------------------------------#
# Directory Creation
#------------------------------------------------------------------------------#
directories=(
"./app/core"
"./app/routers"
"./app/models"
"./app/services"
"./app/schemas"
"./app/config"
"./app/utils"
"./tests/unit"
"./tests/integration"
"./scripts"
)
for dir in "${directories[@]}"; do
if [ ! -d "$dir" ]; then
mkdir -p "$dir"
log "Created directory: $dir"
else
log "Directory already exists: $dir"
fi
done
#------------------------------------------------------------------------------#
# File Creation
#------------------------------------------------------------------------------#
files=(
"./app/__init__.py"
"./app/main.py"
"./app/core/__init__.py"
"./app/core/initial_data.py"
"./app/core/cli.py"
"./app/routers/__init__.py"
"./app/routers/bookings.py"
"./app/models/__init__.py"
"./app/models/booking.py"
"./app/services/__init__.py"
"./app/services/booking_service.py"
"./app/services/validation.py"
"./app/schemas/__init__.py"
"./app/schemas/booking.py"
"./app/config/__init__.py"
"./app/config/settings.py"
"./app/utils/__init__.py"
"./app/utils/nlp_service.py"
"./tests/__init__.py"
"./tests/unit/test_services.py"
"./tests/integration/test_api.py"
"./scripts/setup.sh"
"./.env.example"
"./README.md"
)
for file in "${files[@]}"; do
if [ ! -f "$file" ]; then
touch "$file"
log "Created file: $file"
else
log "File already exists: $file"
fi
done
#------------------------------------------------------------------------------#
# Create or Update .env.example
#------------------------------------------------------------------------------#
ENV_EXAMPLE_CONTENT="# .env.example
# Copy this file to .env and replace the placeholder values as needed.
# Security: Never commit your actual .env to version control.
# Hugging Face API Key (if using a private or hosted model)
HUGGINGFACE_API_KEY=\"<YOUR_HUGGING_FACE_API_KEY>\"
# Default model for your Transformers pipelines
MODEL_NAME=\"bert-base-uncased\"
# Add any other environment variables you need:
# e.g., DB_URL, SECRET_KEY, etc.
"
# Overwrite (or create fresh) .env.example
echo "$ENV_EXAMPLE_CONTENT" > "./.env.example"
log "Wrote placeholder content to .env.example"
#------------------------------------------------------------------------------#
# Create or Update pyproject.toml (if desired)
#------------------------------------------------------------------------------#
# If you want to automate creation of a minimal pyproject.toml, uncomment below:
: '
PYPROJECT_CONTENT="[tool.poetry]
name = \"TechBooker\"
version = \"0.1.0\"
description = \"Technician Booking System with NLP Integration\"
authors = [\"Ericson Willians <ericsonwillians@protonmail.com>\"]
license = \"MIT\"
readme = \"README.md\"
[tool.poetry.dependencies]
python = \"^3.10\"
fastapi = \"^0.103.2\"
uvicorn = \"^0.23.2\"
pydantic = \"^2.4.2\"
python-dotenv = \"^1.0.0\"
transformers = \"^4.36.2\"
torch = \"^2.1.1\"
datasets = \"^2.16.1\"
sentence-transformers = \"^2.2.2\"
accelerate = \"^0.25.0\"
python-dateutil = \"^2.8.2\"
typer = \"^0.9.0\"
[tool.poetry.group.dev.dependencies]
pytest = \"^7.4.2\"
mypy = \"^1.6.1\"
black = \"^23.10.1\"
flake8 = \"^6.1.0\"
isort = \"^5.12.0\"
httpx = \"^0.25.0\"
[build-system]
requires = [\"poetry-core\"]
build-backend = \"poetry.core.masonry.api\"
"
if [ ! -f "./pyproject.toml" ]; then
echo "$PYPROJECT_CONTENT" > "./pyproject.toml"
log "Created pyproject.toml for Poetry."
else
log "pyproject.toml already exists. Skipping creation."
fi
'
#------------------------------------------------------------------------------#
# Final Message
#------------------------------------------------------------------------------#
log "Project structure has been initialized successfully!"
log "Next steps:"
log "1) Check your .env.example and create a .env file with real values."
log "2) Run 'poetry init' or verify your existing pyproject.toml to manage dependencies."
log "3) Install dependencies with 'poetry install'."
log "4) You're ready to start developing your FastAPI + Hugging Face project!"