2
2
* SPDX-License-Identifier: GPL-3.0-or-later
3
3
* -------------------------------------------------------------
4
4
* File Authors : happy game <[email protected] >
5
- * Contributors : ccy <[email protected] >
5
+ * Contributors : ccy <[email protected] >
6
+ * | Aoran Zeng <[email protected] >
7
+ * |
6
8
* Created On : <2024-12-11>
7
- * Last Modified : <2025-04 -02>
9
+ * Last Modified : <2025-06 -02>
8
10
* ------------------------------------------------------------*/
9
11
10
-
11
12
/**
12
13
* chsrc get uv
14
+ *
13
15
* uv的配置优先级顺序如下(高到低):
14
16
* 1. $workspaces/uv.toml
15
17
* 2. $workspaces/pyproject.toml
@@ -27,36 +29,36 @@ pl_python_find_uv_config (bool mkdir)
27
29
{
28
30
if (CliOpt_Locally )
29
31
{
30
- return xy_strjoin ( 2 , UV_LOCAL_CONFIG_PATH , UV_CONFIG );
32
+ return xy_2strjoin ( UV_LOCAL_CONFIG_PATH , UV_CONFIG );
31
33
}
32
34
else
33
35
{
34
36
if (xy_on_windows )
35
37
{
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\\" );
44
48
if (mkdir )
45
49
{
46
50
chsrc_ensure_dir (config_dir );
47
51
}
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 );
51
53
}
52
- else
54
+ else
53
55
{
54
- // config path on Linux or macOS
56
+ /* config path on Linux or macOS */
55
57
if (mkdir )
56
58
{
57
59
chsrc_ensure_dir (UV_USER_CONFIG_PATH );
58
60
}
59
- return xy_strjoin ( 2 , UV_USER_CONFIG_PATH , UV_CONFIG );
61
+ return xy_2strjoin ( UV_USER_CONFIG_PATH , UV_CONFIG );
60
62
}
61
63
}
62
64
}
65
67
pl_python_uv_getsrc (char * option )
66
68
{
67
69
char * uv_config = pl_python_find_uv_config (false);
70
+
68
71
if (!chsrc_check_file (uv_config ))
69
72
{
70
73
chsrc_error2 ("未找到 uv 配置文件" );
71
74
return ;
72
75
}
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
+ */
75
81
char * cmd = xy_strjoin (3 , "grep -A 2 'index' " ,
76
82
uv_config ,
77
83
" | sed -n 's/^url = \"\\(.*\\)\"/\\1/p'" );
@@ -106,9 +112,11 @@ pl_python_uv_setsrc (char *option)
106
112
"url = \"" , source .url , "\"\\n" ,
107
113
"default = true\\n" );
108
114
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
112
120
char * sed_cmd = "sed -i '' " ;
113
121
#else
114
122
char * sed_cmd = "sed -i " ;
@@ -124,21 +132,25 @@ pl_python_uv_setsrc (char *option)
124
132
char * cmd = NULL ;
125
133
if (!xy_file_exist (uv_config ))
126
134
{
127
- // uv_config 不存在,追加到新文件末尾
128
- // run: append_source_cmd
135
+ /**
136
+ * uv_config 不存在,追加到新文件末尾
137
+ * run: append_source_cmd
138
+ */
129
139
cmd = append_source_cmd ;
130
140
}
131
141
else
132
142
{
133
143
if (xy_on_windows )
134
144
{
135
- // TODO: Windows 下替换源暂不支持
145
+ /* TODO: Windows 下替换源暂不支持 */
136
146
chsrc_note2 ("Windows 下暂不支持修改 uv.toml,请手动修改配置文件" );
137
147
}
138
148
else
139
149
{
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
+ */
142
154
cmd = xy_strjoin (6 , "grep -q '^\\[\\[index\\]\\]$' " ,
143
155
uv_config ,
144
156
" && " ,
@@ -193,4 +205,4 @@ pl_python_uv_feat (char *option)
193
205
}
194
206
195
207
// 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