Skip to content

Commit d3e8024

Browse files
committed
fix(pip): 修复 pip 的 getsrc
使用 `python -m pip config get global.index-url 2>/dev/null` 获取源,失败时会退至显示默认源 Close: #272
1 parent 32feeae commit d3e8024

File tree

1 file changed

+20
-4
lines changed
  • src/recipe/lang/Python

1 file changed

+20
-4
lines changed

src/recipe/lang/Python/pip.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ pl_python_pip_prelude (void)
1010
chef_prep_this (pl_python_pip, gsr);
1111

1212
chef_set_created_on (this, "2023-09-03");
13-
chef_set_last_updated (this, "2025-07-11");
13+
chef_set_last_updated (this, "2025-09-10");
1414
chef_set_sources_last_updated (this, "2025-07-11");
1515

1616
chef_set_chef (this, NULL);
1717
chef_set_cooks (this, 1, "@ccmywish");
18-
chef_set_sauciers (this, 0);
18+
chef_set_sauciers (this, 1, "@happy-game");
1919

2020
chef_allow_local_mode (this, CanNot, NULL, NULL);
2121
chef_allow_english(this);
@@ -31,8 +31,24 @@ pl_python_pip_getsrc (char *option)
3131
char *py_prog_name = NULL;
3232
pl_python_get_py_program_name (&py_prog_name);
3333

34-
char *cmd = xy_2strcat (py_prog_name, " -m pip config get global.index-url");
35-
chsrc_run (cmd, RunOpt_Default);
34+
char *cmd = xy_2strcat (py_prog_name, " -m pip config get global.index-url 2>/dev/null");
35+
36+
int status = system (cmd);
37+
if (0 == status)
38+
{
39+
// 执行成功时显示当前源
40+
}
41+
else
42+
{
43+
// 执行失败时显示默认源
44+
if (ENGLISH)
45+
chsrc_note2 ("No source configured in pip, showing default upstream source:");
46+
else
47+
chsrc_note2 ("pip 中未配置源,显示默认上游源:");
48+
49+
Source_t default_source = chsrc_yield_source (&pl_python_group_target, "upstream");
50+
chsrc_log (default_source.url);
51+
}
3652
}
3753

3854

0 commit comments

Comments
 (0)