Skip to content

Commit 05ac8f3

Browse files
committed
format
1 parent 45d5280 commit 05ac8f3

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

src/installer/get-python.js

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ export async function findPythonExecutable() {
6666
for (const exename of exenames) {
6767
const executable = path.normalize(path.join(location, exename)).replace(/"/g, '');
6868
try {
69-
if (fs.existsSync(executable) &&
70-
(await isValidPythonVersion(executable)) &&
71-
(await callInstallerScript(executable, ['check', 'python']))) {
69+
if (
70+
fs.existsSync(executable) &&
71+
(await isValidPythonVersion(executable)) &&
72+
(await callInstallerScript(executable, ['check', 'python']))
73+
) {
7274
log('info', `Found compatible Python: ${executable}`);
7375
return executable;
7476
}
@@ -101,7 +103,7 @@ async function isValidPythonVersion(executable) {
101103
const output = execSync(`"${executable}" --version`, {
102104
encoding: 'utf8',
103105
timeout: 3000,
104-
stdio: ['ignore', 'pipe', 'pipe']
106+
stdio: ['ignore', 'pipe', 'pipe'],
105107
});
106108

107109
const versionMatch = output.match(/Python (\d+\.\d+\.\d+)/);
@@ -141,14 +143,21 @@ async function installUV() {
141143
try {
142144
if (proc.IS_WINDOWS) {
143145
// Windows: Use PowerShell with official installer script
144-
await execFile('powershell', [
145-
'-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command',
146-
'irm https://astral.sh/uv/install.ps1 | iex'
147-
], { timeout: 120000 });
146+
await execFile(
147+
'powershell',
148+
[
149+
'-NoProfile',
150+
'-ExecutionPolicy',
151+
'Bypass',
152+
'-Command',
153+
'irm https://astral.sh/uv/install.ps1 | iex',
154+
],
155+
{ timeout: 120000 },
156+
);
148157
} else {
149158
// Unix/Linux/macOS: Use shell with curl installer
150159
await execFile('sh', ['-c', 'curl -LsSf https://astral.sh/uv/install.sh | sh'], {
151-
timeout: 120000
160+
timeout: 120000,
152161
});
153162
}
154163

@@ -167,7 +176,7 @@ async function installUV() {
167176
* @returns {Promise<string>} Path to installed Python directory
168177
* @throws {Error} If UV installation or Python installation fails
169178
*/
170-
async function installPythonWithUV(destinationDir, pythonVersion = "3.13") {
179+
async function installPythonWithUV(destinationDir, pythonVersion = '3.13') {
171180
log('info', `Installing Python ${pythonVersion} using UV`);
172181

173182
// Ensure UV is available, install if necessary
@@ -190,22 +199,21 @@ async function installPythonWithUV(destinationDir, pythonVersion = "3.13") {
190199
const env = {
191200
...process.env,
192201
UV_PYTHON_INSTALL_DIR: destinationDir,
193-
UV_CACHE_DIR: path.join(core.getTmpDir(), 'uv-cache')
202+
UV_CACHE_DIR: path.join(core.getTmpDir(), 'uv-cache'),
194203
};
195204

196205
// Execute UV Python installation command
197206
await execFile('uv', ['python', 'install', pythonVersion], {
198207
env,
199208
timeout: 300000, // 5 minutes timeout for download and installation
200-
cwd: destinationDir
209+
cwd: destinationDir,
201210
});
202211

203212
// Verify that Python executable was successfully installed
204213
await ensurePythonExeExists(destinationDir, pythonVersion);
205214

206215
log('info', `Python ${pythonVersion} installation completed: ${destinationDir}`);
207216
return destinationDir;
208-
209217
} catch (err) {
210218
throw new Error(`UV Python installation failed: ${err.message}`);
211219
}
@@ -219,7 +227,7 @@ async function installPythonWithUV(destinationDir, pythonVersion = "3.13") {
219227
* @returns {Promise<boolean>} True if executable exists and is accessible
220228
* @throws {Error} If no Python executable found in expected locations
221229
*/
222-
async function ensurePythonExeExists(pythonDir, pythonVersion = "3.13") {
230+
async function ensurePythonExeExists(pythonDir, pythonVersion = '3.13') {
223231
// UV typically installs to subdirectories organized by version
224232
const possiblePaths = [
225233
pythonDir, // Direct installation in target directory
@@ -269,10 +277,12 @@ export async function installPortablePython(destinationDir, options = {}) {
269277

270278
// UV-based installation is now the only supported method
271279
try {
272-
return await installPythonWithUV(destinationDir, "3.13");
280+
return await installPythonWithUV(destinationDir, '3.13');
273281
} catch (uvError) {
274282
log('error', `UV installation failed: ${uvError.message}`);
275-
throw new Error(`Python installation failed: ${uvError.message}. Please ensure UV can be installed and internet connection is available.`);
283+
throw new Error(
284+
`Python installation failed: ${uvError.message}. Please ensure UV can be installed and internet connection is available.`,
285+
);
276286
}
277287
}
278288

@@ -313,9 +323,4 @@ function getPythonExecutablePath(pythonDir) {
313323
}
314324

315325
// Export utility functions for external use
316-
export {
317-
isPythonVersionCompatible,
318-
isUVAvailable,
319-
installUV,
320-
getPythonExecutablePath
321-
};
326+
export { isPythonVersionCompatible, isUVAvailable, installUV, getPythonExecutablePath };

0 commit comments

Comments
 (0)