Settings#

b2luigi.core.settings.get_setting(key: str, default: Any = None, task: object | None = None, deprecated_keys: List[str] | None = None) Any[source]#

b2luigi adds a settings management to luigi and also uses it at various places. Many batch systems, the output and log path, the environment etc. is controlled via these settings.

There are four ways settings could be defined. They are used in the following order (an earlier setting overrides a later one):

  1. If the currently processed (or scheduled) task has a property of the given name, it is used. Please note that you can either set the property directly, e.g.

    class MyTask(b2luigi.Task):
        batch_system = "htcondor"
    

    or by using a function (which might even depend on the parameters)

    class MyTask(b2luigi.Task):
        @property
        def batch_system(self):
            return "htcondor"
    

    The latter is especially useful for batch system specific settings such as requested wall time etc.

  2. Settings set directly by the user in your script with a call to b2luigi.set_setting().

  3. Settings specified in the settings.json in the folder of your script or any folder above that. This makes it possible to have general project settings (e.g. the output path or the batch system) and a specific settings.json for your sub-project.

With this function, you can get the current value of a specific setting with the given key. If there is no setting defined with this name, either the default is returned or, if you did not supply any default, a value error is raised.

Settings can be of any type, but are mostly strings.

Parameters:
  • key (str) – The name of the parameter to query.

  • task – (b2luigi.Task): If given, check if the task has a parameter with this name.

  • default (optional) – If there is no setting which the name, either return this default or if it is not set, raise a ValueError.

  • deprecated_keys (List) – Former names of this setting, will throw a warning when still used

b2luigi.core.settings.set_setting(key: str, value: Any) None[source]#

Updates the global settings dictionary with a specified key-value pair.

This function allows overriding any existing settings defined in setting.json. It is particularly useful for dynamically updating settings during runtime. For task-specific settings, consider creating a parameter with the given name in your task instead.

Parameters:
  • key (str) – The name of the setting to update or add.

  • value (Any) – The value to associate with the specified key.

b2luigi.core.settings.clear_setting(key: str) None[source]#

Removes a setting from the global settings dictionary.

If the key does not exist, the function silently handles the KeyError.

Parameters:

key (str) – The key of the setting to be removed.

exception b2luigi.core.settings.DeprecatedSettingsWarning[source]#

Bases: DeprecationWarning

A custom warning class used to indicate deprecated settings.

This warning is a subclass of DeprecationWarning and can be used to alert users about the usage of settings that are no longer supported or will be removed in future versions.

Usage:

Raise this warning when a deprecated setting is accessed or used.

Example

warnings.warn("This setting is deprecated.", DeprecatedSettingsWarning)