Skip to content

Commit bdc963c

Browse files
committed
fix(desktop): retry pip install for uv-managed runtime
1 parent 3108863 commit bdc963c

1 file changed

Lines changed: 52 additions & 17 deletions

File tree

desktop/scripts/build-backend.mjs

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,30 +96,65 @@ const installRuntimeDependencies = (runtimePython) => {
9696
throw new Error(`Backend requirements file does not exist: ${requirementsPath}`);
9797
}
9898

99-
const installArgs = [
100-
'-m',
101-
'pip',
102-
'--disable-pip-version-check',
103-
'install',
104-
'--no-cache-dir',
105-
'-r',
106-
requirementsPath,
107-
];
108-
const installResult = spawnSync(runtimePython.absolute, installArgs, {
109-
cwd: outputDir,
110-
stdio: 'inherit',
111-
windowsHide: true,
112-
});
99+
const runPipInstall = (extraArgs = []) => {
100+
const installArgs = [
101+
'-m',
102+
'pip',
103+
'--disable-pip-version-check',
104+
'install',
105+
'--no-cache-dir',
106+
'-r',
107+
requirementsPath,
108+
...extraArgs,
109+
];
110+
const installResult = spawnSync(runtimePython.absolute, installArgs, {
111+
cwd: outputDir,
112+
stdio: ['ignore', 'pipe', 'pipe'],
113+
encoding: 'utf8',
114+
windowsHide: true,
115+
});
116+
if (installResult.stdout) {
117+
process.stdout.write(installResult.stdout);
118+
}
119+
if (installResult.stderr) {
120+
process.stderr.write(installResult.stderr);
121+
}
122+
return installResult;
123+
};
124+
125+
let installResult = runPipInstall();
113126
if (installResult.error) {
114127
throw new Error(
115128
`Failed to install backend runtime dependencies: ${installResult.error.message}`,
116129
);
117130
}
118-
if (installResult.status !== 0) {
119-
throw new Error(
120-
`Backend runtime dependency installation failed with exit code ${installResult.status}.`,
131+
if (installResult.status === 0) {
132+
return;
133+
}
134+
135+
const outputText = `${installResult.stderr || ''}\n${installResult.stdout || ''}`;
136+
const shouldRetryWithBreakSystemPackages =
137+
outputText.includes('externally-managed-environment') ||
138+
outputText.includes('This environment is externally managed');
139+
140+
if (shouldRetryWithBreakSystemPackages) {
141+
console.warn(
142+
'Detected externally managed Python runtime; retrying pip install with --break-system-packages.',
121143
);
144+
installResult = runPipInstall(['--break-system-packages']);
145+
if (installResult.error) {
146+
throw new Error(
147+
`Failed to install backend runtime dependencies: ${installResult.error.message}`,
148+
);
149+
}
150+
if (installResult.status === 0) {
151+
return;
152+
}
122153
}
154+
155+
throw new Error(
156+
`Backend runtime dependency installation failed with exit code ${installResult.status}.`,
157+
);
123158
};
124159

125160
const main = () => {

0 commit comments

Comments
 (0)