Separate pip out

[GitHub #79]
This commit is contained in:
Aoran Zeng 2024-09-13 19:12:13 +08:00
parent 5f4d5dc583
commit 0baf265c0a
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98

View File

@ -0,0 +1,99 @@
/** ------------------------------------------------------------
* 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 Zjupypi在校外访问会自动转向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)
{
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_Default);
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);