feat: Add configurable conda-forge URL for Python installation
- Implement getCondaForgeUrl function to fetch URL from config - Use configurable URL in Python installation process - Add error handling and fallback to default URL if needed
This commit is contained in:
parent
d2b6ff42ae
commit
429f52357d
@ -2,6 +2,7 @@ import { exec, spawn } from 'child_process';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { logger } from '../logger';
|
||||
import { DevChatConfig } from '../config';
|
||||
const fs = require('fs');
|
||||
|
||||
// Check if the environment already exists
|
||||
@ -125,11 +126,12 @@ export async function installPythonMicromamba(mambaCommandPath: string, envName:
|
||||
return pythonPath2;
|
||||
}
|
||||
|
||||
// Get conda-forge URL from config file
|
||||
const condaForgeUrl = getCondaForgeUrl();
|
||||
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
const cmd = mambaCommandPath;
|
||||
const args = ['create', '-n', envName, '-c', 'conda-forge', '-r', pathToMamba, `python=${pythonVersion}`, '--yes'];
|
||||
// output command and args in line
|
||||
// args to "create -n xx -c conda-forge ..."
|
||||
const args = ['create', '-n', envName, '-c', condaForgeUrl, '-r', pathToMamba, `python=${pythonVersion}`, '--yes'];
|
||||
logger.channel()?.info(`cmd: ${cmd} ${args.join(' ')}`);
|
||||
const child = spawn(cmd, args);
|
||||
|
||||
@ -162,3 +164,16 @@ export async function installPythonMicromamba(mambaCommandPath: string, envName:
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function getCondaForgeUrl(): string {
|
||||
const defaultUrl = "https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/";
|
||||
try {
|
||||
const config = DevChatConfig.getInstance();
|
||||
const url = config.get("conda-forge-url", defaultUrl);
|
||||
return url || defaultUrl; // 如果 url 是 undefined 或空字符串,返回默认 URL
|
||||
} catch (error) {
|
||||
logger.channel()?.error(`Error reading conda-forge URL from config: ${error}`);
|
||||
logger.channel()?.show();
|
||||
return defaultUrl;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user