From cb0a18f7484a3ea84a4e9a9ac96959d7e26693bd Mon Sep 17 00:00:00 2001 From: NotSoToothless <67082114+FURRO404@users.noreply.github.com> Date: Sun, 31 May 2026 01:43:19 -0700 Subject: [PATCH] move venv to shared (#1291) --- BOT/botscript.py | 4 ++-- BOT/tests/smoke_player_recap.py | 2 +- BOT/tests/smoke_recap.py | 2 +- BOT/utils.py | 2 +- README.md | 8 ++++---- ecosystem.config.js | 9 ++++++--- requirements.txt | 21 --------------------- scripts/diag_entitlements.py | 2 +- scripts/diag_meta_points.py | 2 +- scripts/migrate_clan_id.py | 2 +- web/server.js | 10 +++++----- 11 files changed, 23 insertions(+), 41 deletions(-) delete mode 100644 requirements.txt diff --git a/BOT/botscript.py b/BOT/botscript.py index ab9c320..3f9a99a 100644 --- a/BOT/botscript.py +++ b/BOT/botscript.py @@ -193,7 +193,7 @@ async def on_ready(): """Handle bot startup: write guild report, refresh presence, init caches, and start tasks.""" GUILD_TOTAL = len(bot.guilds) - out_path = STORAGE_DIR / "GUILD_REPORT.txt" + out_path = STORAGE_DIR / "SREBOT_GUILDS.txt" with out_path.open("w", encoding="utf-8") as f: f.write(f"We have logged in as {bot.user} in the following Guilds:\n\n") for guild in bot.guilds: @@ -334,7 +334,7 @@ async def _refresh_presence(): await bot.change_presence( activity=discord.Activity( type=discord.ActivityType.playing, - name=f"Playing War Thunder in {GUILD_TOTAL} servers!" + name=f"Playing SRE in {GUILD_TOTAL} servers!" ) ) diff --git a/BOT/tests/smoke_player_recap.py b/BOT/tests/smoke_player_recap.py index 93ceb74..da08769 100644 --- a/BOT/tests/smoke_player_recap.py +++ b/BOT/tests/smoke_player_recap.py @@ -2,7 +2,7 @@ Smoke test for BOT/render_recap.py in --mode player. Usage: - source .venv/bin/activate && python BOT/tests/smoke_player_recap.py + source ../SHARED/.venv/bin/activate && python BOT/tests/smoke_player_recap.py """ import sqlite3 diff --git a/BOT/tests/smoke_recap.py b/BOT/tests/smoke_recap.py index be61d32..aa0d646 100644 --- a/BOT/tests/smoke_recap.py +++ b/BOT/tests/smoke_recap.py @@ -5,7 +5,7 @@ Runs the renderer end-to-end against the live HC storage volume databases and verifies a PNG lands at the --out path. Usage: - source .venv/bin/activate && python BOT/tests/smoke_recap.py + source ../SHARED/.venv/bin/activate && python BOT/tests/smoke_recap.py """ import subprocess diff --git a/BOT/utils.py b/BOT/utils.py index 711e1c0..948ad3f 100644 --- a/BOT/utils.py +++ b/BOT/utils.py @@ -1957,7 +1957,7 @@ _REPO_ROOT = Path(__file__).resolve().parent.parent SQUADRON_RECAP_CACHE_DIR = STORAGE_DIR / "RECAPS" / "squadrons" PLAYER_RECAP_CACHE_DIR = STORAGE_DIR / "RECAPS" / "players" -_RECAP_PYTHON_BIN = _REPO_ROOT / ".venv" / "bin" / "python" +_RECAP_PYTHON_BIN = _REPO_ROOT.parent / "SHARED" / ".venv" / "bin" / "python" _RECAP_SCRIPT = _REPO_ROOT / "BOT" / "render_recap.py" RECAP_TTL_SECONDS = 24 * 60 * 60 # in-progress season TTL (matches web) diff --git a/README.md b/README.md index 996c82a..8f51201 100644 --- a/README.md +++ b/README.md @@ -7,15 +7,15 @@ cd BOTS/SREBOT ``` -2. **Set up Python virtual environment** +2. **Set up the shared Python virtual environment** (used by both SREBOT and TSSBOT) ```bash - python3 -m venv .venv - source .venv/bin/activate + python3 -m venv ../SHARED/.venv + source ../SHARED/.venv/bin/activate ``` 3. **Install dependencies** ```bash - pip install -r requirements.txt + pip install -r ../SHARED/requirements.txt ``` 4. **Configure environment variables** diff --git a/ecosystem.config.js b/ecosystem.config.js index cd613dc..36e972c 100644 --- a/ecosystem.config.js +++ b/ecosystem.config.js @@ -6,13 +6,16 @@ const DEPLOY_PATH = __dirname; +// Both bots share one venv at BOTS/SHARED/.venv (built from SHARED/requirements.txt). +const PY_INTERPRETER = `${DEPLOY_PATH}/../SHARED/.venv/bin/python`; + module.exports = { apps: [ // Discord Bot { name: 'srebot', script: 'start_bot.py', - interpreter: `${DEPLOY_PATH}/.venv/bin/python`, + interpreter: PY_INTERPRETER, cwd: DEPLOY_PATH, instances: 1, autorestart: true, @@ -54,7 +57,7 @@ module.exports = { { name: 'srebot-axbot', script: 'BOT/srebot_external.py', - interpreter: `${DEPLOY_PATH}/.venv/bin/python`, + interpreter: PY_INTERPRETER, cwd: DEPLOY_PATH, instances: 1, autorestart: true, @@ -74,7 +77,7 @@ module.exports = { { name: 'srebot-webhook', script: 'github_webhook_updater.py', - interpreter: `${DEPLOY_PATH}/.venv/bin/python`, + interpreter: PY_INTERPRETER, cwd: DEPLOY_PATH, instances: 1, autorestart: true, diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 7c41112..0000000 --- a/requirements.txt +++ /dev/null @@ -1,21 +0,0 @@ -discord.py>=2.4.0,<3.0.0 -requests>=2.32.3,<3.0.0 -beautifulsoup4>=4.12.3,<5.0.0 -lxml>=5.0.0 -zstandard -lz4==4.3.3 -aiofiles -aiohttp -aiohttp-socks -websockets>=13.0 -aiosqlite -deepl -python-dotenv>=1.0.0 -flask>=2.0.0 -Pillow>=10.0.0 -WtFileUtils -dotenv -numpy -wcwidth -fontTools -matplotlib diff --git a/scripts/diag_entitlements.py b/scripts/diag_entitlements.py index f8c764c..881a7bb 100644 --- a/scripts/diag_entitlements.py +++ b/scripts/diag_entitlements.py @@ -4,7 +4,7 @@ right now. Compare against the local entitlements.db cache. Usage (on the server): cd ~/GitHub/SREBOT_MEOW - source .venv/bin/activate + source ../SHARED/.venv/bin/activate python scripts/diag_entitlements.py Targeted guild: 1379510072815779961 (bot owner's max-tier server). diff --git a/scripts/diag_meta_points.py b/scripts/diag_meta_points.py index c71ed2e..2d1d4b4 100644 --- a/scripts/diag_meta_points.py +++ b/scripts/diag_meta_points.py @@ -8,7 +8,7 @@ mismatch, squadron-name mismatch). Usage (on the server): cd ~/SREBOT/SREBOT_MEOW - source .venv/bin/activate + source ../SHARED/.venv/bin/activate python scripts/diag_meta_points.py 1378960248118841507 """ from __future__ import annotations diff --git a/scripts/migrate_clan_id.py b/scripts/migrate_clan_id.py index 46af37f..c391a18 100644 --- a/scripts/migrate_clan_id.py +++ b/scripts/migrate_clan_id.py @@ -20,7 +20,7 @@ Run with `--dry-run` first. The script prints exactly what it would do. Usage ----- - source .venv/bin/activate + source ../SHARED/.venv/bin/activate python scripts/migrate_clan_id.py --dry-run python scripts/migrate_clan_id.py --apply """ diff --git a/web/server.js b/web/server.js index c7c6d83..85764cc 100644 --- a/web/server.js +++ b/web/server.js @@ -156,7 +156,7 @@ const SQUADRON_RECAP_CACHE_DIR = path.join(STORAGE_ROOT, 'RECAPS', 'squadrons'); const PLAYER_RECAP_CACHE_DIR = path.join(STORAGE_ROOT, 'RECAPS', 'players'); const RECAP_TTL_MS = 24 * 60 * 60 * 1000; // in-progress season TTL const RECAP_RENDER_TIMEOUT_MS = 30_000; -const PYTHON_BIN = path.join(REPO_ROOT, '.venv', 'bin', 'python'); +const PYTHON_BIN = path.join(REPO_ROOT, '..', 'SHARED', '.venv', 'bin', 'python'); const RECAP_SCRIPT = path.join(REPO_ROOT, 'BOT', 'render_recap.py'); function resolveReplaySessionDir(sessionId) { @@ -1896,7 +1896,7 @@ app.get('/api/match/:sessionId/video', async (req, res) => { _videoRenderCount++; try { await new Promise((resolve, reject) => { - const pythonBin = path.join(__dirname, '..', '.venv', 'bin', 'python'); + const pythonBin = path.join(__dirname, '..', '..', 'SHARED', '.venv', 'bin', 'python'); execFile(pythonBin, ['-m', 'BOT.render_replay', replayPath, videoPath], { timeout: 120000, cwd: path.join(__dirname, '..') @@ -1959,7 +1959,7 @@ app.get('/api/match/:sessionId/replay-canvas', async (req, res) => { _canvasRenderCount++; try { await new Promise((resolve, reject) => { - const pythonBin = path.join(__dirname, '..', '.venv', 'bin', 'python'); + const pythonBin = path.join(__dirname, '..', '..', 'SHARED', '.venv', 'bin', 'python'); execFile(pythonBin, ['-m', 'BOT.render_replay', replayPath, jsonPath], { timeout: 30000, cwd: path.join(__dirname, '..') @@ -2338,9 +2338,9 @@ app.get('/api/stats', cors(apiCorsOptions), async (req, res) => { return res.json({ ...statsCache, uptime: Math.floor(process.uptime()) }); } - // Guild count from GUILD_REPORT.txt (bot writes one line per guild on startup) + // Guild count from SREBOT_GUILDS.txt (bot writes one line per guild on startup) let servers = 0; - const reportPath = path.join(STORAGE_ROOT, 'GUILD_REPORT.txt'); + const reportPath = path.join(STORAGE_ROOT, 'SREBOT_GUILDS.txt'); try { const report = fs.readFileSync(reportPath, 'utf8').trim(); servers = report ? report.split('\n').length : 0;