Skip to content

Commit

Permalink
Add support for Just task runner
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall authored and ssbarnea committed Jan 11, 2024
1 parent 5657805 commit 93613b6
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions playbooks/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
url: https://github.com/python/typeshed.git
- name: flask-babel
url: https://github.com/python-babel/flask-babel.git
- name: just
url: https://github.com/casey/just
tasks:
- name: Show cache directory
ansible.builtin.debug:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ mk = "mk.__main__:cli"
ansible = "mk.tools.ansible:AnsibleTool"
cmake = "mk.tools.cmake:CMakeTool"
git = "mk.tools.git:GitTool"
just = "mk.tools.just:JustTool"
make = "mk.tools.make:MakeTool"
node = "mk.tools.node:NodeTool"
pypackage = "mk.tools.py_package:PyPackageTool"
Expand Down
1 change: 1 addition & 0 deletions samples/integration/just.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
justfile
50 changes: 50 additions & 0 deletions src/mk/tools/just.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from __future__ import annotations

import os
import re
from pathlib import Path

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


class JustTool(Tool):
name = "just"

def __init__(self) -> None:
super().__init__(self)
self.justfile: str | None = None

def run(self, action: Action | None = None) -> None:
cmd = ["just"]
if action:
cmd.append(action.name)
run_or_fail(cmd, tee=True)

def is_present(self, path: Path) -> bool:
for name in ["Justfile", "justfile", "JUSTFILE", ".justfile"]:
justfile = os.path.join(path, name)
if os.path.isfile(justfile):
self.justfile = justfile
return True
return False

def actions(self) -> list[Action]:
actions = []
if not self.justfile:
msg = "Justfile not found"
raise RuntimeError(msg)
# pylint: disable=duplicate-code
with open(self.justfile, encoding="utf-8") as file:
for line in file.readlines():
# Current implementation assumes that descriptions are added
# using double ## after the target name.
# Inspired by https://github.com/containers/podman/blob/master/Makefile#L127
match = re.match(r"^([a-zA-Z_-]+):.*?## (.*)$$", line)
if match:
target, description = match.groups()
actions.append(
Action(name=target, tool=self, description=description),
)
# pylint: enable=duplicate-code
return actions

0 comments on commit 93613b6

Please sign in to comment.