refactor(conditions): 重命名HAS_APP_INSTALLED为HAS_INSTALLED

This commit is contained in:
2026-06-21 14:59:59 +08:00
parent cd38e1246a
commit 5ddfe8510c
5 changed files with 12 additions and 14 deletions
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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"),))
+2 -2
View File
@@ -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
+7 -9
View File
@@ -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
+1 -1
View File
@@ -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"),),
),
]
)