Skip to main content

A small build system

Project description

Bygg

a Python build system that gets out of your way

PyPI GitHub Release Date GitHub Workflow Status (with branch) Python Version from PEP 621 TOML GitHub

InstallationUsageDevelopment


Bygg is in early stage of development. It is usable and useful for its currently implemented use cases. Feel free to try it out, but also expect things to change and evolve. Feedback and bug reports are welcome!

Introduction

Bygg is a build system implemented in and configured using Python. It is general-purpose, but is aimed at those that (want to) use Python to glue together other systems.

Bygg tries to get out of your way and be as thin as possible, while still providing correctness and minimal rebuilds.

Basics

  • Specify actions in pure Python.
  • Actions can depend on other actions.
  • An action will be executed if the digests of its source or output files have changed.

Installation

Bygg requires Python 3.11 or 3.12.

Install with

pip install bygg or pipx install bygg

or in a virtual environment.

Usage

Specify the actions in Byggfile.py in your source directory. Either wrap the action function using the @action decorator, or use the Action constructor directly.

# Decorator:

@action(
    "build1",
    inputs=["foo.in", "bar.in"],
    outputs=["foo.out", "bar.out"],
    is_entrypoint=True
)
def a_build_command(ctx: ActionContext):
    # do stuff
    ...


# Separate function + Action constructor:

def also_a_build_command(ctx: ActionContext):
    # do stuff
    ...

Action(
    "build2",
    inputs=["foo.in", "bar.in"],
    outputs=["foo.out", "bar.out"],
    dependencies=["another action"],
    command=also_a_build_command,
    is_entrypoint=True
)

Bygg will check for the presence of Byggfile.py in the current directory. The actions above would be built with bygg build1 and bygg build2, respectively. See the examples/ directory for worked examples.

Settings files

There is also support for declaring actions, environments and settings in YAML and TOML files called Byggfile.yml and Byggfile.toml, respectively. This is intended primarily for configuring static settings like which virtual environment to use and their respective entrypoints, but can also be used for declaring static actions. See examples/taskrunner/Byggfile.toml, examples/taskrunner/Byggfile.yml and examples/environments/Byggfile.yml.

The evaluation order is TOML -> YAML -> Python. Actions and settings declared later will override earlier ones.

Shell tab completions

TL;DR: bygg --completions

Bygg has support for Bash and Zsh tab completions of arguments and entrypoint actions. The completions will be loaded:

  • from Byggfile.py if Byggfile.yml doesn't exist, or if there are no environments declared in Byggfile.yml.
  • from Byggfile.yml if it exists. If it has environments, each environment will be installed if needed and its respective Byggfile evaluated to collect all entrypoint actions.

To install completions, do:

bygg --completions

It will output a line that you can then add to .bashrc or .zshrc.

Don't forget to open a new shell instance after you've made changes to the settings files.

Manual steps

Add the following line to .bashrc or .zshrc:

eval "$(.your_bygg_venv/bin/register-python-argcomplete .your_bygg_venv/bin/bygg)"
Note for Zsh + argcomplete v2 users

The recommended setup above uses the argcomplete that is installed with Bygg, since this version (starting with v3) has proper support for Zsh so that the action completions will show descriptions. If you for whatever reason need to use a lower version of argcomplete you need to load the Bash compatibility layer first, and then the Bygg completions:

autoload -U bashcompinit ; bashcompinit
eval "$(register-python-argcomplete bygg)"

Getting a local copy

If you want to try out the examples or even develop Bygg itself, Bygg can be tried out and worked on without installing it globally:

First, clone this repo and cd into it, then execute the commands below.

If uv is installed (e.g. with pipx install uv), it will be used by bootstrap.py and the Bygg examples where relevant. This will speed up project setup and test running. If uv is not installed, regular pip will be used.

# Create a virtual environment and install Bygg into it together with its dependencies:
./bootstrap.py
# Activate the virtual environment:
. .venv/bin/activate

Now you can try out one of the examples:

cd examples/trivial
bygg transform

In the above, bygg is the command to execute bygg, and transform is an action (much like a target in a Makefile). See examples/trivial/Byggfile.py for details.

The target can be cleaned with

bygg transform --clean

Development

Running tests

With Bygg's virtual environment activated per above, tests can be run from the root directory:

pytest

With the virtual environment deactivated, the full test suite can be run with Nox. Nox should be installed outside of Bygg's virtual environment since it manages its own virtual environments:

pipx install nox

or

pip install --user --upgrade nox

After that, run tests with

nox

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

bygg-0.6.1.tar.gz (60.2 kB view details)

Uploaded Source

Built Distribution

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

bygg-0.6.1-py3-none-any.whl (39.7 kB view details)

Uploaded Python 3

File details

Details for the file bygg-0.6.1.tar.gz.

File metadata

  • Download URL: bygg-0.6.1.tar.gz
  • Upload date:
  • Size: 60.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for bygg-0.6.1.tar.gz
Algorithm Hash digest
SHA256 e5ba49aef21ab487bcd882338518bdde872e1f6881d19fc93467807a3ae277d4
MD5 b86537ef088c4391f18f81e37681a495
BLAKE2b-256 8db7725e5325f36a0ca008a18bef5418bf95f5e9b3409473cf10f8623fd6b316

See more details on using hashes here.

Provenance

The following attestation bundles were made for bygg-0.6.1.tar.gz:

Publisher: pypi_publish.yml on rikardg/bygg

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

File details

Details for the file bygg-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: bygg-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 39.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for bygg-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e55517c139051e08f40e40bfa263b7983a1d868e5e43f76e42846a9615dd5811
MD5 08ac6481917ee56aa77da150ca521b1f
BLAKE2b-256 2c2cef5c43e07c70585d856d09cea3246b60d2a104a89d24484aea216e86070b

See more details on using hashes here.

Provenance

The following attestation bundles were made for bygg-0.6.1-py3-none-any.whl:

Publisher: pypi_publish.yml on rikardg/bygg

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