Skip to main content

A tool to automatically format Python docstrings that tries to follow recommendations from PEP 8 and PEP 257.

Project description

PyPI pyversions codecov Tests pre-commit.ci status Documentation Status

Pydocstringformatter

A tool to automatically format Python docstrings to follow recommendations from PEP 8 and PEP 257 (or other supported style guides.)

See What it does for currently supported auto-formatting.

Rationale

This project is heavily inspired by docformatter.

When this project was started docformatter did not meet all of the requirements the pylint project had for its docstring formatter and was no longer actively maintained (this has changed since then). Therefore, some contributors of pylint got together and started working on our own formatter to fulfill our needs.

When asked we defined the objective of the tool as:

"A docstring formatter that follows PEP8 and PEP257 but makes some of the more 'controversial' elements of the PEPs optional"

See the original answer.

As such, the biggest difference between the two is that pydocstringformatter fixes some of the open issues we found in docformatter. In general, the output of both formatters (and any other docstring formatter) should be relatively similar.

How to install

pip install pydocstringformatter

Usage

Click here for a full Usage overview.

Configuration

Pydocstringformatter will also read any configuration added to the [tool.pydocstringformatter] section of a pyproject.toml file.

For example:

[tool.pydocstringformatter]
write = true
exclude = "**/my_dir/**,**/my_other_dir/**"
# Or:
exclude = ["**/my_dir/**", "**/my_other_dir/**"]
strip-whitespaces = true
split-summary-body = false
numpydoc-section-hyphen-length = false

Style

Pydocstringformatter can be configured to use a specific style. The default is pep257 but we support other styles as well. These can also be used at the same time. For example with:

pydocstringformatter --style=pep257 --style=numpydoc myfile.py

Pre-commit

Pydocstringformatter can also be used as a pre-commit hook. Add the following to your .pre-commit-config.yaml file:

- repo: https://github.com/DanielNoord/pydocstringformatter
  rev: SPECIFY VERSION HERE
  hooks:
    - id: pydocstringformatter

What it does

The following examples show some of the changes pydocstringformatter will apply. For a full overview of all potential changes you can check out the Usage page which shows an up to date list of all formatters and their description.

# Bad
'''
my docstring'''

"""    my
multi-line docstring      """

"""my title
===========

my docstring
"""


# Good
"""My docstring."""

"""My
multi-line docstring.
"""

"""My title
===========

My docstring
"""

# With --summary-quotes-same-line
# Bad
"""
My
multi-line docstring
"""

# Good
"""My
multi-line docstring
"""

Development

For development and contributing guidelines please see Development.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydocstringformatter-0.7.3.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

pydocstringformatter-0.7.3-py3-none-any.whl (31.3 kB view details)

Uploaded Python 3

File details

Details for the file pydocstringformatter-0.7.3.tar.gz.

File metadata

  • Download URL: pydocstringformatter-0.7.3.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for pydocstringformatter-0.7.3.tar.gz
Algorithm Hash digest
SHA256 dfcc07bec1706803d563275e282ef9e629b02dc19983ec6778d07a9f500bb62b
MD5 fcfe6f29ebc754d2fa8874f13f37c012
BLAKE2b-256 b3515c21963eb7bdba245ec808fdb0ef8abc0cd87ef674f2b6ba1fd76f3a0ffa

See more details on using hashes here.

File details

Details for the file pydocstringformatter-0.7.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pydocstringformatter-0.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3654f52c49fc729b49712d1e7c49384dfd253bdffeda4939e79dab31491c563f
MD5 c4fc10b54dd419cb4d840a444ab3db05
BLAKE2b-256 3a38b3a99e9cc66941e044ad3d40e90a72b1191925b8af13e3e4d8edc5c0eb87

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page