refactor(conditions): 重命名HAS_APP_INSTALLED为HAS_INSTALLED
This commit is contained in:
@@ -43,7 +43,7 @@
|
|||||||
px.TaskSpec(
|
px.TaskSpec(
|
||||||
"git_check",
|
"git_check",
|
||||||
cmd=["git", "--version"],
|
cmd=["git", "--version"],
|
||||||
conditions=(BuiltinConditions.HAS_APP_INSTALLED("git"),)
|
conditions=(BuiltinConditions.HAS_INSTALLED("git"),)
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
report = px.run(graph)
|
report = px.run(graph)
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ def check(name: str) -> px.Condition:
|
|||||||
bool
|
bool
|
||||||
如果已安装则返回 True,否则返回 False.
|
如果已安装则返回 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"),))
|
uv_build: px.TaskSpec = px.TaskSpec("uv_build", cmd=["uv", "build"], conditions=(check("uv"),))
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ class BuiltinConditions:
|
|||||||
return sys.version_info >= (major, minor)
|
return sys.version_info >= (major, minor)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def HAS_APP_INSTALLED(app_name: str) -> Condition:
|
def HAS_INSTALLED(app_name: str) -> Condition:
|
||||||
"""检查指定应用是否已安装.
|
"""检查指定应用是否已安装.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
@@ -102,7 +102,7 @@ class BuiltinConditions:
|
|||||||
def _check() -> bool:
|
def _check() -> bool:
|
||||||
return shutil.which(app_name) is not None
|
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
|
return _check
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -79,25 +79,23 @@ def test_builtin_conditions_python_version_at_least():
|
|||||||
current_major = sys.version_info.major
|
current_major = sys.version_info.major
|
||||||
current_minor = sys.version_info.minor
|
current_minor = sys.version_info.minor
|
||||||
# Current version should be at least itself
|
# Current version should be at least itself
|
||||||
assert (
|
assert BuiltinConditions.PYTHON_VERSION_AT_LEAST(current_major, current_minor) is True
|
||||||
BuiltinConditions.PYTHON_VERSION_AT_LEAST(current_major, current_minor) is True
|
|
||||||
)
|
|
||||||
# Current version should be at least an older version
|
# Current version should be at least an older version
|
||||||
assert BuiltinConditions.PYTHON_VERSION_AT_LEAST(current_major - 1, 0) is True
|
assert BuiltinConditions.PYTHON_VERSION_AT_LEAST(current_major - 1, 0) is True
|
||||||
# Current version should NOT be at least a newer version
|
# Current version should NOT be at least a newer version
|
||||||
assert BuiltinConditions.PYTHON_VERSION_AT_LEAST(current_major + 1, 0) is False
|
assert BuiltinConditions.PYTHON_VERSION_AT_LEAST(current_major + 1, 0) is False
|
||||||
|
|
||||||
|
|
||||||
def test_builtin_conditions_has_app_installed_true():
|
def test_builtin_conditions_HAS_INSTALLED_true():
|
||||||
"""Test BuiltinConditions.HAS_APP_INSTALLED when app exists."""
|
"""Test BuiltinConditions.HAS_INSTALLED when app exists."""
|
||||||
# Python should always be available
|
# Python should always be available
|
||||||
condition = BuiltinConditions.HAS_APP_INSTALLED("python")
|
condition = BuiltinConditions.HAS_INSTALLED("python")
|
||||||
assert condition() is True
|
assert condition() is True
|
||||||
|
|
||||||
|
|
||||||
def test_builtin_conditions_has_app_installed_false():
|
def test_builtin_conditions_HAS_INSTALLED_false():
|
||||||
"""Test BuiltinConditions.HAS_APP_INSTALLED when app doesn't exist."""
|
"""Test BuiltinConditions.HAS_INSTALLED when app doesn't exist."""
|
||||||
condition = BuiltinConditions.HAS_APP_INSTALLED("nonexistent_app_12345")
|
condition = BuiltinConditions.HAS_INSTALLED("nonexistent_app_12345")
|
||||||
assert condition() is False
|
assert condition() is False
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ def test_app_installed_conditions():
|
|||||||
px.TaskSpec(
|
px.TaskSpec(
|
||||||
"python_check",
|
"python_check",
|
||||||
cmd=python_cmd,
|
cmd=python_cmd,
|
||||||
conditions=(BuiltinConditions.HAS_APP_INSTALLED("python"),),
|
conditions=(BuiltinConditions.HAS_INSTALLED("python"),),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user