mirror of
https://github.com/whyour/qinglong.git
synced 2026-01-27 10:25:40 +08:00
Address code review feedback: improve pattern matching and error handling
Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
This commit is contained in:
parent
023d0f1cc4
commit
f3ec352066
|
|
@ -535,16 +535,30 @@ export async function setSystemTimezone(timezone: string): Promise<boolean> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper function to check if a name is a GitHub URL
|
||||||
|
function isGitHubUrl(name: string): boolean {
|
||||||
|
return !!name.match(/^(https?:\/\/|git\+)/i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to check if a name is a requirements file
|
||||||
|
function isRequirementsFile(name: string): boolean {
|
||||||
|
return !!name.match(/requirements.*\.(txt|in)$/i) || name === 'requirements.txt';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to check if a name is a pyproject.toml file
|
||||||
|
function isPyprojectToml(name: string): boolean {
|
||||||
|
return name.endsWith('pyproject.toml');
|
||||||
|
}
|
||||||
|
|
||||||
export function getGetCommand(type: DependenceTypes, name: string): string {
|
export function getGetCommand(type: DependenceTypes, name: string): string {
|
||||||
const trimmedName = name.trim();
|
const trimmedName = name.trim();
|
||||||
|
|
||||||
// For Python dependencies installed from GitHub or requirements files,
|
// For Python dependencies installed from GitHub or requirements files,
|
||||||
// we can't reliably check if they're installed, so skip the check
|
// we can't reliably check if they're installed, so skip the check
|
||||||
if (type === DependenceTypes.python3) {
|
if (type === DependenceTypes.python3) {
|
||||||
if (trimmedName.match(/^(https?:\/\/|git\+)/i) ||
|
if (isGitHubUrl(trimmedName) ||
|
||||||
trimmedName.match(/\.(txt|in)$/i) ||
|
isRequirementsFile(trimmedName) ||
|
||||||
trimmedName.includes('requirements') ||
|
isPyprojectToml(trimmedName)) {
|
||||||
trimmedName.endsWith('pyproject.toml')) {
|
|
||||||
// Return a command that will always indicate not installed
|
// Return a command that will always indicate not installed
|
||||||
// This ensures GitHub URLs and requirements files are always installed
|
// This ensures GitHub URLs and requirements files are always installed
|
||||||
return 'echo ""';
|
return 'echo ""';
|
||||||
|
|
@ -590,18 +604,24 @@ export function getInstallCommand(type: DependenceTypes, name: string): string {
|
||||||
// Handle different installation methods for Python
|
// Handle different installation methods for Python
|
||||||
if (type === DependenceTypes.python3) {
|
if (type === DependenceTypes.python3) {
|
||||||
// Check if it's a GitHub URL (support both git+ and direct URLs)
|
// Check if it's a GitHub URL (support both git+ and direct URLs)
|
||||||
if (trimmedName.match(/^(https?:\/\/|git\+)/i)) {
|
if (isGitHubUrl(trimmedName)) {
|
||||||
return `${command} ${trimmedName}`;
|
return `${command} ${trimmedName}`;
|
||||||
}
|
}
|
||||||
// Check if it's a requirements file path
|
// Check if it's a requirements file path
|
||||||
if (trimmedName.match(/\.(txt|in)$/i) || trimmedName.includes('requirements')) {
|
if (isRequirementsFile(trimmedName)) {
|
||||||
return `${command} -r ${trimmedName}`;
|
return `${command} -r ${trimmedName}`;
|
||||||
}
|
}
|
||||||
// Check if it's a pyproject.toml file
|
// Check if it's a pyproject.toml file
|
||||||
if (trimmedName.endsWith('pyproject.toml')) {
|
if (isPyprojectToml(trimmedName)) {
|
||||||
// For pyproject.toml, install from the directory containing it
|
// For pyproject.toml, install from the directory containing it
|
||||||
const dir = trimmedName.replace(/\/pyproject\.toml$/, '');
|
const pathMatch = trimmedName.match(/^(.+)\/pyproject\.toml$/);
|
||||||
return dir && dir !== 'pyproject.toml' ? `${command} ${dir}` : `${command} .`;
|
if (pathMatch) {
|
||||||
|
// Has a path prefix, use the directory
|
||||||
|
return `${command} ${pathMatch[1]}`;
|
||||||
|
} else {
|
||||||
|
// Just "pyproject.toml", install current directory
|
||||||
|
return `${command} .`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -124,8 +124,12 @@ auto_install_python_deps() {
|
||||||
if [[ -f "${repo_path}/requirements.txt" ]]; then
|
if [[ -f "${repo_path}/requirements.txt" ]]; then
|
||||||
echo -e "发现 requirements.txt,开始自动安装依赖...\n"
|
echo -e "发现 requirements.txt,开始自动安装依赖...\n"
|
||||||
local req_file="${dir_scripts}/${uniq_path}/requirements.txt"
|
local req_file="${dir_scripts}/${uniq_path}/requirements.txt"
|
||||||
cp -f "${repo_path}/requirements.txt" "${req_file}"
|
|
||||||
|
|
||||||
|
# 确保目标目录存在
|
||||||
|
make_dir "${dir_scripts}/${uniq_path}"
|
||||||
|
|
||||||
|
# 复制文件并检查结果
|
||||||
|
if cp -f "${repo_path}/requirements.txt" "${req_file}" 2>/dev/null; then
|
||||||
# 调用API添加依赖安装任务
|
# 调用API添加依赖安装任务
|
||||||
local dep_name="${uniq_path}/requirements.txt"
|
local dep_name="${uniq_path}/requirements.txt"
|
||||||
local currentTimeStamp=$(date +%s)
|
local currentTimeStamp=$(date +%s)
|
||||||
|
|
@ -141,14 +145,21 @@ auto_install_python_deps() {
|
||||||
else
|
else
|
||||||
echo -e "添加 requirements.txt 依赖失败,请手动添加\n"
|
echo -e "添加 requirements.txt 依赖失败,请手动添加\n"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
echo -e "复制 requirements.txt 失败,跳过自动安装\n"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 检查 pyproject.toml
|
# 检查 pyproject.toml
|
||||||
if [[ -f "${repo_path}/pyproject.toml" ]]; then
|
if [[ -f "${repo_path}/pyproject.toml" ]]; then
|
||||||
echo -e "发现 pyproject.toml,开始自动安装依赖...\n"
|
echo -e "发现 pyproject.toml,开始自动安装依赖...\n"
|
||||||
local pyproject_file="${dir_scripts}/${uniq_path}/pyproject.toml"
|
local pyproject_file="${dir_scripts}/${uniq_path}/pyproject.toml"
|
||||||
cp -f "${repo_path}/pyproject.toml" "${pyproject_file}"
|
|
||||||
|
|
||||||
|
# 确保目标目录存在
|
||||||
|
make_dir "${dir_scripts}/${uniq_path}"
|
||||||
|
|
||||||
|
# 复制文件并检查结果
|
||||||
|
if cp -f "${repo_path}/pyproject.toml" "${pyproject_file}" 2>/dev/null; then
|
||||||
# 调用API添加依赖安装任务
|
# 调用API添加依赖安装任务
|
||||||
local dep_name="${uniq_path}/pyproject.toml"
|
local dep_name="${uniq_path}/pyproject.toml"
|
||||||
local currentTimeStamp=$(date +%s)
|
local currentTimeStamp=$(date +%s)
|
||||||
|
|
@ -164,6 +175,9 @@ auto_install_python_deps() {
|
||||||
else
|
else
|
||||||
echo -e "添加 pyproject.toml 依赖失败,请手动添加\n"
|
echo -e "添加 pyproject.toml 依赖失败,请手动添加\n"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
echo -e "复制 pyproject.toml 失败,跳过自动安装\n"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user