From 98cf3b54a16189b9047f29ce19886e1843236cea Mon Sep 17 00:00:00 2001 From: gooker_young Date: Sun, 21 Jun 2026 20:12:24 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=8F=91=E5=B8=83v0.1.5=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=B9=B6=E5=AE=8C=E6=88=90=E4=BB=A3=E7=A0=81=E6=B8=85?= =?UTF-8?q?=E7=90=86=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 移除pyproject.toml中冗余的ruff格式化配置 2. 删除CliRunner内置的类型校验逻辑并移除对应测试用例 3. 修复条件判断模块的匿名函数命名兼容非函数对象场景 4. 优化task.py中的类型转换和命令执行逻辑 5. 更新pymake.py的格式化任务配置并调整测试任务依赖 6. 从依赖和锁文件中移除ruff包,统一pre-commit配置格式 --- .pre-commit-config.yaml | 6 +++--- pyproject.toml | 8 -------- src/pyflowx/cli/pymake.py | 4 ++-- src/pyflowx/conditions.py | 6 +++--- src/pyflowx/runner.py | 4 ---- src/pyflowx/task.py | 8 +++++--- tests/test_runner.py | 17 ----------------- uv.lock | 29 +---------------------------- 8 files changed, 14 insertions(+), 68 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e928f5d..2ec6a20 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,10 +7,10 @@ repos: hooks: # Run the linter - id: ruff - args: [ --fix, --exit-non-zero-on-fix ] + args: [--fix, --exit-non-zero-on-fix] # Run the formatter - id: ruff-format - args: [ --config=pyproject.toml] + args: [--config=pyproject.toml] - repo: https://gitcode.com/gh_mirrors/pr/pre-commit-hooks.git rev: v5.0.0 hooks: @@ -18,5 +18,5 @@ repos: - id: debug-statements - id: fix-byte-order-marker - id: trailing-whitespace - args: [ --markdown-linebreak-ext=md ] + args: [--markdown-linebreak-ext=md] - id: end-of-file-fixer diff --git a/pyproject.toml b/pyproject.toml index ebe3886..52bca4e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -123,11 +123,3 @@ ignore = [ "PLR0915", # too many statements (intentional for complex methods) "PTH119", # os.path.basename (intentional for sys.argv) ] - -[tool.ruff.lint.isort] -known-first-party = ["pyflowx"] - -[tool.ruff.format] -quote-style = "double" -indent-style = "space" -docstring-code-format = true diff --git a/src/pyflowx/cli/pymake.py b/src/pyflowx/cli/pymake.py index da9cd2f..86aa7e2 100644 --- a/src/pyflowx/cli/pymake.py +++ b/src/pyflowx/cli/pymake.py @@ -47,7 +47,7 @@ test_coverage: px.TaskSpec = px.TaskSpec( cmd=["pytest", "--cov", "-n", "8", "--dist", "loadfile", "--tb=short", "-v", "--color=yes", "--durations=10"], ) ruff_lint: px.TaskSpec = px.TaskSpec("lint", cmd=["ruff", "check", "--fix", "--unsafe-fixes"]) -ruff_format: px.TaskSpec = px.TaskSpec("format", cmd=["ruff", "format", "--check", "."], depends_on=("lint",)) +ruff_format: px.TaskSpec = px.TaskSpec("format", cmd=["ruff", "format", "."], depends_on=("lint",)) mypy_check: px.TaskSpec = px.TaskSpec("typecheck", cmd=["mypy", "."]) ty_check: px.TaskSpec = px.TaskSpec("ty_check", cmd=["ty", "check", "."]) doc: px.TaskSpec = px.TaskSpec("doc", cmd=["sphinx-build", "-b", "html", "docs", "docs/_build"]) @@ -122,7 +122,7 @@ def main(): "pb": px.Graph.from_specs([twine_publish, hatch_publish]), "t": px.Graph.from_specs([test]), "tf": px.Graph.from_specs([test_fast]), - "tc": px.Graph.from_specs([mypy_check, ty_check]), + "tc": px.Graph.from_specs([mypy_check, ty_check, ruff_lint, ruff_format]), "tox": px.Graph.from_specs([tox]), # 发布命令 "p": px.Graph.from_specs([git_clean, git_push, git_push_tags]), diff --git a/src/pyflowx/conditions.py b/src/pyflowx/conditions.py index f7651c9..87b9f7c 100644 --- a/src/pyflowx/conditions.py +++ b/src/pyflowx/conditions.py @@ -167,7 +167,7 @@ class BuiltinConditions: def _check() -> bool: return not condition() - _check.__name__ = f"NOT({condition.__name__})" + _check.__name__ = f"NOT({getattr(condition, '__name__', repr(condition))})" return _check @staticmethod @@ -188,7 +188,7 @@ class BuiltinConditions: def _check() -> bool: return all(c() for c in conditions) - names = [c.__name__ for c in conditions] + names = [getattr(c, "__name__", repr(c)) for c in conditions] _check.__name__ = f"AND({', '.join(names)})" return _check @@ -210,7 +210,7 @@ class BuiltinConditions: def _check() -> bool: return any(c() for c in conditions) - names = [c.__name__ for c in conditions] + names = [getattr(c, "__name__", repr(c)) for c in conditions] _check.__name__ = f"OR({', '.join(names)})" return _check diff --git a/src/pyflowx/runner.py b/src/pyflowx/runner.py index e80cc42..8b645bf 100644 --- a/src/pyflowx/runner.py +++ b/src/pyflowx/runner.py @@ -114,10 +114,6 @@ class CliRunner: if not self.graphs: raise ValueError("CliRunner 至少需要一个命令 (通过关键字参数提供)") - for name, graph in self.graphs.items(): - if not isinstance(graph, Graph): - raise TypeError(f"CliRunner 命令 {name!r} 的值必须是 Graph 实例, 实际是 {type(graph).__name__}") - # ------------------------------------------------------------------ # # 内省 # ------------------------------------------------------------------ # diff --git a/src/pyflowx/task.py b/src/pyflowx/task.py index 42565b9..7a78090 100644 --- a/src/pyflowx/task.py +++ b/src/pyflowx/task.py @@ -174,18 +174,19 @@ class TaskSpec(Generic[T]): verbose = self.verbose if isinstance(cmd, list): + cmd_list = cast(List[str], cmd) def _run_list() -> T: import subprocess - cmd_str = " ".join(str(arg) for arg in cmd) + cmd_str = " ".join(str(arg) for arg in cmd_list) if verbose: print(f"[verbose] 执行命令: {cmd_str}", flush=True) if cwd is not None: print(f"[verbose] 工作目录: {cwd}", flush=True) try: result = subprocess.run( - cmd, + cmd_list, cwd=cwd, timeout=timeout, capture_output=not verbose, @@ -287,7 +288,8 @@ class TaskSpec(Generic[T]): cmd = self.cmd if isinstance(cmd, list) and cmd: - return shutil.which(cmd[0]) is not None + first_arg = cast(str, cmd[0]) + return shutil.which(first_arg) is not None return True diff --git a/tests/test_runner.py b/tests/test_runner.py index 6be2d69..5c6f2f5 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -603,23 +603,6 @@ class TestCliRunnerIntegration: assert exit_code == CliExitCode.SUCCESS.value -# ---------------------------------------------------------------------- # -# 构造校验 (补充覆盖) -# ---------------------------------------------------------------------- # -class TestCliRunnerConstructionValidation: - """测试 CliRunner 的构造校验 (补充覆盖).""" - - def test_non_graph_value_raises_type_error(self) -> None: - """非 Graph 值应抛出 TypeError (覆盖 runner.py line 119).""" - with pytest.raises(TypeError, match="必须是 Graph 实例"): - _ = px.CliRunner(graphs={"bad": "not a graph"}) # type: ignore[dict-item] - - def test_non_graph_value_dict_raises_type_error(self) -> None: - """dict 中包含非 Graph 值应抛出 TypeError.""" - with pytest.raises(TypeError, match="必须是 Graph 实例"): - _ = px.CliRunner(graphs={"good": _echo_graph(), "bad": 123}) # type: ignore[dict-item] - - # ---------------------------------------------------------------------- # # _apply_verbose_to_graph (补充覆盖) # ---------------------------------------------------------------------- # diff --git a/uv.lock b/uv.lock index 820fec1..b9d2aa4 100644 --- a/uv.lock +++ b/uv.lock @@ -2221,7 +2221,7 @@ wheels = [ [[package]] name = "pyflowx" -version = "0.1.4" +version = "0.1.5" source = { editable = "." } dependencies = [ { name = "graphlib-backport", marker = "python_full_version < '3.9'" }, @@ -2252,7 +2252,6 @@ dev = [ { name = "pytest-mock", version = "3.15.1", source = { registry = "https://mirrors.aliyun.com/pypi/simple/" }, marker = "python_full_version >= '3.9'" }, { name = "pytest-xdist", version = "3.6.1", source = { registry = "https://mirrors.aliyun.com/pypi/simple/" }, marker = "python_full_version < '3.9'" }, { name = "pytest-xdist", version = "3.8.0", source = { registry = "https://mirrors.aliyun.com/pypi/simple/" }, marker = "python_full_version >= '3.9'" }, - { name = "ruff" }, { name = "tox", version = "4.25.0", source = { registry = "https://mirrors.aliyun.com/pypi/simple/" }, marker = "python_full_version < '3.9'" }, { name = "tox", version = "4.30.3", source = { registry = "https://mirrors.aliyun.com/pypi/simple/" }, marker = "python_full_version == '3.9.*'" }, { name = "tox", version = "4.55.1", source = { registry = "https://mirrors.aliyun.com/pypi/simple/" }, marker = "python_full_version >= '3.10'" }, @@ -2280,7 +2279,6 @@ requires-dist = [ { name = "pytest-html", marker = "extra == 'dev'", specifier = ">=4.1.1" }, { name = "pytest-mock", marker = "extra == 'dev'", specifier = ">=3.14.0" }, { name = "pytest-xdist", marker = "extra == 'dev'", specifier = ">=3.6.1" }, - { name = "ruff", marker = "extra == 'dev'", specifier = ">=0.8.0" }, { name = "tox", marker = "extra == 'dev'", specifier = ">=4.25.0" }, { name = "tox-uv", marker = "extra == 'dev'", specifier = ">=1.13.1" }, ] @@ -2712,31 +2710,6 @@ wheels = [ { url = "https://mirrors.aliyun.com/pypi/packages/82/3b/64d4899d73f91ba49a8c18a8ff3f0ea8f1c1d75481760df8c68ef5235bf5/rich-15.0.0-py3-none-any.whl", hash = "sha256:33bd4ef74232fb73fe9279a257718407f169c09b78a87ad3d296f548e27de0bb" }, ] -[[package]] -name = "ruff" -version = "0.15.18" -source = { registry = "https://mirrors.aliyun.com/pypi/simple/" } -sdist = { url = "https://mirrors.aliyun.com/pypi/packages/74/98/1295ad5a5aa9bc85bdcdfa5d82fe7b49c61af5657df4f227637ff9de0da6/ruff-0.15.18.tar.gz", hash = "sha256:2698a964c70e8bf402dcb99c8810472d270d141e7aa8c4e13599fd52033a2f33" } -wheels = [ - { url = "https://mirrors.aliyun.com/pypi/packages/b9/d0/686e984941269621e2be72612d5c1e461f8f7b38415a2a7d7a81c8ae6715/ruff-0.15.18-py3-none-linux_armv6l.whl", hash = "sha256:8b6850172348c8381b8b3084c5915a4393c2373b9b54cd5b5e1ea15812bc10df" }, - { url = "https://mirrors.aliyun.com/pypi/packages/ed/21/bc4123e3f5515ee99f8ce1eb93a14a0628fe4d1678663cd08f933ac16931/ruff-0.15.18-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:3fccc153a85417dcd976883160cacce486997b0a0058dd18f54b8aaaac7d1ce2" }, - { url = "https://mirrors.aliyun.com/pypi/packages/51/93/4769464c25cf7ab2acb3c7dda9cad3d867eb41c59565b3e2a9d17249c90c/ruff-0.15.18-py3-none-macosx_11_0_arm64.whl", hash = "sha256:08d4c86a68f2c3ec2c9d56380a71fb4a4f65373055cbb8caabd645e9102f38d4" }, - { url = "https://mirrors.aliyun.com/pypi/packages/6c/42/56926d17120db2c208d76bf60a1a019644dd9e91dc27f0f95c9caddb1366/ruff-0.15.18-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:37e5108745c2c0705da916d7d4de533ddf547051ef45f62888c31bae73f66318" }, - { url = "https://mirrors.aliyun.com/pypi/packages/22/4f/d43fab8d8189afde803103022d000a8ef9f230616d436d52a8b2b8d63b50/ruff-0.15.18-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:56949a6ce8b3abde54c0bcb22cebfe57e8771cadc84b407ae8b8eaf67ebdcd43" }, - { url = "https://mirrors.aliyun.com/pypi/packages/63/42/1e3e4c68bd408b9768cf3e439acbe2c78245225faef253f7028a0cdb63e0/ruff-0.15.18-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:01a754cd6a1b630d3f97e33eb452cf7a98040482318e870f8bc52a5a30e62657" }, - { url = "https://mirrors.aliyun.com/pypi/packages/20/77/47a3484bea8521e14a203d98c389c5c97846675e4f02734672da4a69b52a/ruff-0.15.18-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:6ba7a07e03a44dbf10bb086ee06705b173625014ec99f73a7e6836a5e5590a0c" }, - { url = "https://mirrors.aliyun.com/pypi/packages/0a/ca/054159590787023d83b658a1a1819c4c8910114e7015069340b71c0961cb/ruff-0.15.18-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:5a2c40a41a4cadbcf5897b548ab29dfe248b20c540961c0247d98a3973c70403" }, - { url = "https://mirrors.aliyun.com/pypi/packages/6d/ff/d353d6b7bbd73cc0ec37f4463d7540e45e894338abdd9964eee0de332708/ruff-0.15.18-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5f0480ce690cbb6c4db6e5d08f19fce98e10ba131a8b60c1bcdac42771e3ae2d" }, - { url = "https://mirrors.aliyun.com/pypi/packages/c1/4a/891f89b9c296ed3e5f3ece1a5629badc989d9a8fdaa30431aaf4774bc1c2/ruff-0.15.18-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:2330215f1f393fa8733f55edce04fcf94c36a2c460fcde31f78cc84e4951e9b1" }, - { url = "https://mirrors.aliyun.com/pypi/packages/32/a3/ed9e370154bf85de360b93c03026157f02d4943b2d01ff4945f4429f8e8a/ruff-0.15.18-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:a6aa6a3d979e48ae617578183674bf264fbe7d0114a796a26bd678d67963c7ff" }, - { url = "https://mirrors.aliyun.com/pypi/packages/f5/d1/5cf5909329fedb5d39d555ee818ba5cf4638e1a301b89785d34f2905bfcb/ruff-0.15.18-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:a81beadbbff2c9c245561ae3f77b16709d87f35eec650d0501679239d3449b22" }, - { url = "https://mirrors.aliyun.com/pypi/packages/fd/44/ff6c635cf2c4f4e7b618b6640da057376baa36014695487d88aed4794268/ruff-0.15.18-py3-none-musllinux_1_2_i686.whl", hash = "sha256:2186d9e940ae332ab293623a75b5f4fe49565f449954d50a72a046683aa6b809" }, - { url = "https://mirrors.aliyun.com/pypi/packages/88/d9/5baa2a30861adfb7022cf33c1e35b2fc18085b08c16f83eff4c7b99a5f48/ruff-0.15.18-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:5c2abf140438032bc77b2284a6c9944ecd8a19e5f1c7b52b1b8e4a0a80d19a7a" }, - { url = "https://mirrors.aliyun.com/pypi/packages/c3/1a/0725a7cfdc32ff769efb96ee782bec882e16448c5d9e3be947ec4c04ce27/ruff-0.15.18-py3-none-win32.whl", hash = "sha256:02299e6e9fa5b297a3f6d5d10d7bcd655c925b028bb8b9d4588214549c6b9ec4" }, - { url = "https://mirrors.aliyun.com/pypi/packages/f3/51/805d9f6fb7970505c3504794a5ec350f605361b807fef4dcf214ebd35e72/ruff-0.15.18-py3-none-win_amd64.whl", hash = "sha256:dac80dc8d26b2257dbefabed62f5d255c3937b4ccb122da1fc634794fa3578b3" }, - { url = "https://mirrors.aliyun.com/pypi/packages/29/4c/67bb45e41609eb4726f1bfeb59e083cf91d14c696d4bd14c234a980be93d/ruff-0.15.18-py3-none-win_arm64.whl", hash = "sha256:b2c9257fcbd4a3e5b977a1904e6facca016bafe2edc17df24db67cfaee03b4e4" }, -] - [[package]] name = "secretstorage" version = "3.3.3"