Skip to content

Commit 463f909

Browse files
committed
Format uv.c
1 parent 7bfe7c7 commit 463f909

File tree

1 file changed

+41
-29
lines changed
  • src/recipe/lang/Python

1 file changed

+41
-29
lines changed

src/recipe/lang/Python/uv.c

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
* SPDX-License-Identifier: GPL-3.0-or-later
33
* -------------------------------------------------------------
44
* File Authors : happy game <[email protected]>
5-
* Contributors : ccy <[email protected]>
5+
* Contributors : ccy <[email protected]>
6+
* | Aoran Zeng <[email protected]>
7+
* |
68
* Created On : <2024-12-11>
7-
* Last Modified : <2025-04-02>
9+
* Last Modified : <2025-06-02>
810
* ------------------------------------------------------------*/
911

10-
1112
/**
1213
* chsrc get uv
14+
*
1315
* uv的配置优先级顺序如下(高到低):
1416
* 1. $workspaces/uv.toml
1517
* 2. $workspaces/pyproject.toml
@@ -27,36 +29,36 @@ pl_python_find_uv_config (bool mkdir)
2729
{
2830
if (CliOpt_Locally)
2931
{
30-
return xy_strjoin (2, UV_LOCAL_CONFIG_PATH, UV_CONFIG);
32+
return xy_2strjoin (UV_LOCAL_CONFIG_PATH, UV_CONFIG);
3133
}
3234
else
3335
{
3436
if (xy_on_windows)
3537
{
36-
// config path on Windows
37-
char *appdata = getenv("APPDATA");
38-
if (!appdata) {
39-
chsrc_error2 ("未能获取 APPDATA 环境变量");
40-
return NULL;
41-
}
42-
43-
char *config_dir = xy_strjoin(2, appdata, "\\uv\\");
38+
/* config path on Windows */
39+
char *appdata = getenv ("APPDATA");
40+
41+
if (!appdata)
42+
{
43+
chsrc_error2 ("未能获取 APPDATA 环境变量");
44+
return NULL;
45+
}
46+
47+
char *config_dir = xy_2strjoin(appdata, "\\uv\\");
4448
if (mkdir)
4549
{
4650
chsrc_ensure_dir (config_dir);
4751
}
48-
char *config_path = xy_strjoin (2, config_dir, UV_CONFIG);
49-
free(config_dir);
50-
return config_path;
52+
return xy_2strjoin (config_dir, UV_CONFIG);
5153
}
52-
else
54+
else
5355
{
54-
// config path on Linux or macOS
56+
/* config path on Linux or macOS */
5557
if (mkdir)
5658
{
5759
chsrc_ensure_dir (UV_USER_CONFIG_PATH);
5860
}
59-
return xy_strjoin (2, UV_USER_CONFIG_PATH, UV_CONFIG);
61+
return xy_2strjoin (UV_USER_CONFIG_PATH, UV_CONFIG);
6062
}
6163
}
6264
}
@@ -65,13 +67,17 @@ void
6567
pl_python_uv_getsrc (char *option)
6668
{
6769
char *uv_config = pl_python_find_uv_config (false);
70+
6871
if (!chsrc_check_file (uv_config))
6972
{
7073
chsrc_error2 ("未找到 uv 配置文件");
7174
return;
7275
}
73-
// grep -A 2 'index' config_file | sed -n 's/^url = "\(.*\)"/\1/p'
74-
// 获取 [[index]] 配置项的 url
76+
77+
/**
78+
* grep -A 2 'index' config_file | sed -n 's/^url = "\(.*\)"/\1/p'
79+
* 获取 [[index]] 配置项的 url
80+
*/
7581
char *cmd = xy_strjoin (3, "grep -A 2 'index' ",
7682
uv_config,
7783
" | sed -n 's/^url = \"\\(.*\\)\"/\\1/p'");
@@ -106,9 +112,11 @@ pl_python_uv_setsrc (char *option)
106112
"url = \"", source.url, "\"\\n",
107113
"default = true\\n");
108114

109-
// sed -i '/^\[\[index\]\]$/,/^default = true$/{s|^url = ".*"$|url = " source.url "|}' uv_config
110-
// 将 [[index]] 到 default = true 之间的 url = ".*" 替换为 url = "source.url"
111-
#if xy_on_macos
115+
/**
116+
* sed -i '/^\[\[index\]\]$/,/^default = true$/{s|^url = ".*"$|url = " source.url "|}' uv_config
117+
* 将 [[index]] 到 default = true 之间的 url = ".*" 替换为 url = "source.url"
118+
*/
119+
#if XY_On_macOS
112120
char *sed_cmd = "sed -i '' ";
113121
#else
114122
char *sed_cmd = "sed -i ";
@@ -124,21 +132,25 @@ pl_python_uv_setsrc (char *option)
124132
char *cmd = NULL;
125133
if (!xy_file_exist (uv_config))
126134
{
127-
// uv_config 不存在,追加到新文件末尾
128-
// run: append_source_cmd
135+
/**
136+
* uv_config 不存在,追加到新文件末尾
137+
* run: append_source_cmd
138+
*/
129139
cmd = append_source_cmd;
130140
}
131141
else
132142
{
133143
if (xy_on_windows)
134144
{
135-
// TODO: Windows 下替换源暂不支持
145+
/* TODO: Windows 下替换源暂不支持 */
136146
chsrc_note2 ("Windows 下暂不支持修改 uv.toml,请手动修改配置文件");
137147
}
138148
else
139149
{
140-
// uv_config 存在,如果存在 [[index]] 则更新,否则追加到文件末尾
141-
// run: grep -q '^[[index]]$' uv_config && update_source_cmd || append_source_cmd
150+
/**
151+
* uv_config 存在,如果存在 [[index]] 则更新,否则追加到文件末尾
152+
* run: grep -q '^[[index]]$' uv_config && update_source_cmd || append_source_cmd
153+
*/
142154
cmd = xy_strjoin (6, "grep -q '^\\[\\[index\\]\\]$' ",
143155
uv_config,
144156
" && ",
@@ -193,4 +205,4 @@ pl_python_uv_feat (char *option)
193205
}
194206

195207
// def_target_gsrf(pl_python_uv);
196-
Target_t pl_python_uv_target = {def_target_inner_gsrf(pl_python_uv),def_target_sourcesn(pl_python)};
208+
Target_t pl_python_uv_target = {def_target_inner_gsrf(pl_python_uv),def_target_sourcesn(pl_python)};

0 commit comments

Comments
 (0)