Skip to main content

A simple Python-based build system

Project description

buildmgr - A simple Python-based build system

This module lets you define targets, dependencies, and commands in pure Python to manage your project's build workflow, similar to Make.

Usage

  1. Define your own targets:

    • Use BuildTarget for normal build steps: • name: unique identifier • help_msg: short description shown in CLI help • log_msg: message printed when the target runs • commands: list of shell commands (each is a Sequence[str|Path]) • dependencies: other BuildTarget instances this target relies on • inputs / outputs: files to determine staleness
    • Use CleanupTarget to remove files or directories: • patterns: glob patterns to delete • directories: Path objects to remove entirely
  2. Customize global behavior:

    • Call get_logger() at import to configure ANSI-colored logging.
    • Use global_config.dry_run = True to simulate without executing.
  3. Wire up your build graph:

    setup = BuildTarget(
        name="setup",
        help_msg="Create virtualenv & install dependencies",
        log_msg="Setting up virtual environment",
        commands=[
            ["python3", "-m", "venv", ".venv"],
            [Path(".venv/bin/python"), "-m", "pip", "install", "-r", "requirements.txt"],
        ],
        outputs=[Path(".venv")],
    )
    
    build_docs = BuildTarget(
        name="docs",
        help_msg="Build Sphinx documentation",
        log_msg="Generating docs",
        commands=[["make", "html", "-C", "docs"]],
        dependencies=[setup],
        inputs=list(Path("docs").rglob("*.rst")),
        outputs=[Path("docs/_build/html/index.html")],
    )
    

Instantiate and run the build system:

from build import BuildSystem
import sys

all_target = BuildTarget(
    name="all",
    help_msg="Build everything",
    log_msg="Building all targets",
    commands=[],
    dependencies=[build_docs, /* your other targets here */],
)

system = BuildSystem(
    targets=[setup, build_docs, all_target, /* others */],
    default=all_target
)

if __name__ == "__main__":
    sys.exit(system())  # Parses CLI args, determines outdated targets, and runs them in order

Command-line interface

$ buildmgr [target]

  target     Name of the target to run (default: 'all')
Options:
  -d, --dry-run    Show commands but do not execute
  -v, --verbose    Enable DEBUG-level logging
  -q, --quiet      Show only WARNING and above

Key features

Incremental builds: only targets whose outputs are missing or older than any inputs will be run.

Automatic dependency topological sort with cycle detection.

ANSI-colored logging with optional verbosity levels.

Easy cleanup via CleanupTarget.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

buildmgr-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

buildmgr-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file buildmgr-0.1.0.tar.gz.

File metadata

  • Download URL: buildmgr-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for buildmgr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6459e4208726b662d7d11b409439c7200c47bb31e4aae58e985a687115842a3a
MD5 d0ae288c5f075ace6a8a7dea850f3f3b
BLAKE2b-256 48751008b26fbf618bbd0a85db50bf7b319098bd8cbf12c156a95e03b7c1c052

See more details on using hashes here.

File details

Details for the file buildmgr-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: buildmgr-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for buildmgr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 864b13ee4a52fee943e00715e8a46c20f30ab343061e782d877eed35ebc5032f
MD5 48b06fe8c976b806be91bfadce3a04b0
BLAKE2b-256 7750b560893c9828b807d74c51ab8239d1b5e3f47b205d44e86335405824905a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page