Just (Python Wrapper)

1.49.0 · active · verified Sun Apr 12

rust-just is a Python wrapper for the `just` command runner, a powerful and simpler alternative to Make for project-specific task automation. It allows Python applications to programmatically invoke `just` recipes defined in a `Justfile`. The current version, 1.49.0, aligns with the version of the underlying `just` command-line tool, which maintains an active development cycle with frequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `rust-just` wrapper to execute recipes defined in a `Justfile`. It shows how to run a simple recipe, a recipe with arguments, and handles expected errors when recipes fail or don't exist. It also sets up a temporary `Justfile` for a runnable example.

import os
import subprocess

# Create a dummy Justfile for demonstration
justfile_content = """
hello:
  echo 'Hello from Just!'

greet NAME=\"World\":
  echo "Hello, {{NAME}}!"

fail:
  exit 1
"""

with open('Justfile', 'w') as f:
    f.write(justfile_content)

try:
    from just import Just
    just_runner = Just()

    print("Running 'hello' recipe:")
    result_hello = just_runner.run(recipe='hello')
    print(f"Output: {result_hello.stdout.strip()}\n")

    print("Running 'greet' recipe with argument:")
    result_greet = just_runner.run(recipe='greet', args=['NAME=Pythonista'])
    print(f"Output: {result_greet.stdout.strip()}\n")

    print("Attempting to run a non-existent recipe (expected error):")
    try:
        just_runner.run(recipe='non_existent')
    except subprocess.CalledProcessError as e:
        print(f"Caught expected error: {e.stderr.strip().splitlines()[0]} [...]")

    print("Attempting to run 'fail' recipe (expected error):")
    try:
        just_runner.run(recipe='fail')
    except subprocess.CalledProcessError as e:
        print(f"Caught expected error with return code {e.returncode}\n")

finally:
    # Clean up the dummy Justfile
    if os.path.exists('Justfile'):
        os.remove('Justfile')

view raw JSON →