Update app.py
Browse files
app.py
CHANGED
|
@@ -14,16 +14,23 @@ def clone_repo():
|
|
| 14 |
repo_url = f"https://{GITHUB_USERNAME}:{GITHUB_TOKEN}@github.com/{GITHUB_USERNAME}/{REPO_NAME}.git"
|
| 15 |
subprocess.run(["git", "clone", repo_url, "repo"], check=True)
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def install_requirements():
|
| 18 |
req_file = "repo/requirements.txt"
|
| 19 |
if os.path.exists(req_file):
|
| 20 |
subprocess.run(["pip", "install", "--no-cache-dir", "-r", req_file], check=True)
|
| 21 |
|
| 22 |
def start_script():
|
| 23 |
-
subprocess.Popen(["
|
| 24 |
|
| 25 |
def run_app():
|
| 26 |
clone_repo()
|
|
|
|
| 27 |
install_requirements()
|
| 28 |
start_script()
|
| 29 |
|
|
@@ -33,4 +40,4 @@ def startup_event():
|
|
| 33 |
|
| 34 |
@app.get("/")
|
| 35 |
def home():
|
| 36 |
-
return {"status": "Repo cloned, requirements installed,
|
|
|
|
| 14 |
repo_url = f"https://{GITHUB_USERNAME}:{GITHUB_TOKEN}@github.com/{GITHUB_USERNAME}/{REPO_NAME}.git"
|
| 15 |
subprocess.run(["git", "clone", repo_url, "repo"], check=True)
|
| 16 |
|
| 17 |
+
def setup_env():
|
| 18 |
+
sample = "repo/.env.example"
|
| 19 |
+
target = "repo/.env"
|
| 20 |
+
if os.path.exists(sample) and not os.path.exists(target):
|
| 21 |
+
subprocess.run(["cp", sample, target], check=True)
|
| 22 |
+
|
| 23 |
def install_requirements():
|
| 24 |
req_file = "repo/requirements.txt"
|
| 25 |
if os.path.exists(req_file):
|
| 26 |
subprocess.run(["pip", "install", "--no-cache-dir", "-r", req_file], check=True)
|
| 27 |
|
| 28 |
def start_script():
|
| 29 |
+
subprocess.Popen(["python3", "-m" , "Hazel"], cwd="repo")
|
| 30 |
|
| 31 |
def run_app():
|
| 32 |
clone_repo()
|
| 33 |
+
setup_env() # 👈 added here
|
| 34 |
install_requirements()
|
| 35 |
start_script()
|
| 36 |
|
|
|
|
| 40 |
|
| 41 |
@app.get("/")
|
| 42 |
def home():
|
| 43 |
+
return {"status": "Repo cloned, env setup, requirements installed, script running 🚀"}
|