luigi_tools.util

This module provides some fonctions to work with luigi tasks.

Functions

apply_over_inputs(task, func)

Apply the given function to all inputs of a luigi.Task.

apply_over_luigi_iterable(luigi_iterable, func)

Apply the given function to a luigi iterable (task.input() or task.output()).

apply_over_outputs(task, func)

Apply the given function to all outputs of a luigi.Task.

get_dependency_graph(task)

Compute dependency graph of a given task.

graphviz_dependency_graph(g[, graph_attrs, ...])

Create a GraphViz dependency graph.

recursive_check(task[, attr])

Check if a task or any of its recursive dependencies has a given attribute set to True.

register_templates([directory, name, ...])

Add INI templates to the config file list processed by luigi.

render_dependency_graph(graph, filepath, ...)

Render a dependency graph using GraphViz.

target_remove(target, *args, **kwargs)

Remove a given target by calling its 'exists()' and 'remove()' methods.

Classes

set_luigi_config([params, configfile])

Context manager to set current luigi config.

Exceptions

WorkflowError

Exception raised when the workflow is not consistent.

exception luigi_tools.util.WorkflowError

Bases: Exception

Exception raised when the workflow is not consistent.

luigi_tools.util.apply_over_inputs(task, func)

Apply the given function to all inputs of a luigi.Task.

The given function should accept the following arguments:
  • task_output: the output(s) of the required task(s) of the given task

  • key=None: the key when the iterable is a dictionnary

luigi_tools.util.apply_over_luigi_iterable(luigi_iterable, func)

Apply the given function to a luigi iterable (task.input() or task.output()).

luigi_tools.util.apply_over_outputs(task, func)

Apply the given function to all outputs of a luigi.Task.

The given function should accept the following arguments:
  • target: the output target(s) of the given task

  • key=None: the key when the iterable is a dictionnary

luigi_tools.util.get_dependency_graph(task)

Compute dependency graph of a given task.

Parameters

task (luigi.Task) – the task from which the dependency graph is computed.

Returns

A list of (parent, child) tuples.

Return type

list(luigi.Task)

luigi_tools.util.graphviz_dependency_graph(g, graph_attrs=None, node_attrs=None, edge_attrs=None, root_attrs=None, task_names=None, node_kwargs=None, edge_kwargs=None, graphviz_class=None)

Create a GraphViz dependency graph.

Parameters
Returns

The Graph or Digraph created.

luigi_tools.util.recursive_check(task, attr='rerun')

Check if a task or any of its recursive dependencies has a given attribute set to True.

luigi_tools.util.register_templates(directory=None, name=None, hierarchy_end=True)

Add INI templates to the config file list processed by luigi.

This function should be used before the luigi.Task are processed, so it should usually be used in the __init__.py of your package.

In order to use a template, a Template section entry must be added to the luigi.cfg of the project. This section should contain at least one entry with the name of the template to use, and, optionally, another entry with the path to the directory containing the templates, as the following example:

[Template]
name = template_name
directory = /path/to/the/template/directory

If the directory or the name entries are given in the luigi.cfg file, they override the arguments given to this function.

A template file should be similar to a luigi.cfg file with only the entries for which specific default values should be defined. The file should named according to the template name. For example, the template named template_1 should be a INI file located in the given directory and named template_1.cfg.

Parameters
  • directory (str) – Path to the directory containing the template files.

  • name (str) – The name of the template to use.

  • hierarchy_end (bool) – If set to False, the luigi.cfg entry is not added after the template entry, so it is possible to combine several templates before processing the luigi.cfg file.

luigi_tools.util.render_dependency_graph(graph, filepath, **kwargs)

Render a dependency graph using GraphViz.

Parameters
class luigi_tools.util.set_luigi_config(params=None, configfile=None)

Bases: object

Context manager to set current luigi config.

Parameters
  • params (dict) – The parameters to load into the luigi configuration.

  • configfile (str) – Path to the temporary config file (luigi.cfg by default).

export_config(filepath)

Export the configuration to the configuration file.

get_config()

Convert the parameter dict to a configparser.ConfigParser object.

luigi_tools.util.target_remove(target, *args, **kwargs)

Remove a given target by calling its ‘exists()’ and ‘remove()’ methods.