Skip to content

Commit f7c5aba

Browse files
committed
fix: using --no-cache-dir when installing Python packages on start
1 parent f9d0bea commit f7c5aba

2 files changed

Lines changed: 46 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- added debouncing to autocompletion in prompt field
66
- keeping the processing on errors (e.g. LLM model API overload that keeps retrying)
7+
- using --no-cache-dir when installing Python packages on start
78

89
## [0.4.1]
910

src/main/start-up.ts

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { promisify } from 'util';
66
import { delay } from '@common/utils';
77
import { is } from '@electron-toolkit/utils';
88

9+
import logger from './logger';
910
import {
1011
AIDER_DESK_DIR,
1112
SETUP_COMPLETE_FILENAME,
@@ -62,7 +63,7 @@ const checkPythonVersion = async (): Promise<void> => {
6263
};
6364

6465
const createVirtualEnv = async (): Promise<void> => {
65-
const command = process.platform === 'win32' ? 'python' : 'python3';
66+
const command = getOSPythonExecutable();
6667
await execAsync(`${command} -m venv "${PYTHON_VENV_DIR}"`, {
6768
windowsHide: true,
6869
});
@@ -87,18 +88,38 @@ const setupAiderConnector = async () => {
8788

8889
const installAiderConnectorRequirements = async (): Promise<void> => {
8990
const pythonBinPath = getPythonVenvBinPath();
90-
const packages = ['aider-chat --upgrade', 'python-socketio', 'websocket-client', 'nest-asyncio'];
91+
const packages = ['pip', 'aider-chat', 'python-socketio', 'websocket-client', 'nest-asyncio'];
92+
93+
logger.info('Starting Aider connector requirements installation', { packages });
9194

9295
for (const pkg of packages) {
93-
await execAsync(`"${PYTHON_COMMAND}" -m pip install ${pkg}`, {
94-
windowsHide: true,
95-
env: {
96-
...process.env,
97-
VIRTUAL_ENV: PYTHON_VENV_DIR,
98-
PATH: `${pythonBinPath}${path.delimiter}${process.env.PATH}`,
99-
},
100-
});
96+
try {
97+
logger.info(`Installing package: ${pkg}`);
98+
const { stdout, stderr } = await execAsync(`"${PYTHON_COMMAND}" -m pip install --upgrade --no-cache-dir ${pkg}`, {
99+
windowsHide: true,
100+
env: {
101+
...process.env,
102+
VIRTUAL_ENV: PYTHON_VENV_DIR,
103+
PATH: `${pythonBinPath}${path.delimiter}${process.env.PATH}`,
104+
},
105+
});
106+
107+
if (stdout.trim()) {
108+
logger.debug(`Package ${pkg} installation output`, { stdout: stdout.trim() });
109+
}
110+
if (stderr.trim()) {
111+
logger.warn(`Package ${pkg} installation warnings`, { stderr: stderr.trim() });
112+
}
113+
} catch (error) {
114+
logger.error(`Failed to install package: ${pkg}`, {
115+
error: error instanceof Error ? error.message : String(error),
116+
stack: error instanceof Error ? error.stack : undefined,
117+
});
118+
throw new Error(`Failed to install Aider connector requirements. Package: ${pkg}. Error: ${error}`);
119+
}
101120
}
121+
122+
logger.info('Completed Aider connector requirements installation');
102123
};
103124

104125
const setupMcpServer = async () => {
@@ -155,7 +176,10 @@ export type UpdateProgressData = {
155176
export type UpdateProgressFunction = (data: UpdateProgressData) => void;
156177

157178
export const performStartUp = async (updateProgress: UpdateProgressFunction): Promise<boolean> => {
179+
logger.info('Starting AiderDesk setup process');
180+
158181
if (fs.existsSync(SETUP_COMPLETE_FILENAME)) {
182+
logger.info('Setup previously completed, performing update check');
159183
await performUpdateCheck(updateProgress);
160184
return true;
161185
}
@@ -168,6 +192,7 @@ export const performStartUp = async (updateProgress: UpdateProgressFunction): Pr
168192
await delay(2000);
169193

170194
if (!fs.existsSync(AIDER_DESK_DIR)) {
195+
logger.info(`Creating AiderDesk directory: ${AIDER_DESK_DIR}`);
171196
fs.mkdirSync(AIDER_DESK_DIR, { recursive: true });
172197
}
173198

@@ -177,27 +202,31 @@ export const performStartUp = async (updateProgress: UpdateProgressFunction): Pr
177202
message: 'Verifying Python installation...',
178203
});
179204

205+
logger.info('Checking Python version compatibility');
180206
await checkPythonVersion();
181207

182208
updateProgress({
183209
step: 'Creating Virtual Environment',
184210
message: 'Setting up Python virtual environment...',
185211
});
186212

213+
logger.info(`Creating Python virtual environment in: ${PYTHON_VENV_DIR}`);
187214
await createVirtualEnv();
188215

189216
updateProgress({
190217
step: 'Setting Up Connector',
191218
message: 'Installing Aider connector (this may take a while)...',
192219
});
193220

221+
logger.info('Setting up Aider connector');
194222
await setupAiderConnector();
195223

196224
updateProgress({
197225
step: 'Setting Up MCP Server',
198226
message: 'Installing MCP server...',
199227
});
200228

229+
logger.info('Setting up MCP server');
201230
await setupMcpServer();
202231

203232
updateProgress({
@@ -206,15 +235,21 @@ export const performStartUp = async (updateProgress: UpdateProgressFunction): Pr
206235
});
207236

208237
// Create setup complete file
238+
logger.info(`Creating setup complete file: ${SETUP_COMPLETE_FILENAME}`);
209239
fs.writeFileSync(SETUP_COMPLETE_FILENAME, new Date().toISOString());
210240

241+
logger.info('AiderDesk setup completed successfully');
211242
return true;
212243
} catch (error) {
244+
logger.error('AiderDesk setup failed', { error });
245+
213246
// Clean up if setup fails
214247
if (fs.existsSync(PYTHON_VENV_DIR)) {
248+
logger.info(`Removing virtual environment directory: ${PYTHON_VENV_DIR}`);
215249
fs.rmSync(PYTHON_VENV_DIR, { recursive: true, force: true });
216250
}
217251
if (fs.existsSync(SETUP_COMPLETE_FILENAME)) {
252+
logger.info(`Removing setup complete file: ${SETUP_COMPLETE_FILENAME}`);
218253
fs.unlinkSync(SETUP_COMPLETE_FILENAME);
219254
}
220255
throw error;

0 commit comments

Comments
 (0)