2025-07-14 15:08:10 +08:00

95 lines
2.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/** ------------------------------------------------------------
* SPDX-License-Identifier: GPL-3.0-or-later
* -------------------------------------------------------------
* File Authors : Aoran Zeng <ccmywish@qq.com>
* Contributors : Nul None <nul@none.org>
* Created On : <2023-09-03>
* Last Modified : <2025-07-11>
* ------------------------------------------------------------*/
/**
* chsrc get pip
*/
void
pl_python_pip_getsrc (char *option)
{
char *py_prog_name = NULL;
pl_python_get_py_program_name (&py_prog_name);
char *cmd = xy_2strjoin (py_prog_name, " -m pip config get global.index-url");
chsrc_run (cmd, RunOpt_Default);
}
/**
* @consult https://mirrors.tuna.tsinghua.edu.cn/help/pypi/
*
* chsrc set pip
*/
void
pl_python_pip_setsrc (char *option)
{
// 对于不支持的情况,尽早结束
if (chsrc_in_local_mode())
{
char *msg = ENGLISH ? "pip doesn't support `-local`. SKIP changing source!" : "pip 不支持 -local跳过换源";
chsrc_error (msg);
// 不能直接退出,因为 Leader target 不能就此结束
return;
}
chsrc_yield_source (pl_python_group);
if (chsrc_in_standalone_mode())
chsrc_confirm_source();
char *py_prog_name = NULL;
pl_python_get_py_program_name (&py_prog_name);
// 这里用的是 config --user会写入用户目录而不是项目目录
// https://github.com/RubyMetric/chsrc/issues/39
// 经测试Windows上调用换源命令会写入 C:\Users\RubyMetric\AppData\Roaming\pip\pip.ini
char *cmd = xy_2strjoin (py_prog_name, xy_2strjoin (" -m pip config --user set global.index-url ", source.url));
chsrc_run (cmd, RunOpt_No_Last_New_Line);
if (chsrc_in_standalone_mode())
{
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}
}
/**
* chsrc reset pip
*/
void
pl_python_pip_resetsrc (char *option)
{
pl_python_pip_setsrc (option);
}
/**
* chsrc ls pip
*/
Feature_t
pl_python_pip_feat (char *option)
{
Feature_t f = {0};
f.can_get = true;
f.can_reset = true;
// pip 不支持项目级换源
f.cap_locally = CanNot;
f.cap_locally_explain = NULL;
f.can_english = true;
f.can_user_define = true;
f.note = NULL;
return f;
}
// def_target_gsrf(pl_python_pip);
Target_t pl_python_pip_target = {def_target_inner_gsrf(pl_python_pip),def_target_sourcesn(pl_python_group)};