Configuration file routines (config)#

Functions:

get_git_root_path([cwd])

Get root path of git repo.

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_git_root_path(cwd: str | Path | None = None) Path | None[source]#

Get root path of git repo.

open_notebook.config.get_config_files(cwd: str | Path = '.', home: str | Path | None = None, config_name: str = '.open-notebook.toml') dict[str, Path | None][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: Mapping[str, Any] | Sequence[Mapping[str, Any]], default_params: Mapping[str, Any] | None = None) 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).

host([section, passed, default])

Host option.

port([section, passed, default])

Port option.

root([section, passed, default])

Root option.

dir_prefix([section, passed, default])

Directory prefix option.

file_prefix([section, passed, default])

File prefix option.

to_options_dict([section])

Convert options to dictionary.

from_paths(paths[, default_params])

Create from path(s).

from_strings(strings[, default_params])

Create from string(s).

from_config_files([name, cwd, home, ...])

Create from config file(s).

get(*keys: str, default: Any = MISSING, factory: Callable[[], Any] | None = None) Any[source]#

Get value from config(s)

get_option(key: str, passed: Any = MISSING, section: str | None = None, default: Any = MISSING, factory: Callable[[], Any] | None = None) Any[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 (object) – Passed in value. If not utils.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

host(section: str | None = None, passed: Any = MISSING, default: str | MISSING_TYPE = MISSING) str[source]#

Host option.

port(section: str | None = None, passed: Any = MISSING, default: str | MISSING_TYPE = MISSING) str[source]#

Port option.

root(section: str | None = None, passed: Any = MISSING, default: str | MISSING_TYPE = MISSING) Path[source]#

Root option.

dir_prefix(section: str | None = None, passed: Any = MISSING, default: str | MISSING_TYPE = MISSING) str[source]#

Directory prefix option.

file_prefix(section: str | None = None, passed: Any = MISSING, default: str | MISSING_TYPE = MISSING) str[source]#

File prefix option.

to_options_dict(section: str | None = None, **kws: Any) dict[str, Any][source]#

Convert options to dictionary.

classmethod from_paths(paths: str | Path | Iterable[str | Path], default_params: Mapping[str, Any] | None = None) Self[source]#

Create from path(s).

classmethod from_strings(strings: str | Iterable[str], default_params: Mapping[str, Any] | None = None) Self[source]#

Create from string(s).

classmethod from_config_files(name: str = '.open-notebook.toml', cwd: str | Path = '.', home: str | Path | None = None, default_params: Mapping[str, Any] | None = None) Self[source]#

Create from config file(s).

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

Create a configuration file.