The Build Object

The core functionality in Uranium is contained inside the build object. The build is an interface the environment that uranium is building: You can use the various attributes to manipulate it.

Examples include:

  • build.packages to modify packages
  • build.envvars to modify environment variables

And so on. For tasks, the build object is always passed in as the only argument:

def main(build):
    print(build.root)

uranium.current_build

There are situations where one needs to bootstrap a ubuild.py before executing a task, such as installing hooks or setting configuration.

In that situation, uranium.current_build works well: It is a proxy object that returns back whatever build object is currently executing:

from uranium import current_build
current_build.config.set_defaults({"debug": False})

def main(build):
    if build.config["debug"]:
        print("debug message")

Full API Reference

class uranium.build.Build(root, config=None, with_sandbox=True, cache_requests=True)[source]

the build class is the object passed to the main method of the uranium script.

it’s designed to serve as the public API to controlling the build process.

Build is designed to be executed within the sandbox itself. Attempting to execute this outside of the sandbox could lead to corruption of the python environment.

config
Returns:a uranium.config.Config object

this is a generic dict to store / retrieve config data that tasks may find valuable

envvars
Returns:a uranium.environment_variables.EnvironmentVariables object

this is an interface to the environment variables of the sandbox. variables modified here will be preserved when executing entry points in the sandbox.

executables
Returns:uranium.executables.Executables

an interface to execute scripts

history
Returns:uranium.history.History

a dictionary that can contain basic data structures, that is preserved across executions.

ideal for storing state, such as if a file was already downloaded.

hooks
Returns:uranium.hooks.Hooks

provides hooks to attach functions to be executed during various phases of Uranium (like initializiation and finalization)

include(script_path, cache=False)[source]

executes the script at the specified path.

options
Returns:uranium.options.Options

an interface to arguments passed into the uranium command line.

packages
Returns:uranium.packages.Packages

an interface to the python packages currently installed.

root
Returns:str

returns the root of the uranium build.

task(f)[source]

a decorator that adds the given function as a task.

e.g.

@build.task def main(build):

build.packages.install(“httpretty”)

this is useful in the case where tasks are being sourced from a different file, besides ubuild.py

tasks
Returns:uranium.tasks.Tasks

an interface to the tasks that uranium has registered, or has discovered in the ubuild.py