Skip to content

Commit

Permalink
Add support for taskfile tool
Browse files Browse the repository at this point in the history
Fixes: #119
  • Loading branch information
ssbarnea committed Mar 7, 2023
1 parent 5089d67 commit 7469719
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
4 changes: 4 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
codecov:
require_ci_to_pass: true
comment: false
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pypackage = "mk.tools.py_package:PyPackageTool"
pytest = "mk.tools.pytest:PyTestTool"
pre-commit = "mk.tools.pre_commit:PreCommitTool"
shell = "mk.tools.shell:ShellTool"
taskfile = "mk.tools.taskfile:TaskfileTool"
tox = "mk.tools.tox:ToxTool"

[tool.black]
Expand Down
62 changes: 62 additions & 0 deletions src/mk/tools/taskfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import json
import logging
import os
import shutil
import sys
from typing import List, Optional

from mk.exec import run_or_fail
from mk.tools import Action, Tool


class TaskfileTool(Tool):
name = "taskfile"

def __init__(self, path=".") -> None:
"""Initialize."""
super().__init__(path)
self.executable = ""

def is_present(self, path: str) -> bool:
if os.path.isfile(os.path.join(path, "taskfile.yml")):
# On some Linux distros might be exposed as taskfile in order to
# avoid clashing with the other Task Warrior executable https://taskwarrior.org/
self.executable = shutil.which("taskfile") or shutil.which("task")
if not self.executable:
logging.error(
"taskfile.yml config found but the tool is not installed. See https://taskfile.dev/installation/"
)
sys.exit(1)
return True
return False

def actions(self) -> List[Action]:
actions: List[Action] = []
tasks_json = (
run_or_fail(
["task", "--list", "--json"],
tee=False,
).stdout
or ""
)
for task in json.loads(tasks_json)["tasks"]:
desc = task["desc"]
if task["summary"]:
desc += "\n"
desc += task["summary"]
actions.append(
Action(
name=task["name"],
tool=self,
description=desc,
args=[task["name"]],
)
)
return actions

def run(self, action: Optional[Action] = None) -> None:
if not action:
cmd = ["task"]
else:
cmd = ["task", action.name]
run_or_fail(cmd, tee=True)

0 comments on commit 7469719

Please sign in to comment.