Skip to main content

Tools for building

Project description

Build Graph

Build Graph provides a set of tools to run build steps in order of their dependencies.

Build graphs can be constructed by hand, or you can let the library construct the graph for you.

In the following examples, we'll be using this step definition:

class Adder(BaseStep):
    """
    Returns its input added to a small random number
    """
    def execute(self, n):
        new = n + 1
        print(new)
        return new

Manual construction

Defining steps

Steps are defined by constructing a step definition and binding the required arguments.

# This will create a single 'Adder' step with input 5
a = Adder(5)

Step arguments can be other steps:

# This will provide the output from step a as input to step b
a = Adder(0).alias("a")  # Set an alias to identify the steps
b = Adder(a).alias("b")

To run the steps, we pick the last step in the graph and call its run method.

...
result = b.run()
print(result)  # 2

A step from anywhere in the graph can be run, but only that step's dependencies will be executed.

print(a.run())  # 1 - Step b won't be run

Side dependencies

Sometimes you'll need to run a step a before step b, but a's output won't be used by b.

class Printer(BaseStep):
    """
    Returns its input added to a small random number
    """
    def execute(self, msg):
        print(msg)

p = Printer("Hi")
a = Adder(0).alias("a")
b = Adder(a).alias("b").after(p)  # This ensures b will run after p
b.run()

The after(*steps) method specified steps that must be run first. If multiple steps are provided it doesn't enforce an ordering between those steps.

Detatched steps

If a step is defined but not listed as a dependency it won't be run:

a = Adder(0).alias("a")
b = Adder(1).alias("b")
b.run()  # This won't run a

You can check which steps will be run with the getExecutionOrder and printExecutionOrder methods.

Circular dependencies

Buildgraph will check for loops in the graph before running it and will raise an exception if one is detected.

Automatic construction

The @buildgraph decorator builds a graph where every node is reachable from the final node.

@buildgraph
def addergraph():
    a = Adder(0)
    b = Adder(1)
    c = Adder(2)

addergraph.run()  # This will run all 3 steps

If the steps don't have dependencies the execution order isn't guaranteed, but generally the steps that are defined first will be run first unless another dependency enforces a different order.

Returning from a graph

Graphs can return results from a step too.

@buildgraph
def addergraph():
    a = Adder(0)
    b = Adder(a)
    return b

result = addergraph.run() 
print(result)  # 1

Extending steps

All steps must inherit from BaseStep and implement an execute method.

You can see example steps from src/steps.py. These steps can also be imported and used in code.

Type checking

Buildgraph will perform type checking when the graph is built if the execute method has type annotations on its parameters.

Configuring buildgraph

By default buildgraph prints coloured output. You can disable this with buildgraph.setColor(False).

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

buildgraph-0.0.2.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

buildgraph-0.0.2-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file buildgraph-0.0.2.tar.gz.

File metadata

  • Download URL: buildgraph-0.0.2.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.7.5 Linux/4.4.0-19041-Microsoft

File hashes

Hashes for buildgraph-0.0.2.tar.gz
Algorithm Hash digest
SHA256 6ecbe2a3a77b3d6c711be41d6d388cda13bbd598d4173f02b8d92c4a4e6fe755
MD5 e950013bef50c634c28a7876963680f8
BLAKE2b-256 b162c77e9210ed80d7413ebff527a01c41780ba7ae43d3a15aa13822506ba1ce

See more details on using hashes here.

File details

Details for the file buildgraph-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: buildgraph-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.7.5 Linux/4.4.0-19041-Microsoft

File hashes

Hashes for buildgraph-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 79ce8b1fb47aefa0f8f7e773dc17d7e76765c07297589d46a1c4d4455a10ddcf
MD5 74c1f91d93ba3553de58e303e95b3837
BLAKE2b-256 a9357b5f7630ff60a56151bfbc9fbd8fcc64a58b4f2b09ecd440d3ff5e217cf6

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