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
Paragraph Formatting¶
Each paragraph type in a docstring can be formatted with a different text formatter. The
paragraph option is a table of paragraph types, each with their own set of formatting
options.
[tool.g_docformatter.paragraph.root]
summary = "inverse_hanging_indent"
eod = "indent_only"
[tool.g_docformatter.paragraph.body]
text = "uniform_indent"
repl_code = "indent_only"
[tool.g_docformatter.paragraph.list_section]
header = "indent_only"
list_item = "hanging_indent"
[tool.g_docformatter.paragraph.std_section]
header = "indent_only"
[tool.g_docformatter.paragraph.sphinx_code_block]
header = "indent_only"
option = "indent_only"
"code.default" = "as_is"
"code.python" = "black"
The value for each option is the name of a text formatter to use. The table below describes the available paragraph types and their options.
Section |
Option |
Default |
Description |
|---|---|---|---|
|
|
|
Text formatter for the summary line of the docstring. |
|
|
|
Text formatter for the end-of-docstring closing quotes. |
|
|
|
Text formatter for body description text. |
|
|
|
Text formatter for REPL (interactive Python session) code blocks in the body. |
|
|
|
Text formatter for the section header of list-style sections (e.g. |
|
|
|
Text formatter for individual items within list-style sections. |
|
|
|
Text formatter for the section header of standard text sections (e.g. |
|
|
|
Text formatter for the |
|
|
|
Text formatter for options within a |
|
|
|
Text formatter for code blocks with no recognised language. |
|
|
|
Text formatter for Python code blocks. |
Text Formatters¶
The following text formatters are available:
Name |
Description |
|---|---|
|
Returns the text unchanged. Useful for preserving manually formatted content. |
|
Applies the correct indentation without reflowing or wrapping the text. |
|
Reflows the text using |
|
Reflows the text so the first line is at the current indent level and subsequent lines are indented one level further. |
|
Reflows the text so the first line has no indentation and subsequent lines are indented at the current indent level. |
|
Formats Python code using the Black code formatter. See Black Formatter Options for additional options. |
Black Formatter Options¶
Options for the Black text formatter can be passed via the text_formatter_options.black
table. These are forwarded directly to black.Mode (excluding line_length,
which is derived from the width and indent_size settings).
[tool.g_docformatter.text_formatter_options.black]
target_versions = ["py311", "py312"]
Refer to the Black documentation
for a full list of supported black.Mode options.