Aoran Zeng 7901491c39
Skip pip when -local
[GitHub #79]
2024-09-13 19:33:00 +08:00

109 lines
3.0 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 : <2024-09-13>
* ------------------------------------------------------------*/
/**
* @update 2024-05-24
* @note 不要添加Zju浙大的pypi在校外访问会自动转向Tuna
*/
static SourceInfo
pl_python_pip_sources[] = {
{&Upstream, "https://pypi.org/simple"},
{&Bfsu, "https://mirrors.bfsu.edu.cn/pypi/web/simple"},
{&Lzuoss, "https://mirror.lzu.edu.cn/pypi/web/simple"},
{&Jlu, "https://mirrors.jlu.edu.cn/pypi/web/simple"},
{&Sjtug_Zhiyuan, "https://mirror.sjtu.edu.cn/pypi/web/simple"},
{&Tuna, "https://pypi.tuna.tsinghua.edu.cn/simple"},
{&Ali, "https://mirrors.aliyun.com/pypi/simple/"},
{&Tencent, "https://mirrors.cloud.tencent.com/pypi/simple"},
{&Huawei, "https://mirrors.huaweicloud.com/repository/pypi/simple"},
{&Hust, "https://mirrors.hust.edu.cn/pypi/web/simple"}
// {&Netease, "https://mirrors.163.com/.help/pypi.html"} // 不用24小时更新一次
};
def_sources_n(pl_python_pip);
/**
* 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 (CliOpt_Locally)
{
char *msg = CliOpt_InEnglish ? "pip doesn't support `-local`. SKIP changing source!" : "pip 不支持 -local跳过换源";
chsrc_error (msg);
// 不能直接退出,因为 Leader target 不能就此结束
return;
}
chsrc_yield_source_and_confirm (pl_python_pip);
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);
chsrc_conclude (&source, ChsrcTypeAuto);
}
/**
* chsrc reset pip
*/
void
pl_python_pip_resetsrc (char *option)
{
pl_python_pip_setsrc (ChsrcTypeReset);
}
/**
* chsrc ls pip
*/
FeatInfo
pl_python_pip_feat (char *option)
{
FeatInfo fi = {0};
fi.can_get = true;
fi.can_reset = true;
// pip 不支持项目级换源
fi.stcan_locally = CanNot;
fi.locally = NULL;
fi.can_english = true;
fi.can_user_define = true;
fi.note = NULL;
return fi;
}
def_target_gsrf(pl_python_pip);