Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
115 lines (96 loc) · 3.38 KB
/
Copy pathsetup.py
File metadata and controls
115 lines (96 loc) · 3.38 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
#!/usr/bin/env python
"""
CareerConnect Setup Script
--------------------------
This script helps with setting up the CareerConnect application locally.
It creates a virtual environment, installs dependencies, and sets up the database.
"""
import os
import sys
import subprocess
import platform
def is_venv():
"""Check if running in a virtual environment"""
return hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)
def create_venv():
"""Create a virtual environment if not already in one"""
if is_venv():
print("Already running in a virtual environment.")
return True
print("Creating virtual environment...")
try:
subprocess.check_call([sys.executable, "-m", "venv", "venv"])
return True
except subprocess.CalledProcessError:
print("Failed to create virtual environment. Please create it manually.")
return False
def activate_venv():
"""Provide instructions to activate the virtual environment"""
if platform.system() == "Windows":
print("\nTo activate the virtual environment, run:")
print(" venv\\Scripts\\activate")
else:
print("\nTo activate the virtual environment, run:")
print(" source venv/bin/activate")
print("\nAfter activation, run this script again to continue setup.")
def create_requirements():
"""Create requirements.txt file"""
print("Creating requirements.txt...")
requirements = [
"flask",
"flask-login",
"flask-migrate",
"flask-sqlalchemy",
"flask-wtf",
"email-validator",
"gunicorn",
"werkzeug",
"markupsafe",
"jinja2"
]
with open("requirements.txt", "w") as f:
f.write("\n".join(requirements))
print("Created requirements.txt successfully.")
def install_dependencies():
"""Install required dependencies"""
print("Installing dependencies...")
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
print("Dependencies installed successfully.")
return True
except subprocess.CalledProcessError:
print("Failed to install dependencies. Please install them manually.")
return False
def run_application():
"""Provide instructions to run the application"""
print("\nSetup completed successfully!")
print("\nTo run the application:")
if platform.system() == "Windows":
print(" set FLASK_APP=main.py")
print(" set FLASK_ENV=development")
else:
print(" export FLASK_APP=main.py")
print(" export FLASK_ENV=development")
print(" flask run")
print("\nAlternatively, you can use:")
print(" python -m flask run")
print("\nThe application will be available at: http://127.0.0.1:5000")
def main():
"""Main setup function"""
print("CareerConnect Setup")
print("===================")
# Check if already in a virtual environment
if not is_venv():
# Create virtual environment
if create_venv():
activate_venv()
return
else:
print("Continuing without virtual environment...")
# Create requirements.txt
create_requirements()
# Install dependencies
if install_dependencies():
run_application()
if __name__ == "__main__":
main()