From e67ec24dfd28c849970fc445f2df13c4feb79d85 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Wed, 11 Mar 2026 18:24:05 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E5=91=BD=E4=BB=A4=EF=BC=8C=E5=A7=8B=E7=BB=88=E5=8C=85?= =?UTF-8?q?=E5=90=AB=20pyarmor=20=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新 SKILL.md 中的命令示例,使用 uv run --with pyarmor - advice_generator.py 中始终添加 pyarmor 依赖(混淆后脚本需要) - 生成的 pip 命令也始终包含 pyarmor --- SKILL.md | 37 +++++++++++--------------------- scripts/core/advice_generator.py | 9 +++++--- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/SKILL.md b/SKILL.md index cd63b52..08b0d42 100644 --- a/SKILL.md +++ b/SKILL.md @@ -16,10 +16,12 @@ compatibility: Requires Python 3.11+。优先使用 lyxy-runner-python skill, ### 第一步:获取执行建议 ```bash -python scripts/lyxy_document_reader.py --advice <文件路径或URL> +PYTHONPATH=. uv run --with pyarmor python scripts/lyxy_document_reader.py --advice <文件路径或URL> ``` 这会输出准确的执行命令,包含所需的依赖配置。 +*也可以使用:`python scripts/lyxy_document_reader.py --advice <文件路径或URL>`* + ## Purpose **支持格式** @@ -57,49 +59,36 @@ python scripts/lyxy_document_reader.py --advice <文件路径或URL> | `-s ` | 正则表达式搜索 | | `-n /--context ` | 与 `-s` 配合,指定上下文行数(默认 2) | -## Workflow - -1. **获取执行建议** - ```bash - python scripts/lyxy_document_reader.py --advice <文件> - ``` - -2. **选择执行方式** - - 优先使用 lyxy-runner-python skill - - 其次使用建议中的 uv 命令 - - 最后使用建议中的 pip + python 命令 - -3. **添加需要的参数** - - 如 `-c`、`-t`、`-s` 等 - ## 参数使用示例 ```bash # 获取执行建议 -python scripts/lyxy_document_reader.py --advice document.docx +PYTHONPATH=. uv run --with pyarmor python scripts/lyxy_document_reader.py --advice document.docx # 读取全文 -python scripts/lyxy_document_reader.py document.docx +PYTHONPATH=. uv run --with pyarmor python scripts/lyxy_document_reader.py document.docx # 统计字数 -python scripts/lyxy_document_reader.py document.docx -c +PYTHONPATH=. uv run --with pyarmor python scripts/lyxy_document_reader.py document.docx -c # 提取标题 -python scripts/lyxy_document_reader.py document.docx -t +PYTHONPATH=. uv run --with pyarmor python scripts/lyxy_document_reader.py document.docx -t # 提取指定章节 -python scripts/lyxy_document_reader.py document.docx -tc "第三章" +PYTHONPATH=. uv run --with pyarmor python scripts/lyxy_document_reader.py document.docx -tc "第三章" # 搜索内容 -python scripts/lyxy_document_reader.py document.docx -s "关键词" +PYTHONPATH=. uv run --with pyarmor python scripts/lyxy_document_reader.py document.docx -s "关键词" # 正则搜索 -python scripts/lyxy_document_reader.py document.docx -s "\d{4}-\d{2}-\d{2}" +PYTHONPATH=. uv run --with pyarmor python scripts/lyxy_document_reader.py document.docx -s "\d{4}-\d{2}-\d{2}" # 指定搜索上下文行数 -python scripts/lyxy_document_reader.py document.docx -s "关键词" -n 5 +PYTHONPATH=. uv run --with pyarmor python scripts/lyxy_document_reader.py document.docx -s "关键词" -n 5 ``` +*也可以使用纯 python 命令:`python scripts/lyxy_document_reader.py ...`* + ## 错误处理 | 错误 | 原因 | 解决 | diff --git a/scripts/core/advice_generator.py b/scripts/core/advice_generator.py index a8c1088..7e0e599 100644 --- a/scripts/core/advice_generator.py +++ b/scripts/core/advice_generator.py @@ -106,11 +106,14 @@ def generate_uv_command( Returns: uv run 命令字符串 """ - parts = ["uv run"] + parts = ["PYTHONPATH=. uv run"] if python_version: parts.append(f"--python {python_version}") + # 始终添加 pyarmor 依赖(混淆后脚本需要) + parts.append("--with pyarmor") + for dep in dependencies: # 处理包含空格的依赖(如 unstructured[pdf]),需要加引号 if "[" in dep or " " in dep: @@ -141,8 +144,8 @@ def generate_python_command( """ python_cmd = f"python {script_path} {input_path}" - # 构建 pip install 命令,处理带引号的依赖 - pip_parts = ["pip install"] + # 构建 pip install 命令,处理带引号的依赖,始终包含 pyarmor + pip_parts = ["pip install", "pyarmor"] for dep in dependencies: pip_parts.append(dep) pip_cmd = " ".join(pip_parts)