Skip to content

Commit 3432ce9

Browse files
Install setuptools/packaging for Windows ToDesktop (#1538)
Fix todesktop packaging by installing setuptools/packaging for the Windows Python 3.12 setup. See https://app.todesktop.com/apps/241012ess7yxs0e/builds/260116d9lblocni This is generally blocking build and release for todesktop. The alternative is a hacky approach where we build and send it to todesktop just for publishing. This is only ran during packaging in todesktop. See https://app.todesktop.com/apps/241012ess7yxs0e/builds/260116ge2tj9796 for the run based off of this branch. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-1538-Install-setuptools-packaging-for-Windows-ToDesktop-2ea6d73d365081389eb2c3710f2fb710) by [Unito](https://www.unito.io)
1 parent 0a5fcbb commit 3432ce9

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

scripts/todesktop/beforeInstall.cjs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,55 @@ module.exports = async ({ pkgJsonPath, pkgJson, appDir, hookName }) => {
2424
shell: true,
2525
stdio: 'ignore',
2626
});
27+
28+
const pythonMajorMinor = '3.12';
29+
const expectedPrefix = `Python ${pythonMajorMinor}`;
30+
31+
const versionMatches = (bin, args = []) => {
32+
const result = spawnSync(bin, [...args, '--version'], { shell: true, encoding: 'utf8' });
33+
const output = `${result.stdout || ''}${result.stderr || ''}`.trim();
34+
return result.status === 0 && output.startsWith(expectedPrefix);
35+
};
36+
37+
const resolvePython312 = () => {
38+
const localAppData = process.env.LOCALAPPDATA;
39+
const programFiles = process.env.ProgramFiles || 'C:\\Program Files';
40+
const programFilesX86 = process.env['ProgramFiles(x86)'] || 'C:\\Program Files (x86)';
41+
const candidates = [
42+
{ bin: process.env.PYTHON_3_12 },
43+
{ bin: process.env.PYTHON },
44+
{ bin: 'py', args: ['-3.12'] },
45+
{ bin: path.join(programFiles, 'Python312', 'python.exe') },
46+
{ bin: path.join(programFilesX86, 'Python312', 'python.exe') },
47+
localAppData ? { bin: path.join(localAppData, 'Programs', 'Python', 'Python312', 'python.exe') } : null,
48+
{ bin: 'python3.12' },
49+
{ bin: 'python' },
50+
];
51+
for (const candidate of candidates) {
52+
if (!candidate || !candidate.bin) continue;
53+
if (versionMatches(candidate.bin, candidate.args)) return candidate;
54+
}
55+
return null;
56+
};
57+
58+
const pythonCandidate = resolvePython312();
59+
60+
if (!pythonCandidate) {
61+
console.error(`[ToDesktop Windows] Python ${pythonMajorMinor} not found after installation attempts`);
62+
return;
63+
}
64+
65+
const pythonBin = pythonCandidate.bin;
66+
const pythonArgs = pythonCandidate.args || [];
67+
68+
console.log(`[ToDesktop Windows] Using Python at ${pythonBin}`);
69+
spawnSync(pythonBin, [...pythonArgs, '--version'], { shell: true, stdio: 'inherit' });
70+
71+
console.log('[ToDesktop Windows] Installing setuptools and packaging (brings distutils)');
72+
spawnSync(pythonBin, [...pythonArgs, '-m', 'pip', 'install', '--upgrade', 'setuptools', 'packaging'], {
73+
shell: true,
74+
stdio: 'inherit',
75+
});
2776
}
2877

2978
if (os.platform() === 'darwin') {

0 commit comments

Comments
 (0)