From a41ff32936e4df2c46141979ae6188946f26abfc Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Mon, 29 Dec 2025 17:51:59 +0800 Subject: [PATCH] =?UTF-8?q?`get=20uv`=20=E4=BD=BF=E7=94=A8=20`PowerShell`?= =?UTF-8?q?=20=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/recipe/lang/Python/rawstr4c.h | 18 +++++++++--------- src/recipe/lang/Python/rawstr4c.md | 25 +++++++++++++++++++------ src/recipe/lang/Python/uv.c | 18 +++++++++--------- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/src/recipe/lang/Python/rawstr4c.h b/src/recipe/lang/Python/rawstr4c.h index 12f03da..37e4f08 100644 --- a/src/recipe/lang/Python/rawstr4c.h +++ b/src/recipe/lang/Python/rawstr4c.h @@ -1,22 +1,22 @@ - #pragma once /** - * Generated by rawstr4c v1.0.0-2025/08/09 + * Generated by rawstr4c v1.1.0-2025/09/27 */ char RAWSTR_pl_python_uv_config_source_content[] = "\x5b\x5b\x69\x6e\x64\x65\x78\x5d\x5d\x0a\x75\x72\x6c\x20\x3d\x20\x22\x40\x75\x72\x6c\x40\x22\x0a\x64\x65\x66\x61\x75\x6c\x74\x20\x3d\x20\x74\x72\x75\x65\x0a"; char RAWSTR_pl_python_get_uv_config[] = "\x67\x72\x65\x70\x20\x2d\x41\x20\x32\x20\x27\x69\x6e\x64\x65\x78\x27\x20\x40\x66\x40\x20\x7c\x20\x73\x65\x64\x20\x2d\x6e\x20\x27\x73\x2f\x5e\x75\x72\x6c\x20\x3d\x20\x22\x5c\x28\x2e\x2a\x5c\x29\x22\x2f\x5c\x31\x2f\x70\x27"; +char RAWSTR_pl_python_get_uv_config_on_windows[] = "\x24\x6c\x69\x6e\x65\x73\x20\x3d\x20\x47\x65\x74\x2d\x43\x6f\x6e\x74\x65\x6e\x74\x20\x40\x66\x40\x3b\x0a\x0a\x66\x6f\x72\x28\x24\x69\x6e\x64\x65\x78\x3d\x30\x3b\x20\x24\x69\x6e\x64\x65\x78\x20\x2d\x6c\x74\x20\x24\x6c\x69\x6e\x65\x73\x2e\x43\x6f\x75\x6e\x74\x3b\x20\x24\x69\x6e\x64\x65\x78\x2b\x2b\x29\x20\x7b\x0a\x20\x20\x69\x66\x28\x24\x6c\x69\x6e\x65\x73\x5b\x24\x69\x6e\x64\x65\x78\x5d\x20\x2d\x6d\x61\x74\x63\x68\x20\x27\x5e\x5c\x5b\x5c\x5b\x69\x6e\x64\x65\x78\x5c\x5d\x5c\x5d\x24\x27\x29\x20\x7b\x0a\x20\x20\x20\x20\x24\x6c\x69\x6e\x65\x73\x5b\x24\x69\x6e\x64\x65\x78\x2e\x2e\x28\x24\x69\x6e\x64\x65\x78\x2b\x33\x29\x5d\x0a\x20\x20\x7d\x0a\x7d"; + char RAWSTR_pl_python_set_uv_config[] = "\x40\x73\x65\x64\x40\x20\x27\x2f\x5e\x5c\x5b\x5c\x5b\x69\x6e\x64\x65\x78\x5c\x5d\x5c\x5d\x24\x2f\x2c\x2f\x5e\x64\x65\x66\x61\x75\x6c\x74\x20\x3d\x20\x74\x72\x75\x65\x24\x2f\x7b\x73\x7c\x5e\x75\x72\x6c\x20\x3d\x20\x22\x2e\x2a\x22\x24\x7c\x75\x72\x6c\x20\x3d\x20\x22\x40\x75\x72\x6c\x40\x22\x7c\x3b\x7d\x27\x20\x40\x66\x40"; -char RAWSTR_pl_python_test_uv_if_set_source[] = "\x67\x72\x65\x70\x20\x2d\x71\x20\x27\x5e\x5c\x5b\x5c\x5b\x69\x6e\x64\x65\x78\x5d\x5d\x24\x27\x20\x40\x66\x40"; - -char RAWSTR_pl_python_rye_config[] = "\x5b\x5b\x73\x6f\x75\x72\x63\x65\x73\x5d\x5d\x0a\x6e\x61\x6d\x65\x20\x3d\x20\x22\x40\x31\x40\x22\x0a\x75\x72\x6c\x20\x20\x3d\x20\x22\x40\x32\x40\x22"; - -char RAWSTR_pl_python_test_uv_if_set_source_on_windows[] = "\x70\x6f\x77\x65\x72\x73\x68\x65\x6c\x6c\x20\x2d\x43\x6f\x6d\x6d\x61\x6e\x64\x20\x22\x69\x66\x20\x28\x47\x65\x74\x2d\x43\x6f\x6e\x74\x65\x6e\x74\x20\x40\x66\x40\x20\x7c\x20\x53\x65\x6c\x65\x63\x74\x2d\x53\x74\x72\x69\x6e\x67\x20\x27\x5e\x5c\x5b\x5c\x5b\x69\x6e\x64\x65\x78\x5c\x5d\x5c\x5d\x24\x27\x29\x20\x7b\x20\x65\x78\x69\x74\x20\x30\x20\x7d\x20\x65\x6c\x73\x65\x20\x7b\x20\x65\x78\x69\x74\x20\x31\x20\x7d\x22"; - char RAWSTR_pl_python_set_uv_config_on_windows[] = "\x70\x6f\x77\x65\x72\x73\x68\x65\x6c\x6c\x20\x2d\x43\x6f\x6d\x6d\x61\x6e\x64\x20\x22\x24\x63\x6f\x6e\x74\x65\x6e\x74\x20\x3d\x20\x47\x65\x74\x2d\x43\x6f\x6e\x74\x65\x6e\x74\x20\x27\x40\x66\x40\x27\x3b\x20\x24\x63\x6f\x6e\x74\x65\x6e\x74\x20\x3d\x20\x24\x63\x6f\x6e\x74\x65\x6e\x74\x20\x2d\x72\x65\x70\x6c\x61\x63\x65\x20\x27\x5e\x75\x72\x6c\x20\x3d\x20\x5c\x22\x2e\x2a\x5c\x22\x24\x27\x2c\x20\x27\x75\x72\x6c\x20\x3d\x20\x5c\x22\x40\x75\x72\x6c\x40\x5c\x22\x27\x3b\x20\x24\x63\x6f\x6e\x74\x65\x6e\x74\x20\x7c\x20\x53\x65\x74\x2d\x43\x6f\x6e\x74\x65\x6e\x74\x20\x27\x40\x66\x40\x27\x22"; -char RAWSTR_pl_python_get_uv_config_on_windows[] = "\x70\x6f\x77\x65\x72\x73\x68\x65\x6c\x6c\x20\x2d\x43\x6f\x6d\x6d\x61\x6e\x64\x20\x22\x24\x6c\x69\x6e\x65\x73\x20\x3d\x20\x47\x65\x74\x2d\x43\x6f\x6e\x74\x65\x6e\x74\x20\x40\x66\x40\x3b\x20\x66\x6f\x72\x28\x24\x69\x6e\x64\x65\x78\x3d\x30\x3b\x20\x24\x69\x6e\x64\x65\x78\x20\x2d\x6c\x74\x20\x24\x6c\x69\x6e\x65\x73\x2e\x43\x6f\x75\x6e\x74\x3b\x20\x24\x69\x6e\x64\x65\x78\x2b\x2b\x29\x20\x7b\x20\x69\x66\x28\x24\x6c\x69\x6e\x65\x73\x5b\x24\x69\x6e\x64\x65\x78\x5d\x20\x2d\x6d\x61\x74\x63\x68\x20\x27\x5e\x5c\x5b\x5c\x5b\x69\x6e\x64\x65\x78\x5c\x5d\x5c\x5d\x24\x27\x29\x20\x7b\x20\x24\x6c\x69\x6e\x65\x73\x5b\x24\x69\x6e\x64\x65\x78\x2e\x2e\x28\x24\x69\x6e\x64\x65\x78\x2b\x33\x29\x5d\x20\x7d\x20\x7d\x22"; \ No newline at end of file +char RAWSTR_pl_python_test_uv_if_set_source[] = "\x67\x72\x65\x70\x20\x2d\x71\x20\x27\x5e\x5c\x5b\x5c\x5b\x69\x6e\x64\x65\x78\x5d\x5d\x24\x27\x20\x40\x66\x40"; + +char RAWSTR_pl_python_test_uv_if_set_source_on_windows[] = "\x70\x6f\x77\x65\x72\x73\x68\x65\x6c\x6c\x20\x2d\x43\x6f\x6d\x6d\x61\x6e\x64\x20\x22\x69\x66\x20\x28\x47\x65\x74\x2d\x43\x6f\x6e\x74\x65\x6e\x74\x20\x40\x66\x40\x20\x7c\x20\x53\x65\x6c\x65\x63\x74\x2d\x53\x74\x72\x69\x6e\x67\x20\x27\x5e\x5c\x5b\x5c\x5b\x69\x6e\x64\x65\x78\x5c\x5d\x5c\x5d\x24\x27\x29\x20\x7b\x20\x65\x78\x69\x74\x20\x30\x20\x7d\x20\x65\x6c\x73\x65\x20\x7b\x20\x65\x78\x69\x74\x20\x31\x20\x7d\x22"; + +char RAWSTR_pl_python_rye_config[] = "\x5b\x5b\x73\x6f\x75\x72\x63\x65\x73\x5d\x5d\x0a\x6e\x61\x6d\x65\x20\x3d\x20\x22\x40\x31\x40\x22\x0a\x75\x72\x6c\x20\x20\x3d\x20\x22\x40\x32\x40\x22"; + diff --git a/src/recipe/lang/Python/rawstr4c.md b/src/recipe/lang/Python/rawstr4c.md index bafe0b0..cf658d6 100644 --- a/src/recipe/lang/Python/rawstr4c.md +++ b/src/recipe/lang/Python/rawstr4c.md @@ -2,11 +2,12 @@ ! SPDX-License-Identifier: GPL-3.0-or-later ! ------------------------------------------------------------- ! Config Type : rawstr4c (Markdown) - ! Config Authors: Aoran Zeng - ! | happy game - ! Contributors : Nil Null + ! Config Authors: @ccmywish + ! | @happy-game + ! | @MingriLingran + ! Contributors : Nil Null ! Created On : <2025-07-14> - ! Last Modified : <2025-12-17> + ! Last Modified : <2025-12-29> ! ---------------------------------------------------------- --> # rawstr4c input for Python @@ -41,8 +42,20 @@ grep -A 2 'index' @f@ | sed -n 's/^url = "\(.*\)"/\1/p' ### Get uv config on Windows +为什么不用 `Select-String`,原因见: + +还有另外一个好处:如果 `[[index]]` 配置被写入了多次,可以这样检查出来 + +我们倾向于使用脚本而非命令,因为内容较长,便于用户检查到底执行了什么内容。 + ```powershell -powershell -Command "$lines = Get-Content @f@; for($index=0; $index -lt $lines.Count; $index++) { if($lines[$index] -match '^\[\[index\]\]$') { $lines[$index..($index+3)] } }" +$lines = Get-Content @f@; + +for($index=0; $index -lt $lines.Count; $index++) { + if($lines[$index] -match '^\[\[index\]\]$') { + $lines[$index..($index+3)] + } +} ``` @@ -83,4 +96,4 @@ powershell -Command "if (Get-Content @f@ | Select-String '^\[\[index\]\]$') { ex [[sources]] name = "@1@" url = "@2@" -``` \ No newline at end of file +``` diff --git a/src/recipe/lang/Python/uv.c b/src/recipe/lang/Python/uv.c index 05edd5f..f42b047 100644 --- a/src/recipe/lang/Python/uv.c +++ b/src/recipe/lang/Python/uv.c @@ -10,12 +10,12 @@ pl_python_uv_prelude (void) chef_prep_this (pl_python_uv, gsr); chef_set_created_on (this, "2024-12-11"); - chef_set_last_updated (this, "2025-12-28"); + chef_set_last_updated (this, "2025-12-29"); chef_set_sources_last_updated (this, "2025-08-09"); chef_set_chef (this, NULL); - chef_set_cooks (this, 1, "@happy-game"); - chef_set_sauciers (this, 3, "@MingriLingran", "@Kattos", "@ccmywish"); + chef_set_cooks (this, 2, "@happy-game", "@MingriLingran"); + chef_set_sauciers (this, 2, "@Kattos", "@ccmywish"); chef_allow_local_mode (this, FullyCan, NULL, NULL); chef_allow_english(this); @@ -91,18 +91,18 @@ pl_python_uv_getsrc (char *option) } /* 获取 [[index]] 配置项的 url */ - char *cmd = NULL; if (xy.on_windows) { /* 在 Windows 上使用 PowerShell 替代 grep */ - cmd = xy_str_gsub(RAWSTR_pl_python_get_uv_config_on_windows, "@f@", uv_config); + char *script = xy_str_gsub (RAWSTR_pl_python_get_uv_config_on_windows, "@f@", uv_config); + chsrc_run_as_pwsh_file (script); } else { - /* 在 Linux 或 macOS 上使用 grep */ - cmd = xy_str_gsub(RAWSTR_pl_python_get_uv_config, "@f@", uv_config); + /* 在类 Unix 系统上使用 grep */ + char *cmd = xy_str_gsub (RAWSTR_pl_python_get_uv_config, "@f@", uv_config); + chsrc_run (cmd, RunOpt_Default); } - chsrc_run(cmd, RunOpt_Default); } @@ -147,7 +147,7 @@ pl_python_uv_setsrc (char *option) { cmd = xy_str_gsub (RAWSTR_pl_python_test_uv_if_set_source, "@f@", uv_config); } - + int status = xy_run_get_status (cmd); if (0==status) {