formate
¶
Python formatting mate.
Functions:
|
Given a list of hooks (in order), call them in turn to reformat the source. |
|
Reformat the given file, and show the diff if changes were made. |
|
Call isort, using the given keyword arguments as its configuration. |
|
Call yapf, using the given keyword arguments as its configuration. |
Classes:
|
Reformat a Python source file. |
-
call_hooks
(hooks, source, filename)[source]¶ Given a list of hooks (in order), call them in turn to reformat the source.
- Parameters
- Return type
- Returns
The reformatted source.
Changed in version 0.4.3: Added the
filename
argument.
-
reformat_file
(filename, config, colour=None)[source]¶ Reformat the given file, and show the diff if changes were made.
- Parameters
- Return type
-
class
Reformatter
(filename, config)[source]¶ Bases:
object
Reformat a Python source file.
- Parameters
filename (
Union
[str
,Path
,PathLike
]) – The filename to reformat.config (
FormateConfigDict
) – Theformate
configuration, parsed from a TOML file (or similar).
Attributes:
The filename being reformatted, as a POSIX-style path.
The filename being reformatted.
The
formate
configuration, parsed from a TOML file (or similar).Methods:
run
()Run the reformatter.
get_diff
()Returns the diff between the original and reformatted file content.
Return the reformatted file as a string.
to_file
()Write the reformatted source to the original file.
-
config
¶ Type:
FormateConfigDict
The
formate
configuration, parsed from a TOML file (or similar).
-
isort_hook
(source, formate_filename, formate_global_config=None, **kwargs)[source]¶ Call isort, using the given keyword arguments as its configuration.
-
yapf_hook
(source, formate_global_config=None, **kwargs)[source]¶ Call yapf, using the given keyword arguments as its configuration.
- Parameters
If
yapf_style
is given as a keyword argument, use that style. If a filename is given as the style it is searched for in the current and parent directories, and the style taken from the configuration in that file.- Return type
- Returns
The reformatted source.