From 5ddfe8510ca7de3c51e9d0b5ac33a27b9806b5fc Mon Sep 17 00:00:00 2001 From: gooker_young Date: Sun, 21 Jun 2026 14:59:59 +0800 Subject: [PATCH] =?UTF-8?q?refactor(conditions):=20=E9=87=8D=E5=91=BD?= =?UTF-8?q?=E5=90=8DHAS=5FAPP=5FINSTALLED=E4=B8=BAHAS=5FINSTALLED?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pyflowx/__init__.py | 2 +- src/pyflowx/cli/pymake.py | 2 +- src/pyflowx/conditions.py | 4 ++-- tests/test_conditions.py | 16 +++++++--------- tests/test_taskspec_commands.py | 2 +- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/pyflowx/__init__.py b/src/pyflowx/__init__.py index 4a554fd..aa154b5 100644 --- a/src/pyflowx/__init__.py +++ b/src/pyflowx/__init__.py @@ -43,7 +43,7 @@ px.TaskSpec( "git_check", cmd=["git", "--version"], - conditions=(BuiltinConditions.HAS_APP_INSTALLED("git"),) + conditions=(BuiltinConditions.HAS_INSTALLED("git"),) ), ]) report = px.run(graph) diff --git a/src/pyflowx/cli/pymake.py b/src/pyflowx/cli/pymake.py index 972281b..05efd85 100644 --- a/src/pyflowx/cli/pymake.py +++ b/src/pyflowx/cli/pymake.py @@ -40,7 +40,7 @@ def check(name: str) -> px.Condition: bool 如果已安装则返回 True,否则返回 False. """ - return BuiltinConditions.HAS_APP_INSTALLED(name) + return BuiltinConditions.HAS_INSTALLED(name) uv_build: px.TaskSpec = px.TaskSpec("uv_build", cmd=["uv", "build"], conditions=(check("uv"),)) diff --git a/src/pyflowx/conditions.py b/src/pyflowx/conditions.py index 49975a3..f7651c9 100644 --- a/src/pyflowx/conditions.py +++ b/src/pyflowx/conditions.py @@ -85,7 +85,7 @@ class BuiltinConditions: return sys.version_info >= (major, minor) @staticmethod - def HAS_APP_INSTALLED(app_name: str) -> Condition: + def HAS_INSTALLED(app_name: str) -> Condition: """检查指定应用是否已安装. Parameters @@ -102,7 +102,7 @@ class BuiltinConditions: def _check() -> bool: return shutil.which(app_name) is not None - _check.__name__ = f"HAS_APP_INSTALLED({app_name!r})" + _check.__name__ = f"HAS_INSTALLED({app_name!r})" return _check @staticmethod diff --git a/tests/test_conditions.py b/tests/test_conditions.py index 302a16a..b866bb2 100644 --- a/tests/test_conditions.py +++ b/tests/test_conditions.py @@ -79,25 +79,23 @@ def test_builtin_conditions_python_version_at_least(): current_major = sys.version_info.major current_minor = sys.version_info.minor # Current version should be at least itself - assert ( - BuiltinConditions.PYTHON_VERSION_AT_LEAST(current_major, current_minor) is True - ) + assert BuiltinConditions.PYTHON_VERSION_AT_LEAST(current_major, current_minor) is True # Current version should be at least an older version assert BuiltinConditions.PYTHON_VERSION_AT_LEAST(current_major - 1, 0) is True # Current version should NOT be at least a newer version assert BuiltinConditions.PYTHON_VERSION_AT_LEAST(current_major + 1, 0) is False -def test_builtin_conditions_has_app_installed_true(): - """Test BuiltinConditions.HAS_APP_INSTALLED when app exists.""" +def test_builtin_conditions_HAS_INSTALLED_true(): + """Test BuiltinConditions.HAS_INSTALLED when app exists.""" # Python should always be available - condition = BuiltinConditions.HAS_APP_INSTALLED("python") + condition = BuiltinConditions.HAS_INSTALLED("python") assert condition() is True -def test_builtin_conditions_has_app_installed_false(): - """Test BuiltinConditions.HAS_APP_INSTALLED when app doesn't exist.""" - condition = BuiltinConditions.HAS_APP_INSTALLED("nonexistent_app_12345") +def test_builtin_conditions_HAS_INSTALLED_false(): + """Test BuiltinConditions.HAS_INSTALLED when app doesn't exist.""" + condition = BuiltinConditions.HAS_INSTALLED("nonexistent_app_12345") assert condition() is False diff --git a/tests/test_taskspec_commands.py b/tests/test_taskspec_commands.py index a1740d1..1a57fa3 100644 --- a/tests/test_taskspec_commands.py +++ b/tests/test_taskspec_commands.py @@ -160,7 +160,7 @@ def test_app_installed_conditions(): px.TaskSpec( "python_check", cmd=python_cmd, - conditions=(BuiltinConditions.HAS_APP_INSTALLED("python"),), + conditions=(BuiltinConditions.HAS_INSTALLED("python"),), ), ] )