The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
perf(deploy): tree-shake FeaturePack deps and drop pypng
XiaoYouChR42a5f4441838
diff --git a/app/view/components/install_button.py b/app/view/components/install_button.pyindex ec851c34..e88a2556 100644--- a/app/view/components/install_button.py+++ b/app/view/components/install_button.py@@ -9,7 +9,7 @@ STOP_SIZE = 6QWIDGETSIZE_MAX = (1 << 24) - 1-class `InstallButton`(PrimaryPushButton):+class InstallButton(PrimaryPushButton):def __init__(self, parent=None):super().__init__(parent)self._progress: int | None = Nonediff --git a/pyproject.toml b/pyproject.tomlindex 2e88c367..1f112c0b 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -14,7 +14,7 @@ dependencies = ["nuitka>=4.3.5","pyside6~=6.10.3","pyside6-fluent-widgets>=1.11.3",- "qrcode[png]>=8.2",+ "qrcode>=8.2","websockets>=14","wreq>=0.12.0","winloop>=0.6.0; sys_platform == 'win32'",diff --git a/scripts/deploy.py b/scripts/deploy.pyindex dc5a050b..10b01cf5 100644--- a/scripts/deploy.py+++ b/scripts/deploy.py@@ -21,7 +21,6 @@ MACOS_DOCUMENT_TYPES = [EXCLUDED_PACKS = {"jack_yao"}-EXTRA_INCLUDE_PACKAGES: list[str] = []PLATFORM_INCLUDE_PACKAGES = {"win32": ["winrt"],}@@ -68,9 +67,19 @@ def _typeCheckingImportIds(tree: ast.Module) -> set[int]:return ids-def findImports(files: Iterable[Path]) -> tuple[set[str], set[str]]:- appModules: set[str] = set()- thirdParty: set[str] = set()+def isModule(dotted: str) -> bool:+ if dotted.split(".")[0] == "app":+ base = REPO / Path(*dotted.split("."))+ return base.with_suffix(".py").is_file() or (base / "__init__.py").is_file()+ try:+ return importlib.util.find_spec(dotted) is not None+ except (ModuleNotFoundError, ValueError):+ return False+++def findImports(files: Iterable[Path], ignoredTopLevels: Iterable[str] = ()) -> set[str]:+ ignored = set(ignoredTopLevels)+ modules: set[str] = set()for source in files:tree = ast.parse(source.read_text(encoding="utf-8"), filename=str(source))typeCheckingIds = _typeCheckingImportIds(tree)@@ -79,33 +88,24 @@ def findImports(files: Iterable[Path]) -> tuple[set[str], set[str]]:continueif isinstance(node, ast.Import):for alias in node.names:- dotted = alias.name- top = dotted.split(".")[0]- if top == "app":- base = Path(*dotted.split("."))- if base.with_suffix(".py").is_file() or (base / "__init__.py").is_file():- appModules.add(dotted)- elif top and top not in sys.stdlib_module_names:- thirdParty.add(top)+ top = alias.name.split(".")[0]+ if top and top not in sys.stdlib_module_names and top not in ignored and isModule(alias.name):+ modules.add(alias.name)elif isinstance(node, ast.ImportFrom) and node.level == 0 and node.module:module = node.moduletop = module.split(".")[0]-- if top == "app":- base = Path(*module.split("."))- if base.with_suffix(".py").is_file() or (base / "__init__.py").is_file():- appModules.add(module)- elif top and top not in sys.stdlib_module_names:- thirdParty.add(top)-+ if not top or top in sys.stdlib_module_names or top in ignored:+ continue+ if isModule(module):+ modules.add(module)for alias in node.names:+ if alias.name == "*":+ continuedotted = f"{module}.{alias.name}"- if top == "app":- base = Path(*dotted.split("."))- if base.with_suffix(".py").is_file() or (base / "__init__.py").is_file():- appModules.add(dotted)+ if isModule(dotted):+ modules.add(dotted)- return appModules, thirdParty+ return modulesdef findQfwModules(@@ -153,24 +153,20 @@ def findIncludes() -> tuple[list[str], list[str]]:from qfluentwidgets._symbols import PACKAGE_EXPORTSfeatureFiles = [path for pack in findPacks() for path in pack.rglob("*.py")]- appFiles = list((REPO / "app").rglob("*.py"))- featureModules, featurePackages = findImports(featureFiles)- appModules, appPackages = findImports(appFiles)+ appFiles = [REPO / "Ghost-Downloader-3.py", *(REPO / "app").rglob("*.py")]featuresDir = REPO / "features"internalPackages = {featuresDir.name} | {item.name for item in featuresDir.iterdir() if item.is_dir()}+ ignoredTopLevels = internalPackages | {"qfluentwidgets"}- packages = ((featurePackages - appPackages - internalPackages) | set(EXTRA_INCLUDE_PACKAGES)) - {"qfluentwidgets"}- packages |= set(PLATFORM_INCLUDE_PACKAGES.get(sys.platform, []))-- qfwModules = findQfwModules([REPO / "Ghost-Downloader-3.py", *appFiles, *featureFiles], PACKAGE_EXPORTS)- modules = {- module- for module in featureModules - appModules- if not (Path(*module.split(".")) / "__init__.py").is_file()- } | set(EXTRA_INCLUDE_MODULES) | qfwModules+ # FeaturePack 第三方依赖按导入模块走 --include-module,由 Nuitka 做传递闭包,避免整包带入 tests 等子包+ featureModules = findImports(featureFiles, ignoredTopLevels)+ appModules = findImports(appFiles, ignoredTopLevels)+ qfwModules = findQfwModules([*appFiles, *featureFiles], PACKAGE_EXPORTS)- return sorted(packages), sorted(modules)+ packages = sorted(PLATFORM_INCLUDE_PACKAGES.get(sys.platform, []))+ modules = sorted((featureModules - appModules) | set(EXTRA_INCLUDE_MODULES) | qfwModules)+ return packages, modulesdef buildArgs() -> list[str]:diff --git a/tests/test_deploy.py b/tests/test_deploy.pyindex a4d02155..9ca11380 100644--- a/tests/test_deploy.py+++ b/tests/test_deploy.py@@ -4,7 +4,7 @@ from pathlib import Pathimport pytest-from scripts.deploy import buildArgs, findQfwModules+from scripts.deploy import buildArgs, findImports, findQfwModulesEXPORTS = {@@ -71,10 +71,33 @@ def test_reject_unknown_symbol(tmp_path: Path):findQfwModules([source], EXPORTS)-def test_build_args_shakes_qfw():+def test_find_imports_collects_modules_and_submodules(tmp_path: Path):+ source = tmp_path / "pack.py"+ source.write_text(+ "from typing import TYPE_CHECKING\n"+ "import qrcode\n"+ "from qrcode import constants\n"+ "from mpegdash.parser import MPEGDASHParser\n"+ "from qfluentwidgets import PushButton\n"+ "if TYPE_CHECKING:\n"+ " import aioftp\n",+ encoding="utf-8",+ )++ assert findImports([source], ignoredTopLevels={"qfluentwidgets"}) == {+ "qrcode",+ "qrcode.constants",+ "mpegdash.parser",+ }+++def test_build_args_shakes_qfw_and_feature_deps():args = buildArgs()assert "--include-package=qfluentwidgets" not in args+ assert "--include-package=qrcode" not in args+ assert "--include-module=qrcode" in args+ assert "--include-module=mpegdash.parser" in argsassert "--include-module=qfluentwidgets.common.runtime" in argsassert "--include-module=qfluentwidgets.window.splash_screen" in argsassert "--include-module=qfluentwidgets.window.fluent_window" in argsdiff --git a/uv.lock b/uv.lockindex 9505c135..58ba341b 100644--- a/uv.lock+++ b/uv.lock@@ -406,7 +406,7 @@ dependencies = [{ name = "pyside6" },{ name = "pyside6-fluent-widgets" },{ name = "pywin32", marker = "sys_platform == 'win32'" },- { name = "qrcode", extra = ["png"] },+ { name = "qrcode" },{ name = "uvloop", marker = "sys_platform != 'win32'" },{ name = "websockets" },{ name = "winloop", marker = "sys_platform == 'win32'" },@@ -440,7 +440,7 @@ requires-dist = [{ name = "pyside6", specifier = "~=6.10.3" },{ name = "pyside6-fluent-widgets", git = "https://github.com/XiaoYouChR/PyQt-Fluent-Widgets.git?branch=main" },{ name = "pywin32", marker = "sys_platform == 'win32'", specifier = ">=312" },- { name = "qrcode", extras = ["png"], specifier = ">=8.2" },+ { name = "qrcode", specifier = ">=8.2" },{ name = "uvloop", marker = "sys_platform != 'win32'", specifier = ">=0.22.1" },{ name = "websockets", specifier = ">=14" },{ name = "winloop", marker = "sys_platform == 'win32'", specifier = ">=0.6.0" },@@ -827,15 +827,6 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/ae/62/cd1fc4fd3a95f7a09744ab25b315dd8c3ff0b69a18ce997a0af7ec28f1f2/pyobjc_framework_quartz-13.0-cp315-cp315t-macosx_10_15_universal2.whl", hash = "sha256:ab6f410ac494b63ed48294392650b88ce8229511a0eb0059458982daeeacc6f7", size = 221391, upload-time = "2026-10-30T10:42:41.015Z" },]-[[package]]-name = "pypng"-version = "0.20220715.0"-source = { registry = "https://pypi.org/simple" }-sdist = { url = "https://files.pythonhosted.org/packages/93/cd/112f092ec27cca83e0516de0a3368dbd9128c187fb6b52aaaa7cde39c96d/pypng-0.20220715.0.tar.gz", hash = "sha256:739c433ba96f078315de54c0db975aee537cbc3e1d0ae4ed9aab0ca1e427e2c1", size = 128992, upload-time = "2022-07-15T14:11:05.301Z" }-wheels = [- { url = "https://files.pythonhosted.org/packages/3e/b9/3766cc361d93edb2ce81e2e1f87dd98f314d7d513877a342d31b30741680/pypng-0.20220715.0-py3-none-any.whl", hash = "sha256:4a43e969b8f5aaafb2a415536c1a8ec7e341cd6a3f957fd5b5f32a4cfeed902c", size = 58057, upload-time = "2022-07-15T14:11:03.713Z" },-]-[[package]]name = "pyside6"version = "6.10.3"@@ -887,7 +878,7 @@ wheels = [[[package]]name = "pyside6-fluent-widgets"version = "1.11.3"-source = { git = "https://github.com/XiaoYouChR/PyQt-Fluent-Widgets.git?branch=main#18e82c47308a486baaa84d67fb587d7956ad168b" }+source = { git = "https://github.com/XiaoYouChR/PyQt-Fluent-Widgets.git?branch=main#a23215c9316ab99f6356ae89aa06a6198962ca2f" }dependencies = [{ name = "darkdetect" },{ name = "pyside6" },@@ -977,11 +968,6 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/dd/b8/d2d6d731733f51684bbf76bf34dab3b70a9148e8f2cef2bb544fccec681a/qrcode-8.2-py3-none-any.whl", hash = "sha256:16e64e0716c14960108e85d853062c9e8bba5ca8252c0b4d0231b9df4060ff4f", size = 45986, upload-time = "2025-05-01T15:44:22.781Z" },]-[package.optional-dependencies]-png = [- { name = "pypng" },-]-[[package]]name = "rubicon-objc"version = "0.5.7"