fix(pip): 修复 pip 的 getsrc

使用  `python -m pip config get global.index-url 2>/dev/null`
获取源,失败时会退至显示默认源

Close: #272
This commit is contained in:
happy-game 2025-09-10 04:52:34 +00:00
parent 32feeaea1b
commit d3e8024553

View File

@ -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);
}
}