Rewrite uv recipe using rawstr4c

This commit is contained in:
Aoran Zeng 2025-07-14 17:32:09 +08:00
parent 0dba3904cf
commit 0fb89b854b
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98
4 changed files with 91 additions and 36 deletions

View File

@ -7,9 +7,11 @@
* |
* Created On : <2023-09-03>
* Major Revision : 1
* Last Modified : <2025-07-11>
* Last Modified : <2025-07-14>
* ------------------------------------------------------------*/
#include "rawstr4c.h"
/**
* host/pipi/web/pacakges....
* packages

View File

@ -0,0 +1,16 @@
#pragma once
/**
* Generated by rawstr4c v0.1.0.1-2025/07/14
*
* Date: 2025-07-14T17:28:23.336582+08:00
*/
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\x22\x0a\x64\x65\x66\x61\x75\x6c\x74\x20\x3d\x20\x74\x72\x75\x65\x0a\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\x0a";
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\x7d\x27\x20\x40\x66\x40\x0a";
char RAWSTR_pl_python_final_uv_cmd[] = "\x67\x72\x65\x70\x20\x2d\x71\x20\x27\x5e\x5b\x5b\x69\x6e\x64\x65\x78\x5d\x5d\x24\x27\x20\x40\x66\x40\x20\x26\x26\x20\x40\x75\x63\x6d\x64\x40\x20\x7c\x7c\x20\x40\x61\x63\x6d\x64\x40\x0a";

View File

@ -0,0 +1,50 @@
<!-- -----------------------------------------------------------
! SPDX-License-Identifier: GPL-3.0-or-later
! -------------------------------------------------------------
! Config Type : rawstr4c (Markdown)
! Config Authors: Aoran Zeng <ccmywish@qq.com>
! | happy game <happygame1024@gmail.com>
! Contributors : Nil Null <nil@null.org>
! Created On : <2025-07-14>
! Last Modified : <2025-07-14>
! ---------------------------------------------------------- -->
# rawstr4c input for Python
- prefix = `RAWSTR_pl_python`
- output = `:global-variable-only-header`
- translate = `:hex`
- keep-postfix = `false`
### uv config source content
```toml
[[index]]
url = "@url"
default = true
```
### Get uv config
```sh
grep -A 2 'index' @f@ | sed -n 's/^url = "\(.*\)"/\1/p'
```
### Set uv config
```sh
@sed@ '/^\[\[index\]\]$/,/^default = true$/{s|^url = ".*"$|url = "@url@"|}' @f@
```
### Final uv cmd
```sh
grep -q '^[[index]]$' @f@ && @ucmd@ || @acmd@
```

View File

@ -6,7 +6,8 @@
* | Aoran Zeng <ccmywish@qq.com>
* |
* Created On : <2024-12-11>
* Last Modified : <2025-07-11>
* Major Revision : 1
* Last Modified : <2025-07-14>
* ------------------------------------------------------------*/
/**
@ -19,9 +20,9 @@
* 4. /etc/uv/uv.toml
*/
#define UV_CONFIG "uv.toml"
#define UV_LOCAL_CONFIG_PATH "./"
#define UV_USER_CONFIG_PATH "~/.config/uv/"
#define PL_Python_uv_ConfigFile "uv.toml"
#define PL_Python_uv_Local_ConfigPath "./"
#define PL_Python_uv_User_ConfigPath "~/.config/uv/"
char *
@ -29,7 +30,7 @@ pl_python_find_uv_config (bool mkdir)
{
if (chsrc_in_local_mode())
{
return xy_2strjoin (UV_LOCAL_CONFIG_PATH, UV_CONFIG);
return xy_2strjoin (PL_Python_uv_Local_ConfigPath, PL_Python_uv_ConfigFile);
}
else
{
@ -49,16 +50,16 @@ pl_python_find_uv_config (bool mkdir)
{
chsrc_ensure_dir (config_dir);
}
return xy_2strjoin (config_dir, UV_CONFIG);
return xy_2strjoin (config_dir, PL_Python_uv_ConfigFile);
}
else
{
/* config path on Linux or macOS */
if (mkdir)
{
chsrc_ensure_dir (UV_USER_CONFIG_PATH);
chsrc_ensure_dir (PL_Python_uv_User_ConfigPath);
}
return xy_2strjoin (UV_USER_CONFIG_PATH, UV_CONFIG);
return xy_2strjoin (PL_Python_uv_User_ConfigPath, PL_Python_uv_ConfigFile);
}
}
}
@ -74,13 +75,8 @@ pl_python_uv_getsrc (char *option)
return;
}
/**
* grep -A 2 'index' config_file | sed -n 's/^url = "\(.*\)"/\1/p'
* [[index]] url
*/
char *cmd = xy_strjoin (3, "grep -A 2 'index' ",
uv_config,
" | sed -n 's/^url = \"\\(.*\\)\"/\\1/p'");
/* 获取 [[index]] 配置项的 url */
char *cmd = xy_str_gsub (RAWSTR_pl_python_get_uv_config, "@f@", uv_config);
chsrc_run (cmd, RunOpt_Default);
}
@ -108,26 +104,21 @@ pl_python_uv_setsrc (char *option)
}
chsrc_backup (uv_config);
const char *source_content = xy_strjoin (5,
"[[index]]\\n",
"url = \"", source.url, "\"\\n",
"default = true\\n");
const char *source_content = xy_str_gsub (RAWSTR_pl_python_uv_config_source_content, "@url@", source.url);
/**
* sed -i '/^\[\[index\]\]$/,/^default = true$/{s|^url = ".*"$|url = " source.url "|}' uv_config
* [[index]] default = true url = ".*" url = "source.url"
*/
#if defined(XY_On_macOS) || defined(XY_On_BSD)
char *sed_cmd = "sed -i '' ";
#else
char *sed_cmd = "sed -i ";
#endif
char *update_source_cmd = xy_strjoin (5, sed_cmd,
"'/^\\[\\[index\\]\\]$/,/^default = true$/{s|^url = \".*\"$|url = \"",
source.url,
"\"|;}' ",
uv_config);
/**
* [[index]] default = true url = ".*" url = "source.url"
*/
char *update_source_cmd = xy_str_gsub (RAWSTR_pl_python_set_uv_config, "@sed@", sed_cmd);
update_source_cmd = xy_str_gsub (update_source_cmd, "@f@", uv_config);
update_source_cmd = xy_str_gsub (update_source_cmd, "@url@", source.url);
char *append_source_cmd = xy_strjoin (4, "printf '", source_content, "' >> ", uv_config);
char *cmd = NULL;
@ -150,14 +141,10 @@ pl_python_uv_setsrc (char *option)
{
/**
* uv_config [[index]]
* run: grep -q '^[[index]]$' uv_config && update_source_cmd || append_source_cmd
*/
cmd = xy_strjoin (6, "grep -q '^\\[\\[index\\]\\]$' ",
uv_config,
" && ",
update_source_cmd,
" || ",
append_source_cmd);
cmd = xy_str_gsub (RAWSTR_pl_python_final_uv_cmd, "@f@", uv_config);
cmd = xy_str_gsub (cmd, "@ucmd@", update_source_cmd);
cmd = xy_str_gsub (cmd, "@acmd@", append_source_cmd);
}
}
if (NULL==cmd)