Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requiring --unstable breaks recursive invocations #1564

Closed
indigoviolet opened this issue Mar 8, 2023 · 5 comments
Closed

Requiring --unstable breaks recursive invocations #1564

indigoviolet opened this issue Mar 8, 2023 · 5 comments

Comments

@indigoviolet
Copy link

If you happen to add an unstable feature like !include to your justfile, now all your recursive invocations are broken because they fail without --unstable. This seems suboptimal. Proposal: allow JUST_UNSTABLE=true to be set in the environment instead.

Related: #1430

@sgtsquiggs
Copy link

To get around this I name my justfiles this.justfile. In my common.justfile I have the recipe:

[private]
generate-unstable-justfile:
  #!/usr/bin/env bash
  set -euxo pipefail
  echo -n > justfile
  for recipe in $(just --justfile this.justfile --unstable --summary); do
    echo "@$recipe:" >> justfile
    echo "  just --justfile this.justfile --unstable $recipe" >> justfile
  done

I have a pre-commit hook that will run

just --justfile path/to/common.justfile  --working-directory path/containing/this.justfile generate-unstable-justfile

@sgtsquiggs
Copy link

honestly working around the limitations feels like make again and it's somehow refreshing 😅

@sgtsquiggs
Copy link

Rewrote this in python to handle arguments properly:

#!/usr/bin/env python3
import subprocess
from argparse import ArgumentParser, FileType


def format_arg(arg: str) -> str:
    if arg[:1] == "+":
        arg = f"*{arg[1:]}"
    return arg.split("=")[0]


def format_var(var: str) -> str:
    return f"{{{{{var.lstrip('+*').split('=')[0]}}}}}"


def main():
    parser = ArgumentParser()
    parser.add_argument("src", help="source justfile", type=FileType("r"))

    args = parser.parse_args()

    lines = [
        x.strip()
        for x in subprocess.run(
            ["just", "--justfile", args.src.name, "--unstable", "--list"],
            check=True,
            capture_output=True,
        )
        .stdout.decode("utf-8")
        .splitlines()
        if x != "Available recipes:"
    ]

    print("# AUTO GENERATED. DO NOT EDIT.")

    for line in lines:
        parts = line.split()
        recipe = parts.pop(0)
        print(f"@{' '.join([recipe]+[format_arg(x) for x in parts])}:")
        print(
            "  {{just_executable()}}",
            "--justfile",
            args.src.name,
            "--unstable",
            recipe,
            *[format_var(x) for x in parts],
        )


if __name__ == "__main__":
    try:
        main()
    except subprocess.CalledProcessError as e:
        print(e.stderr)
        raise e

should be run in the directory you want the destination justfile to live, ie:

python3 -u script.py relative/path/to/unstable.justfile > justfile

@IrrationalPi
Copy link

@sgtsquiggs I have purely just workaround using dump for the !includes issue, I've posted it in: Issue 1641

Not sure if it fills the same need as your Python script.

@casey
Copy link
Owner

casey commented Oct 9, 2023

A workaround is now available, you can set the JUST_UNSTABLE environment variable, which will be available to recursive invocations of just.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants