Skip to main content

Make, but Sane

Project description

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.

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

sane-build-4.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

sane_build-4-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file sane-build-4.tar.gz.

File metadata

  • Download URL: sane-build-4.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for sane-build-4.tar.gz
Algorithm Hash digest
SHA256 269d205f9794725bf1bb4d37c1de208c1c5a5e1f646fceb1c73b132e7b6af050
MD5 9d05081d6c5c8f48806f50a76199f6c7
BLAKE2b-256 2d47e0a96ccb6d958c046f2c3e16fd14c82e8a6270656a9737c282af6d78e4d8

See more details on using hashes here.

File details

Details for the file sane_build-4-py3-none-any.whl.

File metadata

  • Download URL: sane_build-4-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for sane_build-4-py3-none-any.whl
Algorithm Hash digest
SHA256 0bba0911770f45a2b477acba5ec81464b1d076b4781dc2dab8fed3f75f40cd93
MD5 166a43207187d39fa0c746e3952c88c0
BLAKE2b-256 342d0d9749b71b330e9b0af6a310caf89111ebb0e04eafd1c1f0bdb7ae84fc48

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