-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathsetup_env.py
More file actions
executable file
·57 lines (45 loc) · 1.71 KB
/
Copy pathsetup_env.py
File metadata and controls
executable file
·57 lines (45 loc) · 1.71 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
#!/usr/bin/env python3
"""Set up the development environment.
Creates a .venv virtual environment and installs dependencies from
requirements.txt. Works on Windows, macOS, and Linux.
Usage:
python setup_env.py
python3 setup_env.py
"""
import os
import subprocess
import sys
def main():
venv_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '.venv')
py = sys.executable
# Create virtual environment
if not os.path.isdir(venv_dir):
print('Creating virtual environment in .venv...')
subprocess.run([py, '-m', 'venv', venv_dir], check=True)
else:
print('Virtual environment already exists in .venv')
# Determine paths inside venv
if sys.platform == 'win32':
pip = os.path.join(venv_dir, 'Scripts', 'pip')
venv_py = os.path.join(venv_dir, 'Scripts', 'python')
else:
pip = os.path.join(venv_dir, 'bin', 'pip')
venv_py = os.path.join(venv_dir, 'bin', 'python')
# Upgrade pip
print('Upgrading pip...')
subprocess.run([venv_py, '-m', 'pip', 'install', '-U', 'pip'], check=True)
# Install requirements
req = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'requirements.txt')
if os.path.isfile(req):
print('Installing dependencies from requirements.txt...')
subprocess.run([pip, 'install', '-r', req], check=True)
else:
print('No requirements.txt found, skipping dependency install.')
# Activation instructions
print('\nSetup complete!')
if sys.platform == 'win32':
print('Activate the environment with: .venv\\Scripts\\activate')
else:
print('Activate the environment with: source .venv/bin/activate')
if __name__ == '__main__':
main()