Skip to main content

Sane

Sane is Makefile for humans.

Key Concepts

  • Recipes are python functions with recipe/file/hook dependencies.

  • If a recipe A depends on recipe B, recipe B is checked. If B is ran, then A is ran afterwards.

  • Recipes are ran if its dependency files are newer than its target files (or if either cannot be found).

  • Recipes with no dependencies are always ran.

  • Hooks are a way to tag dependencies. Recipes depending on a hook depend on all recipes with that hook.

  • Everything else is standard Python.

Getting Started

All of Sane is contained in sane.py.

With this file in your PYTHONPATH or the same directory:

# make.py

from sane import *

# ... Recipe definitions ...

sane_run(default_recipe)

then python make.py runs the default recipe. Call python make.py --help for more information.

Example

import subprocess as sp
from os import makedirs
from glob import glob

from sane import *

CC = "gcc"
EXE = "main"

c_sources = glob("src/*.c")

for sourcefile in c_sources:
    objectfile = sourcefile + '.o'
    @recipe(
        name=f"compile_{sourcefile}",
        hooks=["compilation"],
        target_files=[objectfile],
        file_deps=[sourcefile])
    def compile():
        makedirs("obj/", exist_ok=True)
        sp.run(f"{CC} -c {sourcefile} -o {objectfile}", shell=True)

@recipe(hook_deps=["compilation"])
def link():
    obj_files = ' '.join(glob("src/*.o"))
    sp.run(f"{CC} -o {EXE} {obj_files}", shell=True)

sane_run(link)

The @recipe Decorator

@recipe(
    name="...",
    hooks=[...],
    file_deps=[...],
    target_files=[...],
    recipe_deps=[...],
    hook_deps=[...])

name - The name of the recipe (str). If none is given, the name is inferred from the associated function's name. Two recipes cannot share the same name.

hooks - An array of hooks applicable to the recipe ([str]).

file_deps - The file dependencies of this recipe ([str]). This recipe is ran if the newest of these files is newer that the oldest of the target_files.

target_files - Files to check against file_deps ([str]).

recipe_deps - The recipe dependencies of this recipe ([str or fn]); before running this recipe, these are checked. If any is ran, this recipe is ran.

hook_deps - The hook dependencies of this recipe ([str]); before running this recipe, all recipes with any of these hooks are checked. If any is ran, this recipe is ran.

License

This tool is licensed under an MIT license. See LICENSE for details.

Support

💕 If you liked sane, consider buying me a coffee.

Metadata

Release files for sane-build 4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sane-build 4
File Size Uploaded
sane-build-4.tar.gz 7.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sane-build 4
File Interpreter ABI Platform
sane_build-4-py3-none-any.whl Python 3 none any Details

Total release size: 13.4 kB

Release files / sane-build-4.tar.gz

Download URL sane-build-4.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
269d205f9794725bf1bb4d37c1de208c1c5a5e1f646fceb1c73b132e7b6af050
BLAKE2b-256 checksum
How to use checksums
2d47e0a96ccb6d958c046f2c3e16fd14c82e8a6270656a9737c282af6d78e4d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.8.5

Release files / sane_build-4-py3-none-any.whl

Download URL sane_build-4-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0bba0911770f45a2b477acba5ec81464b1d076b4781dc2dab8fed3f75f40cd93
BLAKE2b-256 checksum
How to use checksums
342d0d9749b71b330e9b0af6a310caf89111ebb0e04eafd1c1f0bdb7ae84fc48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.6.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.8.5

Release history Release notifications | RSS feed

7.3

2 release files

7.2

2 release files

7.1

2 release files

6.1

2 release files

6.0

2 release files

5.0

2 release files

4.3

2 release files

4.2

2 release files

4.1

2 release files

This release

4 This release

2 release files

2.2

2 release files

2.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page