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.1.tar.gz (6.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.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: buildmgr-0.1.1.tar.gz
  • Upload date:
  • Size: 6.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.1.tar.gz
Algorithm Hash digest
SHA256 5d13a8fcee88e5726e309daeff6de2ef9ea0835af1c08895f722a5d36c51ee0c
MD5 478d2f4e536c5231970b7115311740ad
BLAKE2b-256 14dbfeb8c621bd1e20992f7410b97165a189408f8ad83c50142ff9b4229b1d5b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: buildmgr-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 325f3c6ced01bfa63e869dc57cb1e8bdd3a587582fc55bf496a5d9ee08402d8c
MD5 29c900dadca1dca2ff88b3e87fc9dd52
BLAKE2b-256 899b63233f1cff5e21511cf752f62f52dfb3a82d4ca2673d91512b2bd0e80c2e

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