Configuration¶
Google Docformatter reads configuration from the [tool.g_docformatter] section in the pyproject.toml file in the root of your project.
Width¶
The maximum line width is controlled by the width option. The default value is 88.
[tool.g_docformatter]
width = 88
Indent Size¶
The number of spaces to use for indentation is controlled by the indent_size option. The default value is 4.
[tool.g_docformatter]
indent_size = 4
Code Formatters¶
Code blocks are formatted using code formatters. By default, Google Docformatter uses black for python code blocks and does not format other languages.
Default Code Formatter¶
To set the default code formatter, use the default_code_formatter option:
[tool.g_docformatter]
default_code_formatter = "DefaultCodeFormatter"
Code formatters may also need options to be passed to them. To pass options to the default code formatter, use the following configuration:
[tool.g_docformatter.default_code_formatter]
class = "DefaultCodeFormatter"
options = {option1 = "value1", option2 = "value2"}
Language Specific Code Formatters¶
To use a different code formatter for a specific language, use the code_formatters option. The following example shows how to set the code formatter for python code blocks:
[tool.g_docformatter]
code_formatters = {python = "BlackCodeFormatter"}
To pass options to the code formatter, use the following configuration:
[tool.g_docformatter.code_formatters.python]
class = "BlackCodeFormatter"
options = {option1 = "value1", option2 = "value2"}
Code formatters for other languages can be set in the same way by replacing python with the desired language.
Built-in Code Formatters¶
Google Docformatter ships with the following built-in code formatters:
- class g_docformatter.code_formatters.BlackCodeFormatter(**options: Any)¶
Formatter that formats Python code with black.
- Parameters:
options** – Options to pass to
black.Mode.
- class g_docformatter.code_formatters.SimpleCodeFormatter(**options: Any)¶
Formatter that uses
textwrap.fillto format the code.
- class g_docformatter.code_formatters.DefaultCodeFormatter(**options: Any)¶
Formatter that does not format the code.
These formatters can be used by specifying just the class name in the configuration.
Using Custom Code Formatters¶
Custom code formatters can be used by specifying the fully qualified class name in the configuration. The following example shows how to set a custom code formatter for python code blocks using a hypothetical CustomCodeFormatter from the custom_code_formatter package:
[tool.g_docformatter]
code_formatters = {python = "custom_code_formatter.CustomCodeFormatter"}
See also