/
vsenv
executable file
·83 lines (72 loc) · 2.17 KB
/
vsenv
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
#!/bin/bash
# Stop on first error
set -e
# Define your project root directory here
PROJECT_ROOT="$(pwd)"
VENV_DIR="$PROJECT_ROOT/venv"
echo "Setting up Python virtual environment..."
# Check if the virtual environment directory exists
if [ ! -d "$VENV_DIR" ]; then
# Create a virtual environment
python3 -m venv "$VENV_DIR"
fi
# Activate the virtual environment
source "$VENV_DIR/bin/activate"
echo "Installing the project and its dependencies..."
# Install the project in editable mode along with its dependencies
pip install -e .
echo "Setting up .env file..."
# Create or overwrite the .env file
echo "PYTHONPATH=$PROJECT_ROOT" > "$PROJECT_ROOT/.env"
echo "Setting up VS Code configuration files..."
# Create .vscode directory if it doesn't exist
mkdir -p "$PROJECT_ROOT/.vscode"
# Create or overwrite settings.json
cat > "$PROJECT_ROOT/.vscode/settings.json" << EOF
{
"python.pythonPath": "$VENV_DIR/bin/python",
"python.envFile": "\${workspaceFolder}/.env",
"python.testing.unittestEnabled": true,
"python.testing.pytestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.unittestArgs": [
"-v",
"-s",
"./tests",
"-p",
"test_*.py"
]
}
EOF
# Create or overwrite launch.json
cat > "$PROJECT_ROOT/.vscode/launch.json" << EOF
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "\${file}",
"console": "integratedTerminal",
"cwd": "\${workspaceFolder}",
"env": {
"PYTHONPATH": "\${workspaceFolder}\${pathSeparator}\${env:PYTHONPATH}"
}
},
{
"name": "Python: Debug Unittests",
"type": "python",
"request": "launch",
"console": "integratedTerminal",
"cwd": "\${workspaceFolder}",
"env": {
"PYTHONPATH": "\${workspaceFolder}\${pathSeparator}\${env:PYTHONPATH}"
},
"purpose": ["debug-test"],
"justMyCode": true
}
]
}
EOF
echo "Setup complete. Please restart VS Code."