blog Checking Justfiles With repo-review Framework

Tags:
justfile python

After finding the repo-review , one of the first checks I wanted, was to check some of the justfiles that I have started using across projects.

I wrote repo-review-just ( PyPI - Version PyPI - Version ) to help me check a few things.

The trick to starting this, is knowing that just allows you to dump the configuraiton as json.

just --dump-format=json --dump

Writing checks

With this in mind, it is easy to get it into Python for us to write our checks with.

from subprocess import check_output
import json

text = check_output(["just", "--dump-format=json", "--dump"])
justfile = json.loads(text)

Using Python 3.10’s match statement, we can write simple tests to check for recipies that we want to ensure exist.

class J003(Just):
    "Provides _help method"

    @staticmethod
    def check(justfile) -> bool | str:
        match justfile:
            case {"recipes": {"_help": dict()}}:
                return True
            case _:
                return "Missing _help"

or write a test that each of our recipies have a doc comment on them.

class J006(Just):
    "Commands are documented"

    @staticmethod
    def check(justfile) -> bool | str:
        missing = []
        for name, recipe in justfile.setdefault("recipes", {}).items():
            if recipe["doc"] is None and not name.startswith("_"):
                missing.append(name)

        if missing:
            return f"Recipies missing docs: {missing}"

        return True

The full code can be found on codeberg and I welcome suggestions.

Enabling our checks

uv add --dev 'repo-review[cli]'
uv add --dev repo-review-just

This adds the packages we need to run our checks. Then we can add a few lines to our Justfile to make it easier to run our review check.

# Run repo-review showing only errors
review *args:
    uv run repo-review --show err {{ args }}

Now when we run just review we can get output similar to the following.

just:
├── J001 Just file present ✅
├── J002 Makefile present without Justfile ❌
│   Check failed
├── J003 Provides _help method ✅
├── J004 Provides format method ❌
│   Missing format
├── J005 Provides test method ❌
│   Missing test
└── J006 Commands are documented ✅

Future work

I may have gone a bit overboard in quickly prototyping several checks to use with some of my repos.

PyPi Version Status
https://pypi.org/project/repo-review-just/ PyPI - Version PyPI - Version
https://pypi.org/project/repo-review-endoflife/ PyPI - Version PyPI - Version
https://pypi.org/project/repo-review-woodpecker/ PyPI - Version PyPI - Version
https://pypi.org/project/repo-review-classifiers/ PyPI - Version PyPI - Version
https://pypi.org/project/repo-review-readme/ PyPI - Version PyPI - Version

Ideally, I will try to make packages under a repo-review-<tool> namespace more generally useful, and then make custom checks in a custom repo for just myself.