formate.config

Read and parse formate configuration.

Exceptions:

HookConfigError

Base exception for errors with hook configuration.

NoHooksError()

Exception for when no hooks are configured.

NoSupportedHooksError(filetype)

Exception for when no hooks support the given file type.

Data:

_C_str

Invariant TypeVar bound to typing.Callable[…, str].

Functions:

formats_filetypes(*filetypes)

Decorator to indicate to formate that the hook formats the specified filetypes (as extensions, e.g.

get_hooks_for_filetype(filetype, hooks)

Filters the hooks to those that support the given filetype.

load_toml(filename)

Load the formate configuration mapping from the given TOML file.

parse_global_config(config)

Returns a read-only view on the global configuration mapping, for hooks to do with as they wish.

parse_hooks(config)

Given a mapping parsed from a TOML file (or similar), return a list of hooks selected by the user.

wants_filename(func)

Decorator to indicate to formate that the filename being reformatted should be passed to this hook.

wants_global_config(func)

Decorator to indicate to formate that the global configuration should be passed to this hook.

exception HookConfigError[source]

Bases: ValueError

Base exception for errors with hook configuration.

exception NoHooksError[source]

Bases: formate.config.HookConfigError

Exception for when no hooks are configured.

exception NoSupportedHooksError(filetype)[source]

Bases: formate.config.HookConfigError

Exception for when no hooks support the given file type.

Parameters

filetype (str)

_C_str = TypeVar(_C_str, bound=typing.Callable[..., str])

Type:    TypeVar

Invariant TypeVar bound to typing.Callable[…, str].

formats_filetypes(*filetypes)[source]

Decorator to indicate to formate that the hook formats the specified filetypes (as extensions, e.g. ".js".

New in version 1.2.0.

Parameters

*filetypes

Return type

Callable[[~_C_str], ~_C_str]

get_hooks_for_filetype(filetype, hooks)[source]

Filters the hooks to those that support the given filetype.

Parameters
Return type

List[Hook]

load_toml(filename)[source]

Load the formate configuration mapping from the given TOML file.

Parameters

filename (Union[str, Path, PathLike])

Return type

FormateConfigDict

parse_global_config(config)[source]

Returns a read-only view on the global configuration mapping, for hooks to do with as they wish.

Parameters

config (Mapping) – The formate configuration, parsed from a TOML file (or similar).

Return type

MappingProxyType

parse_hooks(config)[source]

Given a mapping parsed from a TOML file (or similar), return a list of hooks selected by the user.

Parameters

config (Mapping) – The formate configuration, parsed from a TOML file (or similar).

Return type

List[Hook]

wants_filename(func)[source]

Decorator to indicate to formate that the filename being reformatted should be passed to this hook.

The configuration will be provided as the formate_filename: PathLike keyword argument.

New in version 0.2.0.

Parameters

func (~_C_str)

Return type

~_C_str

wants_global_config(func)[source]

Decorator to indicate to formate that the global configuration should be passed to this hook.

The configuration will be provided as the formate_global_config: Mapping keyword argument.

Parameters

func (~_C_str)

Return type

~_C_str