From 9d1a287f91fb2d50fe4107d6a5bc31695f4af650 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Fri, 12 Sep 2025 12:30:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20`chsrc=5Frun=5Fdirectly()`?= =?UTF-8?q?=20=E5=B9=B6=E4=BF=AE=E5=A4=8D=20`pip`=20=E5=9C=A8=20`get`=20?= =?UTF-8?q?=E6=97=B6=E5=9C=A8=20Windows=20=E4=B8=8A=E6=89=BE=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E8=B7=AF=E5=BE=84=E7=9A=84=E9=97=AE=E9=A2=98=20[GitHu?= =?UTF-8?q?b=20#286]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/framework/core.c | 24 +++++++++++++++++++++++- src/recipe/lang/Python/pip.c | 13 +++++++------ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/framework/core.c b/src/framework/core.c index 364b1e6..94ac56e 100644 --- a/src/framework/core.c +++ b/src/framework/core.c @@ -10,7 +10,7 @@ * | BingChunMoLi * | * Created On : <2023-08-29> - * Last Modified : <2025-08-27> + * Last Modified : <2025-09-12> * * chsrc framework * ------------------------------------------------------------*/ @@ -1348,6 +1348,28 @@ chsrc_run_as_a_service (const char *cmd) } +/** + * @brief 以纯粹的方式直接运行命令,不做任何多余处理, + * 命令执行前显示给用户,并保留所有输出给用户 + * + * @return 返回命令的退出状态 + */ +int +chsrc_run_directly (const char *cmd) +{ + if (ENGLISH) + xy_log_brkt (blue (App_Name), bdblue ("RUN"), blue (cmd)); + else + xy_log_brkt (blue (App_Name), bdblue ("运行"), blue (cmd)); + + if (in_dry_run_mode()) + { + return 0; // Dry Run 此时立即结束,并不真正执行 + } + int status = system (cmd); + return status; +} + /** * @brief 在本目录创建一个临时文件 diff --git a/src/recipe/lang/Python/pip.c b/src/recipe/lang/Python/pip.c index 81b2ea4..4fdf0ca 100644 --- a/src/recipe/lang/Python/pip.c +++ b/src/recipe/lang/Python/pip.c @@ -10,7 +10,7 @@ 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-09-10"); + chef_set_last_updated (this, "2025-09-12"); chef_set_sources_last_updated (this, "2025-07-11"); chef_set_chef (this, NULL); @@ -31,12 +31,13 @@ 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 2>/dev/null"); - - int status = system (cmd); + char *cmd = xy_2strcat (py_prog_name, " -m pip config get global.index-url"); + + int status = chsrc_run_directly (cmd); if (0 == status) { // 执行成功时显示当前源 + xy_noop (); } else { @@ -45,9 +46,9 @@ pl_python_pip_getsrc (char *option) 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); + say (default_source.url); } }