From feb1593aba491460d501cdabb6bdc9c555cb850a Mon Sep 17 00:00:00 2001 From: chakcy <947105045@qq.com> Date: Tue, 1 Sep 2026 10:08:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=B7=E6=B7=86=E5=A4=B1=E8=B4=A5=E5=88=99?= =?UTF-8?q?=E8=B7=B3=E8=BF=87=E6=B7=B7=E6=B7=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- src/chongming_cli/build.py | 43 ++++++++++++++++++++++--------- src/chongming_cli/code_content.py | 1 + 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e9a5041..98eae0d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ requires = ["hatchling"] [project] name = "chongming-cli" -version = "0.2.4" +version = "0.3.0" description = "chongming 命令脚本集合:构建打包 / 进程插件打包 / 插件脚手架 / 模型生成" readme = "README.md" requires-python = ">=3.12" diff --git a/src/chongming_cli/build.py b/src/chongming_cli/build.py index 4cebab2..6945f78 100644 --- a/src/chongming_cli/build.py +++ b/src/chongming_cli/build.py @@ -209,6 +209,23 @@ def _parse_args() -> tuple[str, set[str]]: # ── 阶段 1: 模块打包 (module-bank) ────────────────────────────────────────── +def _pack_mbank(output_path: str, source_dir: str, package_name: str, obfuscate: bool) -> str: + """打包单个 mbank 目标,返回文件大小描述""" + key = Encryption.generate_key() + packer = PythonToSQLite(output_path, key, pyarmor_obfuscate=obfuscate) + packer.pack_directory(source_dir, package_name) + packer.verify_package_structure() + packer.packer_key(key) + packer.delete_source_code(None) + return _format_size(output_path) + + +def _is_pyarmor_license_error(exc: Exception) -> bool: + """判断异常是否为 PyArmor 试用版授权额度不足所致""" + msg = str(exc).lower() + return "out of license" in msg or "license" in msg + + def _stage_pack_modules(config: Config) -> str: """ 使用 module-bank 加密打包 Python 模块为 .mbank 文件。 @@ -221,18 +238,20 @@ def _stage_pack_modules(config: Config) -> str: messages = [] for output_path, source_dir, package_name in mbank_list: - key = Encryption.generate_key() - packer = PythonToSQLite( - output_path, - key, - pyarmor_obfuscate=True, - ) - packer.pack_directory(source_dir, package_name) - packer.verify_package_structure() - packer.packer_key(key) - packer.delete_source_code(None) - size = _format_size(output_path) - messages.append(f"{Path(output_path).name} ({size})") + try: + size = _pack_mbank(output_path, source_dir, package_name, obfuscate=True) + messages.append(f"{Path(output_path).name} ({size})") + except Exception as e: + if not _is_pyarmor_license_error(e): + raise + # PyArmor 试用版授权额度耗尽(out of license) → 降级为不混淆重打包 + Path(output_path).unlink(missing_ok=True) + size = _pack_mbank(output_path, source_dir, package_name, obfuscate=False) + print( + f" ⚠️ {Path(output_path).name}: PyArmor 授权不足(out of license)," + f"降级为无混淆打包" + ) + messages.append(f"{Path(output_path).name} ({size}, 无 PyArmor 混淆)") return " - " + "\n - ".join(messages) diff --git a/src/chongming_cli/code_content.py b/src/chongming_cli/code_content.py index a4caf15..bab562a 100644 --- a/src/chongming_cli/code_content.py +++ b/src/chongming_cli/code_content.py @@ -14,6 +14,7 @@ def generate_markdown_from_py_files(directory, output_file): dirs[:] = [d for d in dirs if d != "build"] dirs[:] = [d for d in dirs if d != "dist"] dirs[:] = [d for d in dirs if d != "chongming-web"] + dirs[:] = [d for d in dirs if d != "workers"] for file in files: if ( file.endswith(".py")