Giter Club home page Giter Club logo

pymake's Introduction

pymake

pymake is a python library and CLI that mimics GNU make's API.

It allows developers to express and execute arbitrarily complex, dependency-based build-trees.

Example

# PyMakefile.py
from pymake import *

some_lib = Makefile('lib/some_lib', out='lib/some_lib/libsome.a')

# compile source -> object files
object_files = CompileC('build/%.o', 'src/%.[ch]', libs=[some_lib])

# link all object files into an executable
@makes('hello-world', object_files("*"))
async def hello_world(deps: List[Path], out: Path):
    await sh(f'gcc {deps} -o {out}')

The above can be rewritten as:

from pymake import *

hello_world = CompileC(
  'hello-world', 'src/**/*.[ch]',
  libs=[
    Makefile('lib/some_lib', out='lib/some_lib/libsome.a')
  ]
)

Now build the hello-world executable with:

pymake hello-world

See examples/hello-world for more detail, or check out the documentation.

Benefits

  • Familiar API and CLI to GNU make
  • Python enables dynamic generation of targets and dependencies
  • Utilise existing Makefiles via pymake.Makefile()
  • Tracks target builds timestamps to a .pymake-cache file by default, so that functions with up-to-date dependencies don't needlessly execute (eloquent alternative to using build flags).
  • Helpful, colorful and configurable log & error messages for quicker bug-fixing
  • Debug your PyMakefiles with PDB or other editor-friendly debuggers
  • Supports async python code out of the box
  • Scales far better with complexity than traditional Makefiles
  • Fully type-hinted for a better developer experience via editor intellisense
  • Provides default implementations of targets which can be overridden:
    • pymake clean - clear the cache and delete all target files.
    • pymake show - displays dependencies and help from docstrings of defined targets (with default docstrings)
  • Backed by simple, extensible OOP framework
  • Callable from CLI or via python library.
  • Import, reconfigure and run targets programatically from other PyMakefiles within a single dependency tree.

Caveats

  • Global mutable state does not work out of the box (ie the globals statement in a function body).
    • pymake may provide a recommended method for achieving this in the future but for now I can't see a use-case.

Documentation

Concepts

Targets

Relative Paths

Wildcards

Caching

API

Alternatives

The OG make. At its core it's a shell executor tied to a dependency tree. Editor support for syntax error/highlighting is minimal. Debugging support is even worse.

In order to track target builds that don't output files, you must use build-flags; empty files that exist solely to track the timestamp of a target's execution. This is messy, error-prone, and unusual.

make is a better option for very simple build trees thanks to it's terse dependency specification syntax. Widely used in industry for decades (particularly among C/C++ devs), so more maintainable in that regard.

Similar to pymake being based on python and an extensible OOP framework.

The API is not as nice to use as pymake though as the scons library is injected rather than imported. Therefore editors either need an SCons extension to provide intellisense or developers must bend over backwards to achieve this.

Requires usage of the scons executable, whereas PyMakefiles can be executed directly through python.

Future Goals

  • pymake --render [target] - Produce a graphviz graphic or .dot file of the dependency tree required by a target
  • Cross-platform support where possible

pymake's People

Contributors

callumjhays avatar

Stargazers

Arnn Baet avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.