forked from Chachigo/FamilyBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreinstall_bot.ps1
More file actions
135 lines (121 loc) · 5.71 KB
/
Copy pathreinstall_bot.ps1
File metadata and controls
135 lines (121 loc) · 5.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
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
# In FamilyBot/reinstall_bot.ps1
<#
.SYNOPSIS
Performs a complete clean reinstall of the FamilyBot's virtual environment and dependencies.
.DESCRIPTION
This script automates the process of:
1. Deactivating the current virtual environment (if active).
2. Deleting the existing virtual environment folder (.venv).
3. Deleting all __pycache__ folders within the project.
4. Creating a new virtual environment using uv.
5. Activating the newly created virtual environment.
6. Installing all project dependencies from pyproject.toml in editable mode using uv.
.NOTES
- Run this script from the FamilyBot/ project root directory.
- Requires PowerShell 7 or later.
- Requires 'uv' to be installed and in your system's PATH.
- This script will delete the .venv folder and __pycache__ folders.
.EXAMPLE
.\reinstall_bot.ps1
#>
# --- Configuration ---
$ProjectRoot = Get-Location
$VenvPath = Join-Path $ProjectRoot ".venv"
$ActivateScript = Join-Path $VenvPath "Scripts" "Activate.ps1"
Write-Host "--- Starting FamilyBot Reinstall Process ---" -ForegroundColor Cyan
# --- NEW CHECK: Verify uv is installed ---
Write-Host "Verifying 'uv' is installed and accessible..." -ForegroundColor Yellow
if (-not (Get-Command uv -ErrorAction SilentlyContinue)) {
Write-Host "ERROR: 'uv' command not found." -ForegroundColor Red
Write-Host "Please install 'uv' globally before running this script." -ForegroundColor Red
Write-Host "Instructions: curl -LsSf https://astral.sh/uv/install.sh | sh (or pip install uv)" -ForegroundColor Red
exit 1
} else {
Write-Host "'uv' found." -ForegroundColor Green
}
# --- END NEW CHECK ---
# 1. Deactivate current virtual environment if active
Write-Host "1. Deactivating virtual environment (if active)..." -ForegroundColor Yellow
if ($env:VIRTUAL_ENV) {
if (Get-Command "deactivate" -ErrorAction SilentlyContinue) {
deactivate
Write-Host " Deactivated." -ForegroundColor Green
} else {
Write-Host " 'deactivate' command not found, attempting manual path cleanup." -ForegroundColor Yellow
$env:VIRTUAL_ENV = $null
$env:PATH = ($env:PATH -split ';') | Where-Object { -not ($_ -like "*\.venv\Scripts") } | Join-String -Separator ';'
}
} else {
Write-Host " No virtual environment active." -ForegroundColor Green
}
# 2. Deleting existing virtual environment folder
Write-Host "2. Deleting existing virtual environment folder: $VenvPath" -ForegroundColor Yellow
if (Test-Path $VenvPath) {
try {
Remove-Item -Path $VenvPath -Recurse -Force -ErrorAction Stop
Write-Host " Deleted .venv folder." -ForegroundColor Green
} catch {
Write-Host " ERROR: Failed to delete .venv folder. Please close any processes using files in .venv and try again." -ForegroundColor Red
Write-Host $_.Exception.Message -ForegroundColor Red
exit 1
}
} else {
Write-Host " .venv folder not found, skipping deletion." -ForegroundColor Green
}
# 3. Deleting all __pycache__ folders
Write-Host "3. Deleting all __pycache__ folders..." -ForegroundColor Yellow
try {
Get-ChildItem -Path $ProjectRoot -Recurse -Directory -Filter "__pycache__" | Remove-Item -Recurse -Force -ErrorAction Stop
Write-Host " Deleted __pycache__ folders." -ForegroundColor Green
} catch {
Write-Host " ERROR: Failed to delete __pycache__ folders." -ForegroundColor Red
Write-Host $_.Exception.Message -ForegroundColor Red
exit 1
}
# 4. Creating a new virtual environment using uv
Write-Host "4. Creating a new virtual environment using uv..." -ForegroundColor Yellow
try {
uv venv
Write-Host " New virtual environment created." -ForegroundColor Green
} catch {
Write-Host " ERROR: Failed to create virtual environment with uv." -ForegroundColor Red
Write-Host " Error message from uv: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
# Verifying Activate.ps1 exists
Write-Host " Verifying Activate.ps1 script..." -ForegroundColor Yellow
if (Test-Path $ActivateScript) {
Write-Host " Activate.ps1 found." -ForegroundColor Green
} else {
Write-Host " ERROR: Activate.ps1 script NOT found after uv venv. Something went wrong." -ForegroundColor Red
Write-Host " Please try running 'uv venv' manually and check for errors." -ForegroundColor Red
exit 1
}
# 5. Activating the new virtual environment
Write-Host "5. Activating the new virtual environment..." -ForegroundColor Yellow
try {
. $ActivateScript -ErrorAction Stop
if ($env:VIRTUAL_ENV -like "*\.venv") {
Write-Host " Virtual environment activated." -ForegroundColor Green
} else {
Write-Host " WARNING: Virtual environment activation seemed to fail. Check your prompt for '(.)venv'." -ForegroundColor Yellow
}
} catch {
Write-Host " ERROR: Failed to activate virtual environment." -ForegroundColor Red
Write-Host $_.Exception.Message -ForegroundColor Red
exit 1
}
# 6. Installing all project dependencies
Write-Host "6. Installing all project dependencies with 'uv pip install -e .'..." -ForegroundColor Yellow
try {
uv pip install -e .
Write-Host " All dependencies installed successfully." -ForegroundColor Green
} catch {
Write-Host " ERROR: Failed to install project dependencies." -ForegroundColor Red
Write-Host $_.Exception.Message -ForegroundColor Red
exit 1
}
Write-Host "--- Reinstall Process Complete ---" -ForegroundColor Cyan
Write-Host "You can now run your bot: uv run python .\src\familybot\FamilyBot.py" -ForegroundColor Cyan
Write-Host "And your token sender: uv run python .\src\familybot\Token_Sender\getToken.py" -ForegroundColor Cyan
Write-Host "Alternatively, to run the bots, use the 'run_bots.ps1' or `run_bots.bat` script." -ForegroundColor Cyan