DutyRunner
Base classes
| Name |
Children |
Inherits |
TaskRunner anyenv.task_runners._base Base class for task runner configurations. |
|
|
⋔ Inheritance diagram
graph TD
3910300439["_python.DutyRunner"]
3225203877["_base.TaskRunner"]
2751680898["builtins.object"]
3225203877 --> 3910300439
2751680898 --> 3225203877
🛈 DocStrings
Bases: TaskRunner
Task runner for Duty (pawamoy/duty).
Source code in src/anyenv/task_runners/_python.py
| @dataclass
class DutyRunner(TaskRunner):
"""Task runner for Duty (pawamoy/duty)."""
id: ClassVar[Literal["duty"]] = "duty"
website: ClassVar[str] = "https://github.com/pawamoy/duty"
filenames: ClassVar[list[str]] = ["duties.py"]
help_cmd: ClassVar[list[str]] = ["duty", "--list"]
logo: ClassVar[str | None] = None
async def get_tasks(self, fs: AsyncFileSystem, cwd: str) -> list[TaskInfo]:
"""Parse duties.py and return available tasks."""
config_file = await self.get_config_file(fs, cwd)
if config_file is None:
return []
content = await self._read_file(fs, config_file)
return self._parse_duties(content)
def _parse_duties(self, content: str) -> list[TaskInfo]:
"""Parse duties.py to extract @duty decorated functions."""
try:
tree = ast.parse(content)
except SyntaxError:
return []
tasks: list[TaskInfo] = []
for node in ast.walk(tree):
if not isinstance(node, ast.FunctionDef):
continue
# Check if function has @duty decorator
is_duty = any(
(isinstance(d, ast.Name) and d.id == "duty")
or (
isinstance(d, ast.Call) and isinstance(d.func, ast.Name) and d.func.id == "duty"
)
for d in node.decorator_list
)
if not is_duty:
continue
# Extract docstring as description
description = ast.get_docstring(node)
tasks.append(TaskInfo(name=node.name, description=description))
return sorted(tasks, key=lambda t: t.name)
def get_run_command(self, task_name: str, *args: str) -> list[str]:
"""Get the duty command for a specific task."""
return ["duty", task_name, *args]
|
get_run_command
get_run_command(task_name: str, *args: str) -> list[str]
Get the duty command for a specific task.
Source code in src/anyenv/task_runners/_python.py
| def get_run_command(self, task_name: str, *args: str) -> list[str]:
"""Get the duty command for a specific task."""
return ["duty", task_name, *args]
|
get_tasks
async
get_tasks(fs: AsyncFileSystem, cwd: str) -> list[TaskInfo]
Parse duties.py and return available tasks.
Source code in src/anyenv/task_runners/_python.py
| async def get_tasks(self, fs: AsyncFileSystem, cwd: str) -> list[TaskInfo]:
"""Parse duties.py and return available tasks."""
config_file = await self.get_config_file(fs, cwd)
if config_file is None:
return []
content = await self._read_file(fs, config_file)
return self._parse_duties(content)
|
:fa-brands-github: Show source on GitHub