Core (barabash.core)

Core of Barabash build scripting framework

barabash.core.run()[source]

Run Barabash script.

It scans command line parameters and executes accordingly. If there is a target in command line then it is executed.

barabash.core.run_target(target)[source]

Run specified target in Barabash script.

Parameters:target – a name of target defined in Barabash script
barabash.core.define_map_op(output, action)[source]

Define a new map operation.

Parameters:
  • output – a mapping definition that maps inputs to outputs, works as rules in GNU make, e.g. %.o: %.c - it maps for example main.c to main.o
  • action – a Bash script or Python function

Example:

>>> Pygmentize = define_map_op("%.html:%.py", "pygmentize -O -f html -o {out} {in}")
barabash.core.define_reduce_op(action)[source]

Define a new reduce operation.

Parameters:action – a Bash script or Python function

Example:

>>> Tar = define_reduce_op("tar -C {srcdir} -zcvf {out} {in.basename}")
barabash.core.define_ops_chain(*actions)[source]

Define a chain of operations.

Parameters:actions – a list of operations

Example:

>>> CompileAndLink = define_ops_chain(Compile, Link)
barabash.core.add_dependency(fname, operation)[source]

Add dependency for given file on a given operation.

Parameters:
  • fname – a file name
  • operation – an operation that file depends on

Example:

>>> add_dependency("www/examples.html", pygmentize_examples)
barabash.core.include(path)[source]

Include submodule to Barabash script.

Parameters:path – a relative or absolute path to Barabsh script submodule

Example:

>>> lib = include("lib/lib.py")
barabash.core.set_env(var, val)[source]

Set Barabash script environment variable.

Parameters:
  • var – a name of variable
  • val – a value of variable

Example:

>>> set_env("CC", "/usr/bin/gcc")
barabash.core.project(name)[source]

Define a project name.

Parameters:name – a name of project

Example:

>>> project("Sample Project")
barabash.core.patsubst(in_ptrn, out_ptrn, files)[source]

Substitute string in files according to pattern.

Parameters:
  • in_ptrn – a pattern for input files
  • out_ptrn – an output pattern for output files
  • files – a list of files
Returns:

a list of converted file names

Example:

>>> patsubst("%.c", "%.o", ["src/main.c"])
["src/main.o"]
class barabash.core.Files(name, files=None, glob_=None, regex=None, recursive=True)[source]

A named set of files.

Parameters:
  • name – a name of the set of files, it can be referenced in deps in Operation
  • files – a list of files
  • glob – a glob rule that matches a set of files, alternative to files parameter
  • regex – a regex rule that matches a set of files, alternative to files parameter
  • recursive – TBD, unused

Example:

>>> src_js = Files("src_js", ["a.js", "b.js"])
class barabash.core.Operation(name, deps, op_type, output, action=None, indirect_deps=[])[source]

An operation that has input dependencies and generates outputs according to action.

Operation class is a core element in Barabash that allows building a graph of dependencies.

Parameters:
  • name – a name of operation, it can be referenced in other Operation as dep
  • deps – a dependency or a list of dependencies, a dependecy can be a Files or other Operation
  • op_type – an operation type, it can be "map" (MapOp) or "reduce" (ReduceOp) or "cmd" (Command).
  • output – a rule that defines how output is named, it depends on op_type
  • action – a python function or a Bash script that will be executed in operation
  • indirect_deps – an additional set of dependent elemets (files and Operation) that is not treated as inputs, e.g. header files in C compilation
indirect_deps(env)[source]

Return indirect dependencies.

Override this function in subclass to return list of additional dependencies for the operation. It can be used to bring additional deps as for example header files from C source files.

See example usage in barabash.ops.Compile class.

run_script(script, env)[source]

Run Bash script.

Parameters:
  • script – a Bash script
  • env – variables that can be used in the script

This is helper function for running shell script. Any variables in the script are substituted with values before running. This function can be used in action function also overriden in this class.

class barabash.core.MapOp(name, deps, output, action, indirect_deps=[])[source]

A map operation.

Parameters:
  • name – a name of operation, it can be referenced in other Operation as dep
  • deps – a dependency or a list of dependencies, a dependecy can be a Files or other Operation
  • output – a mapping rule like in GNU make
  • action – a python function or a Bash script that will be executed in operation
  • indirect_deps – an additional set of dependent elemets (files and Operation) that is not treated as inputs, e.g. header files in C compilation

Example:

>>> objects = MapOp("objects", src_c, "%.o:%.c", "{CC} -c {in} -o {out}")
class barabash.core.ReduceOp(name, deps, *args)[source]

A reduce operation.

Parameters:
  • name – a name of operation, it can be referenced in other Operation as dep
  • deps – a dependency or a list of dependencies, a dependecy can be a Files or other Operation
  • output – an output file name, optional
  • action – a python function or a Bash script that will be executed in operation

Example:

>>> js_tar_gz = ReduceOp("js.tar.gz", src_js, "tar -C {srcdir} -zcvf {out} {in.basename}")
class barabash.core.Command(name, *args)[source]

A command operation.

Parameters:
  • name – a name of operation, it can be referenced in other Operation as dep
  • deps – a dependency or a list of dependencies, a dependecy can be a Files or other Operation
  • action – a python function or a Bash script that will be executed in operation

Example:

>>> build_pkg = Command("build-pkg", "python setup.py sdist")





blog comments powered by Disqus