Configuration file routines (config)#

Functions:

get_config_files([cwd, home, config_name])

Find the config file

create_config(host, port, root, dir_prefix, ...)

Create a configuration file.

Classes:

Config(data[, default_params])

Configuration handler

open_notebook.config.get_config_files(cwd='.', home=None, config_name='.open-notebook.toml')[source]#

Find the config file

Order for search is "current directory", "git root", "user home".

Parameters:
  • cwd (str or Path, default ".") -- Current directory.

  • home (str or Path, optional) -- Defaults to pathlib.Path.home. For testing purposes.

  • config_name (str, default ".open-notebook.ini")

  • Name of config file

class open_notebook.config.Config(data, default_params=None)[source]#

Bases: object

Configuration handler

Accepts multiple mappings. Will parse them left to right for matches

Methods:

get(*keys[, default, factory])

Get value from config(s)

get_option(key[, passed, section, default, ...])

Get option value from either passed in option, or from config file (left to right).

get(*keys, default=_Missing.MISSING, factory=None)[source]#

Get value from config(s)

get_option(key, passed=_Missing.MISSING, section=None, default=_Missing.MISSING, factory=None)[source]#

Get option value from either passed in option, or from config file (left to right).

Order of checking is:

  • passed

  • data[section][key] for data in self.data.

  • data[key] for data in self.data.

  • factory

  • default

Parameters:
  • key (str, optional) -- key to look for.

  • passed (default MISSING) -- Passed in value. If not MISSING, this will be the returned value.

  • section (str, optional) -- The table section to check. Fall back to top level of any dict.

  • factory (callable(), optional) -- If no value found, return factory().

  • default -- Fallback value to return

open_notebook.config.create_config(host, port, root, dir_prefix, file_prefix, path=None, overwrite=False, home=None)[source]#

Create a configuration file.