line_profiler.toml_config module¶
Read and resolve user-supplied TOML files and combine them with the default to generate configurations.
- class line_profiler.toml_config.ConfigSource(conf_dict: Dict[str, Any], path: Path, subtable: List[str])[source]¶
Bases:
objectObject encapsulating the config dict and the source whence it is read from.
- Variables:
conf_dict (dict[str, Any]) – The combination of the
tool.line_profilertables of the provided/looked-up config file (if any) and the default as a dictionary.path (pathlib.Path) – Absolute path to the config file whence the config options are loaded.
subtable (list[str]) – Sequence of table headers under which in
pathconf_dictcan be found.
- get_subconfig(*headers, allow_absence=False, copy=False)[source]¶
- Parameters:
headers (str) – Table headers.
allow_absence (bool) – If true, allow for the keys to be absent (and return an instance with an empty
conf_dict); otherwise, raise aKeyError.copy (bool) – If true, create a (deep) copy of the subtable in
selffor the new instance’sconf_dict; otherwise, just refer to the existing subtable.
- Returns:
New instance which consists of the required subtable of the existing one.
Example
>>> default = ConfigSource.from_default() >>> display_widths = default.get_subconfig( ... 'show', 'column_widths') >>> assert display_widths.path == default.path >>> assert (display_widths.subtable ... == default.subtable + ['show', 'column_widths']) >>> assert (display_widths.conf_dict ... is default.conf_dict['show']['column_widths'])
- classmethod from_default(*, copy=True)[source]¶
Get the default TOML configuration that ships with the package.
- Parameters:
copy (bool) – Whether to make a copy.
- Returns:
New instance if
copyis true, the global default instance otherwise.
- classmethod from_config(config=None, *, read_env=True)[source]¶
Create an instance by loading from a config file.
- Parameters:
config (Union[str, PurePath, bool, None]) – Optional path to a specific TOML file; if a (string) path, skip lookup and just try to read from that file; if
NoneorTrue, use lookup to resolve to the correct file; ifFalse, skip lookup and just use the default configsread_env (bool) – Whether to read the environment variable
LINE_PROFILER_RCfor a config file (instead of moving straight onto environment-based lookup) ifconfigis not provided.
- Returns:
New instance
Note
For the config TOML file, it is required that each of the following keys either is absent or maps to a table:
toolandtool.line_profilertool.line_profiler.kernprof,.cli,.setup,.write, and.showtool.line_profiler.show.column_widths
If this is not the case:
If
configis provided, aValueErroris raised.Otherwise, the looked-up file is considered invalid and ignored.