From 5ec75b379ac445c81b25221020d1555135f9abbd Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Fri, 6 Dec 2024 10:56:38 +0800 Subject: [PATCH] Support `Rye` for `Python` [GitHub #127] --- src/chsrc-main.c | 6 ++- src/recipe/lang/Python/PDM.c | 2 +- src/recipe/lang/Python/Rye.c | 89 ++++++++++++++++++++++++++++++++++++ src/recipe/lang/Python/pip.c | 2 +- src/recipe/menu.c | 5 +- 5 files changed, 98 insertions(+), 6 deletions(-) create mode 100644 src/recipe/lang/Python/Rye.c diff --git a/src/chsrc-main.c b/src/chsrc-main.c index 56b80e5..19cef2b 100644 --- a/src/chsrc-main.c +++ b/src/chsrc-main.c @@ -17,14 +17,15 @@ * | GnixAij * | ChatGPT * | czyt + * | zouri * | * Created On : <2023-08-28> - * Last Modified : <2024-11-22> + * Last Modified : <2024-12-06> * * chsrc: Change Source —— 全平台通用命令行换源工具 * ------------------------------------------------------------*/ -#define Chsrc_Version "0.1.9.4" +#define Chsrc_Version "0.1.9.4-dev1" #define Chsrc_Release_Date "2024/11/22" #define Chsrc_Banner_Version "v" Chsrc_Version "-" Chsrc_Release_Date #define Chsrc_Maintain_URL "https://github.com/RubyMetric/chsrc" @@ -38,6 +39,7 @@ #include "recipe/lang/Python/pip.c" #include "recipe/lang/Python/Poetry.c" #include "recipe/lang/Python/PDM.c" + #include "recipe/lang/Python/Rye.c" #include "recipe/lang/Python/Python.c" #include "recipe/lang/Node.js/common.h" diff --git a/src/recipe/lang/Python/PDM.c b/src/recipe/lang/Python/PDM.c index 292ec7b..e2e0b0d 100644 --- a/src/recipe/lang/Python/PDM.c +++ b/src/recipe/lang/Python/PDM.c @@ -2,7 +2,7 @@ * SPDX-License-Identifier: GPL-3.0-or-later * ------------------------------------------------------------- * File Authors : Aoran Zeng - * Contributors : Nul None + * Contributors : Nul None * Created On : <2024-06-05> * Last Modified : <2024-09-14> * ------------------------------------------------------------*/ diff --git a/src/recipe/lang/Python/Rye.c b/src/recipe/lang/Python/Rye.c new file mode 100644 index 0000000..a0b4433 --- /dev/null +++ b/src/recipe/lang/Python/Rye.c @@ -0,0 +1,89 @@ +/** ------------------------------------------------------------ + * SPDX-License-Identifier: GPL-3.0-or-later + * ------------------------------------------------------------- + * File Authors : Aoran Zeng + * Contributors : Nul None + * Created On : <2024-12-06> + * Last Modified : <2024-12-06> + * + * 由于Rye已经有后继uv了,所以我们不把该管理器纳入Python group中 + * ------------------------------------------------------------*/ + +char * +pl_python_find_rye_config () +{ + char *buf = xy_run ("rye config --show-path", 0, NULL); + char *rye_config = xy_normalize_path (xy_str_strip (buf)); + + return rye_config; +} + +/** + * chsrc get rye + */ +void +pl_python_rye_getsrc (char *option) +{ + char *rye_config = pl_python_find_rye_config (); + chsrc_note2 (xy_strjoin (3, "请查看 ", rye_config, " 配置文件中的 [[sources]] 节内容")); +} + + +/** + * @consult https://github.com/RubyMetric/chsrc/issues/127 + * @consult recipe Java + * + * chsrc set rye + */ +void +pl_python_rye_setsrc (char *option) +{ + chsrc_yield_source_and_confirm (pl_python); + + const char *file = xy_strjoin (7, + "[[sources]]\n", + "name = \"", source.mirror->abbr, "\"\n", + "url = \"", source.url, "\""); + + char *rye_config = pl_python_find_rye_config (); + chsrc_note2 (xy_strjoin (3, "请在您的 Rye 配置文件 ", rye_config, " 中添加:")); + puts (file); + + ProgMode_ChgType = ChgType_Manual; + chsrc_conclude (&source); +} + + +/** + * chsrc reset rye + */ +void +pl_python_rye_resetsrc (char *option) +{ + pl_python_rye_setsrc (option); +} + + +/** + * chsrc ls rye + */ +Feature_t +pl_python_rye_feat (char *option) +{ + Feature_t f = {0}; + + f.can_get = true; + f.can_reset = true; + + f.cap_locally = true; + f.cap_locally_explain = NULL; + + f.can_english = false; + f.can_user_define = true; + + f.note = NULL; + return f; +} + +// def_target_gsrf(pl_python_rye); +Target_t pl_python_rye_target = {def_target_inner_gsrf(pl_python_rye),def_target_sourcesn(pl_python)}; diff --git a/src/recipe/lang/Python/pip.c b/src/recipe/lang/Python/pip.c index fc953ef..4e88753 100644 --- a/src/recipe/lang/Python/pip.c +++ b/src/recipe/lang/Python/pip.c @@ -2,7 +2,7 @@ * SPDX-License-Identifier: GPL-3.0-or-later * ------------------------------------------------------------- * File Authors : Aoran Zeng - * Contributors : Nul None + * Contributors : Nul None * Created On : <2023-09-03> * Last Modified : <2024-09-14> * ------------------------------------------------------------*/ diff --git a/src/recipe/menu.c b/src/recipe/menu.c index 0a5f7d8..c17e040 100644 --- a/src/recipe/menu.c +++ b/src/recipe/menu.c @@ -5,7 +5,7 @@ * Contributors : Nil Null * Created On : <2023-09-01> * Major Revision : 1 - * Last Modified : <2024-10-29> + * Last Modified : <2024-12-06> * ------------------------------------------------------------*/ /* Begin Target Matrix */ @@ -17,6 +17,7 @@ static const char *pl_python_pip[] = {"pip", NULL, t(&pl_python_pip_target)}, *pl_python_poetry[] = {"poetry", NULL, t(&pl_python_poetry_target)}, *pl_python_pdm[] = {"pdm", NULL, t(&pl_python_pdm_target)}, + *pl_python_rye[] = {"rye", NULL, t(&pl_python_rye_target)}, *pl_nodejs[] = {"node", "nodejs", NULL, t(&pl_nodejs_target)}, *pl_nodejs_bun[] = {"bun", NULL, t(&pl_nodejs_bun_target)}, @@ -47,7 +48,7 @@ static const char **pl_packagers[] = { pl_ruby, - pl_python, pl_python_pip, pl_python_poetry, pl_python_pdm, + pl_python, pl_python_pip, pl_python_poetry, pl_python_pdm, pl_python_rye, pl_nodejs, pl_nodejs_bun, pl_nodejs_npm, pl_nodejs_pnpm, pl_nodejs_yarn, pl_nodejs_nvm,