Skip to content

Commit

Permalink
feat: Support Just task runner
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall committed Dec 5, 2023
1 parent 7a6ae1f commit e7cbc7d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = [
"setuptools >= 63.0.0", # required by pyproject+setuptools_scm integration
"setuptools >= 63.0.0", # required by pyproject+setuptools_scm integration
"setuptools_scm[toml] >= 7.0.5", # required for "no-local-version" scheme

]
Expand Down 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 Expand Up @@ -97,7 +98,7 @@ no_incremental = true
max-statements = 60
disable = [
# Disabled on purpose (explain in comment)
"line-too-long", # black managed
"line-too-long", # black managed
"wrong-import-position", # isort managed
# TODO(ssbarnea): remove temporary skips adding during initial adoption:
"dangerous-default-value",
Expand Down
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
2 changes: 1 addition & 1 deletion src/mk/tools/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def actions(self) -> list[Action]:
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
# Inspired by https://github.com/containers/podman/blob/6d984739458511f444e80f06f6a12dd400268372/Makefile#L127
match = re.match(r"^([a-zA-Z_-]+):.*?## (.*)$$", line)
if match:
target, description = match.groups()
Expand Down

0 comments on commit e7cbc7d

Please sign in to comment.