From d3e8024553cc93290df976e7265727b32a24cfb9 Mon Sep 17 00:00:00 2001 From: happy-game Date: Wed, 10 Sep 2025 04:52:34 +0000 Subject: [PATCH] =?UTF-8?q?fix(pip):=20=E4=BF=AE=E5=A4=8D=20pip=20?= =?UTF-8?q?=E7=9A=84=20getsrc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用 `python -m pip config get global.index-url 2>/dev/null` 获取源,失败时会退至显示默认源 Close: #272 --- src/recipe/lang/Python/pip.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/recipe/lang/Python/pip.c b/src/recipe/lang/Python/pip.c index db26c49..81b2ea4 100644 --- a/src/recipe/lang/Python/pip.c +++ b/src/recipe/lang/Python/pip.c @@ -10,12 +10,12 @@ pl_python_pip_prelude (void) chef_prep_this (pl_python_pip, gsr); chef_set_created_on (this, "2023-09-03"); - chef_set_last_updated (this, "2025-07-11"); + chef_set_last_updated (this, "2025-09-10"); chef_set_sources_last_updated (this, "2025-07-11"); chef_set_chef (this, NULL); chef_set_cooks (this, 1, "@ccmywish"); - chef_set_sauciers (this, 0); + chef_set_sauciers (this, 1, "@happy-game"); chef_allow_local_mode (this, CanNot, NULL, NULL); chef_allow_english(this); @@ -31,8 +31,24 @@ pl_python_pip_getsrc (char *option) char *py_prog_name = NULL; pl_python_get_py_program_name (&py_prog_name); - char *cmd = xy_2strcat (py_prog_name, " -m pip config get global.index-url"); - chsrc_run (cmd, RunOpt_Default); + char *cmd = xy_2strcat (py_prog_name, " -m pip config get global.index-url 2>/dev/null"); + + int status = system (cmd); + if (0 == status) + { + // 执行成功时显示当前源 + } + else + { + // 执行失败时显示默认源 + if (ENGLISH) + chsrc_note2 ("No source configured in pip, showing default upstream source:"); + else + chsrc_note2 ("pip 中未配置源,显示默认上游源:"); + + Source_t default_source = chsrc_yield_source (&pl_python_group_target, "upstream"); + chsrc_log (default_source.url); + } }