mcflugen / docformatter

Formats docstrings to follow PEP 257

Home Page:https://pypi.python.org/pypi/docformatter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

docformatter

Code BLACK ISORT
Docstrings SELF DOCSTYLE
GitHub CI CONTRIBUTORS COMMIT
PyPi VERSION LICENSE PYVERS PYMAT DD

Formats docstrings to follow PEP 257.

Features

docformatter automatically formats docstrings to follow a subset of the PEP 257 conventions. Below are the relevant items quoted from PEP 257.

  • For consistency, always use triple double quotes around docstrings.
  • Triple quotes are used even though the string fits on one line.
  • Multi-line docstrings consist of a summary line just like a one-line docstring, followed by a blank line, followed by a more elaborate description.
  • Unless the entire docstring fits on a line, place the closing quotes on a line by themselves.

docformatter also handles some of the PEP 8 conventions.

  • Don't write string literals that rely on significant trailing whitespace. Such trailing whitespace is visually indistinguishable and some editors (or more recently, reindent.py) will trim them.

See the the full documentation at read-the-docs, especially the requirements section for a more detailed discussion of PEP 257 and other requirements.

Installation

From pip:

$ pip install --upgrade docformatter

Or, if you want to use pyproject.toml to configure docformatter:

$ pip install --upgrade docformatter[tomli]

Example

After running:

$ docformatter --in-place example.py

this code

"""   Here are some examples.

    This module docstring should be dedented."""


def launch_rocket():
    """Launch
the
rocket. Go colonize space."""


def factorial(x):
    '''

    Return x factorial.

    This uses math.factorial.

    '''
    import math
    return math.factorial(x)


def print_factorial(x):
    """Print x factorial"""
    print(factorial(x))


def main():
    """Main
    function"""
    print_factorial(5)
    if factorial(10):
        launch_rocket()

gets formatted into this

"""Here are some examples.

This module docstring should be dedented.
"""


def launch_rocket():
    """Launch the rocket.

    Go colonize space.
    """


def factorial(x):
    """Return x factorial.

    This uses math.factorial.
    """
    import math
    return math.factorial(x)


def print_factorial(x):
    """Print x factorial."""
    print(factorial(x))


def main():
    """Main function."""
    print_factorial(5)
    if factorial(10):
        launch_rocket()

Marketing

Do you use docformatter? What style docstrings do you use? Add some badges to your project's README and let everyone know.

SELF

.. image:: https://img.shields.io/badge/%20formatter-docformatter-fedcba.svg
  :target: https://github.com/PyCQA/docformatter
.. image:: https://img.shields.io/badge/%20style-google-3666d6.svg
    :target: https://google.github.io/styleguide/pyguide.html#s3.8-comments-and-docstrings

DOCSTYLE

.. image:: https://img.shields.io/badge/%20style-numpy-459db9.svg
  :target: https://numpydoc.readthedocs.io/en/latest/format.html
.. image:: https://img.shields.io/badge/%20style-sphinx-0a507a.svg
    :target: https://www.sphinx-doc.org/en/master/usage/index.html

Issues

Bugs and patches can be reported on the GitHub page.

About

Formats docstrings to follow PEP 257

https://pypi.python.org/pypi/docformatter

License:MIT License


Languages

Language:Python 100.0%