-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-python.js
More file actions
62 lines (51 loc) · 1.91 KB
/
setup-python.js
File metadata and controls
62 lines (51 loc) · 1.91 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
import { spawn } from 'child_process';
import path from 'path';
import fs from 'fs';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const venvPath = path.join(__dirname, '.venv');
const requirementsPath = path.join(__dirname, 'packages/chatterbox/requirements.txt');
const isWindows = process.platform === 'win32';
const pythonCmd = isWindows ? 'python' : 'python3';
const venvPython = isWindows ? path.join(venvPath, 'Scripts', 'python.exe') : path.join(venvPath, 'bin', 'python');
const pipCmd = isWindows ? path.join(venvPath, 'Scripts', 'pip.exe') : path.join(venvPath, 'bin', 'pip');
async function runCommand(command, args, cwd = __dirname) {
return new Promise((resolve, reject) => {
console.log(`> ${command} ${args.join(' ')}`);
const proc = spawn(command, args, {
cwd,
stdio: 'inherit',
shell: true
});
proc.on('close', (code) => {
if (code === 0) resolve();
else reject(new Error(`Command failed with code ${code}`));
});
});
}
async function setup() {
console.log('🐍 Setting up Python environment for Chatterbox...');
// 1. Create venv if it doesn't exist
if (!fs.existsSync(venvPath)) {
console.log('Creating virtual environment...');
await runCommand(pythonCmd, ['-m', 'venv', '.venv']);
} else {
console.log('Virtual environment already exists.');
}
// 2. Install requirements
if (fs.existsSync(requirementsPath)) {
console.log('Installing dependencies from requirements.txt...');
// Upgrade pip first
await runCommand(venvPython, ['-m', 'pip', 'install', '--upgrade', 'pip']);
// Install deps
await runCommand(venvPython, ['-m', 'pip', 'install', '-r', requirementsPath]);
} else {
console.error('requirements.txt not found at:', requirementsPath);
}
console.log('✅ Python setup complete.');
}
setup().catch((err) => {
console.error('Setup failed:', err);
process.exit(1);
});