fix(packaging): keep distribution minimal
This commit is contained in:
1 parent
c97e4edc74
commit
b74baef555
18 files changed
+492
-49
No files matched your search
@@ -35,13 +35,47 @@ FORBIDDEN_PREFIXES = (
|
||||
FORBIDDEN_EXACT = {
|
||||
"config/config.json",
|
||||
"douyin_guaji.code-workspace",
|
||||
"license.dat",
|
||||
"pyproject.toml",
|
||||
"pyrightconfig.json",
|
||||
"readme.md",
|
||||
"repo-backup.bundle",
|
||||
"requirements.txt",
|
||||
"requirements-minimal.txt",
|
||||
}
|
||||
|
||||
ALLOWED_ASSET_FILES = {
|
||||
"assets/coupon.png",
|
||||
"assets/fav.png",
|
||||
"assets/fudai.png",
|
||||
"assets/fudai_icon_countdown_v20260618.png",
|
||||
"assets/fudai_icon_pending_v20260618.png",
|
||||
"assets/fudai_icon_purple_left_v20260618.png",
|
||||
"assets/fudai_icon_red_left_v20260618.png",
|
||||
"assets/fudai_task_status_dacheng_shape.png",
|
||||
"assets/like.png",
|
||||
"assets/x.png",
|
||||
"assets/xin.png",
|
||||
}
|
||||
|
||||
ALLOWED_WEBUI_ROOT_FILES = {
|
||||
"webui/app.js",
|
||||
"webui/index.html",
|
||||
"webui/styles.css",
|
||||
}
|
||||
|
||||
ALLOWED_WEBUI_DIRS = (
|
||||
"webui/css/",
|
||||
"webui/js/",
|
||||
"webui/partials/",
|
||||
)
|
||||
|
||||
ALLOWED_WEBUI_SUFFIXES = {
|
||||
".css",
|
||||
".html",
|
||||
".js",
|
||||
}
|
||||
|
||||
FORBIDDEN_SUFFIXES = (
|
||||
".py",
|
||||
".pyc",
|
||||
@@ -66,9 +100,11 @@ def normalize_entry(entry: str) -> str:
|
||||
return entry.replace("\\", "/").lstrip("./")
|
||||
|
||||
|
||||
def is_forbidden_distribution_entry(entry: str) -> bool:
|
||||
def is_forbidden_distribution_entry(entry: str, *, allow_license: bool = False) -> bool:
|
||||
norm = normalize_entry(entry)
|
||||
lower = norm.lower()
|
||||
if lower == "license.dat" and allow_license:
|
||||
return False
|
||||
if lower.startswith("_internal/"):
|
||||
project_bits = {
|
||||
"_internal/douyin/",
|
||||
@@ -88,13 +124,31 @@ def is_forbidden_distribution_entry(entry: str) -> bool:
|
||||
return lower not in ALLOWED_RUNTIME_PLACEHOLDERS
|
||||
if lower.startswith("pic/"):
|
||||
return lower not in ALLOWED_RUNTIME_PLACEHOLDERS
|
||||
if lower.startswith("assets/"):
|
||||
return lower not in ALLOWED_ASSET_FILES
|
||||
if lower.startswith("webui/"):
|
||||
if lower in ALLOWED_WEBUI_ROOT_FILES:
|
||||
return False
|
||||
if lower.endswith("/readme.md") or lower.endswith("/readme.txt"):
|
||||
return True
|
||||
if not any(lower.startswith(prefix) for prefix in ALLOWED_WEBUI_DIRS):
|
||||
return True
|
||||
return Path(lower).suffix not in ALLOWED_WEBUI_SUFFIXES
|
||||
if any(lower.startswith(prefix.lower()) for prefix in FORBIDDEN_PREFIXES):
|
||||
return True
|
||||
return any(lower.endswith(suffix) for suffix in FORBIDDEN_SUFFIXES)
|
||||
|
||||
|
||||
def find_forbidden_distribution_entries(entries: list[str]) -> list[str]:
|
||||
return [entry for entry in entries if is_forbidden_distribution_entry(entry)]
|
||||
def find_forbidden_distribution_entries(
|
||||
entries: list[str],
|
||||
*,
|
||||
allow_license: bool = False,
|
||||
) -> list[str]:
|
||||
return [
|
||||
entry
|
||||
for entry in entries
|
||||
if is_forbidden_distribution_entry(entry, allow_license=allow_license)
|
||||
]
|
||||
|
||||
|
||||
def find_missing_required_runtime_entries(entries: list[str]) -> list[str]:
|
||||
@@ -110,9 +164,13 @@ def find_missing_required_runtime_entries(entries: list[str]) -> list[str]:
|
||||
return missing
|
||||
|
||||
|
||||
def find_distribution_issues(entries: list[str]) -> list[str]:
|
||||
def find_distribution_issues(
|
||||
entries: list[str],
|
||||
*,
|
||||
allow_license: bool = False,
|
||||
) -> list[str]:
|
||||
return [
|
||||
*find_forbidden_distribution_entries(entries),
|
||||
*find_forbidden_distribution_entries(entries, allow_license=allow_license),
|
||||
*find_missing_required_runtime_entries(entries),
|
||||
]
|
||||
|
||||
@@ -129,10 +187,15 @@ def iter_distribution_entries(root: str | os.PathLike[str]) -> list[str]:
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
parser = argparse.ArgumentParser(description="检查分发目录是否混入源码/调试产物")
|
||||
parser.add_argument("dist_dir", help="例如 dist/DouyinGuaji-3.3.3")
|
||||
parser.add_argument(
|
||||
"--allow-license",
|
||||
action="store_true",
|
||||
help="允许测试包包含 license.dat;正式分发不要使用",
|
||||
)
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
entries = iter_distribution_entries(args.dist_dir)
|
||||
blocked = find_distribution_issues(entries)
|
||||
blocked = find_distribution_issues(entries, allow_license=args.allow_license)
|
||||
if blocked:
|
||||
print("[DIST-CHECK] FAIL forbidden entries:")
|
||||
for entry in blocked[:200]:
|
||||
|
||||
@@ -13,7 +13,10 @@ import sys
|
||||
|
||||
|
||||
RUNTIME_SOURCE_DIRS = ("douyin", "gui", "operations")
|
||||
RUNTIME_ENTRY_FILES = ("bin/run_cli.py",)
|
||||
RUNTIME_ENTRY_FILES = (
|
||||
"bin/run_cli.py",
|
||||
"bin/run_cli_entry.py",
|
||||
)
|
||||
FORBIDDEN_STAGING_PREFIXES = ("tools/", "tests/", "artifacts/", "docs/", "packaging/")
|
||||
FORBIDDEN_STAGING_FILES = ("tools/license_dev.py",)
|
||||
INTERNAL_IMPORT_TOP_LEVELS = {Path(item).parts[0] for item in RUNTIME_SOURCE_DIRS}
|
||||
|
||||
Reference in new issue
Block a user