Skip to main content

Python build automation framework with decorator-based DSL

Project description

chorelib

A Python build automation framework — like Make, but in Python. chorelib focuses on keeping Make-style speed and rebuild behavior while letting you write build logic in real Python.

chorelib uses a decorator-based DSL for defining build rules and tasks, with dependency management, parallel execution, and mtime-based rebuild detection.

Features

  • Decorator-based DSL — Define build rules with @rule and tasks with @task, using familiar Python syntax
  • Regex target patterns — Match multiple targets with regex and use backreferences (\1) in dependency specifications
  • Async parallel execution — Run independent build steps concurrently with configurable worker count
  • mtime-based rebuild — Skip up-to-date targets automatically, just like Make
  • Custom mtime functions — Override mtime checking per target pattern to manage non-file resources (databases, S3 objects, etc.)
  • Order-only prerequisitesneeds dependencies ensure build order without triggering rebuilds
  • Auto-generated help-h shows usage with target documentation from docstrings, -l lists all available targets
  • Custom command-line options — Subclass Main to add your own argparse options for build configuration
  • Zero dependencies — Pure Python, no external packages required

Best for: developers who want Make-like rebuild behavior but need Python for complex logic or non-file resources. It also works well as a simple task runner for everyday scripts.

Documentation

Full documentation is available at https://chorelib.readthedocs.io/en/latest/

Installation

pip install chorelib

Quick Start

Here is a Makefile and its chorelib equivalent side by side.

Makefile:

CC=gcc
CFLAGS=-I.
DEPS = hello.h
OBJS = main.o hello.o
.PHONY: clean

%.o: %.c $(DEPS)
	$(CC) -c -o $@ $< $(CFLAGS)

hello.exe: $(OBJS)
	$(CC) -o $@ $^

clean:
	rm -f $(OBJS) hello.exe

chorelib (make.py):

import re
from chorelib import Main, command, rule, task

main = Main()
APP = "hello.exe"
CC = "gcc"
CFLAGS = ["-c", "-I."]
DEPS = ["hello.h"]
OBJS = ["hello.o", "main.o"]

@rule(APP, depends=OBJS, default=True)
def link(target, deps, needs):
    """Build executable"""
    command(CC, "-o", target, deps)

@rule(re.compile(r"(.+)\.o"), depends=(r"\1.c", DEPS))
def compile(target, deps, needs):
    command(CC, "-o", target, deps[0], CFLAGS)

@task
def clean():
    """Remove the built files."""
    command("rm", "-f", OBJS, APP)

if __name__ == "__main__":
    main.run()
uv run make.py              # Build default target
uv run make.py clean        # Run the clean task
uv run make.py -w 4         # Build with 4 parallel workers
uv run make.py -r           # Force rebuild all
uv run make.py -h           # Show help with target docs
uv run make.py -l           # List all available targets

-h displays usage information along with target documentation extracted from docstrings:

$ uv run make.py -h
usage: make.py [-h] [-C DIRECTORY] [-w WORKERS] [-r] [-l] [-v] [-V] [targets ...]

Sample build script for building a C program using chorelib.

hello.exe [default]:
    Build executable

clean:
    Remove the built files.

rebuild:
    Clean and rebuild all files.

execute:
    Rebuild and execute the program.
...

-l lists all registered targets with their types, dependencies, and builder functions:

$ uv run make.py -l
[rule] hello.exe:
  depends: hello.o, main.o
  needs:
  function: link

[rule] re: (.+)\.o:
  depends: \1.c, hello.h
  needs:
  function: compile

[task] clean:
  needs:
  builder: clean
...

Why chorelib over Make?

Make chorelib
Pattern rules %.o: %.c r"^(.+)\.o" with backreferences
Variables & logic Limited macro language Full Python
Parallel builds make -j4 python make.py -w 4
Non-file targets .PHONY @task decorator
Custom mtime Not supported @mtime decorator for databases, remote objects, etc.
Dependencies File-only Files, functions, or any callable

License

MIT

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

chorelib-0.2.1.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

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

chorelib-0.2.1-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file chorelib-0.2.1.tar.gz.

File metadata

  • Download URL: chorelib-0.2.1.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for chorelib-0.2.1.tar.gz
Algorithm Hash digest
SHA256 8ae00327b475bb89a2f85fa7c11e2b1e82f947d318beba921d2c076d8cd6cbf2
MD5 b22c3a838755d9e3d0375c3aecdb7fd9
BLAKE2b-256 aa8383f969f29c6db7ee7584340f51670c08d86ec04629f4b047d9e4b7190954

See more details on using hashes here.

Provenance

The following attestation bundles were made for chorelib-0.2.1.tar.gz:

Publisher: publish.yml on atsuoishimoto/chorelib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chorelib-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: chorelib-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for chorelib-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 079a7dc712aeb771c7027615e7479582ef04cce7ef3f5cd83de743ca20b901c4
MD5 db2813de1b07d6cf774416ca4d30c069
BLAKE2b-256 d27965d9214c13630ed4ce87cb01c3a2d958bb663683cc80c8b1964bac41e6fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for chorelib-0.2.1-py3-none-any.whl:

Publisher: publish.yml on atsuoishimoto/chorelib

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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