Skip to main content

Small, practical build and task automation system written in Python.

Project description

halfling

Small, practical build and task automation system written in Python.

Installation

$ pip3 install halfling

Introduction

For some strange reason I felt the urge to create my own build system. Halfling currently supports C and C++ builds out of the box (with incremental builds based on file modified times), but adding your own builder is as simple as subclassing halfling.builders.Builder (see halfling/builders/cxx.py for an example).

Halfling is not intended to be feature rich, free of bugs, or particularly fast. On my machine, builds with halfling are marginally slower than builds with make.

The biggest advantage to halfling is extensibility. The halfling CLI (invoked with halfling) will attempt to load a file named halfling.py in the current directory. This halfling.py file acts as an extension file; it can be used to configure your builds, add tasks to the CLI, and/or execute any arbitrary python code.

Example extension file (halfling/examples/shotgun/halfling.py):

from pathlib import Path

import halfling

# Common build options used by all types
build_options = halfling.builders.CxxBuildOptions(
    executable_name="shotgun.out",
    compiler="g++",
    build_dir=Path(__file__).parent / "hbuild",
    sources=[
        "src/main.cpp",
        "src/add.cpp",
        "src/sub.cpp",
    ],
    obj_dir="hobj",
    flags=["-Wall"],
    include_paths=["lib/mul/inc"],
    defines=["DEFINED_IN_PY", "ALSO_DEFINED_IN_PY"],
    lib_paths=["lib/mul"],
    libs=["mul"]
)

# Add build and clean tasks to halfling
halfling.shortcuts.add_build_and_clean_tasks(
    halfling.builders.CxxBuilder(build_options),
    # The build_types_dict allows users to specify custom build types which can be selected with
    # the -t/--type CLI option. The default will be the first build type specified in the dict
    # (if you're using python 3.7+, and most likely if you're using python 3.6).
    #
    # Each build type must provide a function which takes one argument (the build options data
    # structure).
    #
    # The build_types_dict defaults to None, in which case, there will be no -t/--type CLI option.
    build_types_dict={
        "debug": lambda options: options.flags.extend(["-g"]),
        "release": lambda options: options.flags.extend(["-O2"])
    }
)


# Add a custom task
def my_task(args):
    print(f"echo: {args.echo}")


def setup_my_task_args(parser):
    parser.add_argument("echo", type=str, help="string to echo back")


halfling.tasks.add_task("my_task", my_task, setup_my_task_args)

# Execute arbitrary code at load time. This probably isn't useful, its more for the sake of
# demonstrating that this is just normal python code.
print("Extension file loaded.")

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

halfling-0.2.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

halfling-0.2.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file halfling-0.2.0.tar.gz.

File metadata

  • Download URL: halfling-0.2.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.10

File hashes

Hashes for halfling-0.2.0.tar.gz
Algorithm Hash digest
SHA256 606133462a96548a3d7ddf70cf5aa5d46c7ea97945b8ea82b63af7865c8fc9ce
MD5 ed646d951028db506ad3e2d5bd0d9b35
BLAKE2b-256 b7ee53711b84e0021d062a5e89d96c27c34135e2e81ea0b5b23045c4ef7cdef3

See more details on using hashes here.

File details

Details for the file halfling-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: halfling-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.10

File hashes

Hashes for halfling-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3fc477f22fc2385e270177b08d806c06e13a59bb45369d05a48bbd72bacbf36
MD5 4be51814ef600b93c6c65b77374b62be
BLAKE2b-256 8ab252c150e29d7582db887a90bf8f1ec85b34d4e7961ad497b4a4e6afd21a0c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page