Name | darglint JSON |
Version |
1.8.1
JSON |
| download |
home_page | |
Summary | A utility for ensuring Google-style docstrings stay up to date with the source code. |
upload_time | 2021-10-18 03:40:37 |
maintainer | |
docs_url | None |
author | terrencepreilly |
requires_python | >=3.6,<4.0 |
license | MIT |
keywords |
documentation
linter
development
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
[![Build Status](https://travis-ci.com/terrencepreilly/darglint.svg?branch=develop)](https://travis-ci.com/terrencepreilly/darglint)
# Darglint
A functional docstring linter which checks whether a docstring's
description matches the actual function/method implementation.
*Darglint* expects docstrings to be formatted using the
[Google Python Style Guide](https://google.github.io/styleguide/pyguide.html),
or [Sphinx Style Guide](https://pythonhosted.org/an_example_pypi_project/sphinx.html#function-definitions),
or [Numpy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html).
Feel free to submit an issue/pull request if you spot a problem or
would like a feature in *darglint*.
**Table of Contents**:
- [Project Status](#project-status)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)
- [Scope](#scope)
- [Sphinx](#sphinx)
- [Numpy](#numpy)
- [Integrations](#integrations)
- [Flake8](#flake8)
- [Roadmap](#roadmap)
- [Contribution](#development-and-contributions)
## Project Status
I no longer work with Python regularly, and I'd like to spend some more
time on other projects. So while I'll continue to maintain darglint,
I likely won't be adding significant new features. That said, I will
try to accept pull requests. See the contribution section for more
information. Consider it in maintenance mode.
## Installation
To install *darglint*, use pip.
```bash
pip install darglint
```
Or, clone the repository, `cd` to the directory, and
```bash
pip install .
```
## Configuration
*darglint* can be configured using a configuration file. The configuration
file must be named either *.darglint*, *setup.cfg*, or *tox.ini*. It must
also have a section starting with the section header, `[darglint]`.
Finally, the configuration file must be located either in the directory
*darglint* is called from, or from a parent directory of that working
directory.
Currently, the configuration file allows us to ignore errors, to specify
message templates, to specify the strictness of checks and to ignore common
exceptions.
### Error Configuration
If we would like to ignore `ExcessRaiseError`s (because we know that
an underlying function will raise an exception), then we would add its
error code to a file named *.darglint*:
```ini
[darglint]
ignore=DAR402
```
We can ignore multiple errors by using a comma-separated list:
```ini
[darglint]
ignore=DAR402,DAR103
```
Instead of specifying error codes to ignore in general one can also specify a
regex to exclude certain function names from tests. For example, the following
configuration would disable linting on all private methods.
```ini
[darglint]
ignore_regex=^_(.*)
```
### Message Template Configuration
If we would like to specify a message template, we may do so as
follows:
```ini
[darglint]
message_template={msg_id}@{path}:{line}
```
Which will produce a message such as `DAR102@driver.py:72`.
Finally, we can specify the docstring style type using `docstring_style`
("google" by default):
```ini
[darglint]
docstring_style=sphinx
```
### Strictness Configuration
Strictness determines how lax darglint will be when checking docstrings.
There are three levels of strictness available:
- short: One-line descriptions are acceptable; anything
more and the docstring will be fully checked.
- long: One-line descriptions and descriptions without
arguments/returns/yields/etc. sections will be allowed. Anything more,
and the docstring will be fully checked.
- full: (Default) Docstrings will be fully checked.
For example, if we have the following function:
```python
def double(x):
# <docstring>
return x * 2
```
Then the following table describes which errors will be raised for
each of the docstrings (rows) when checked against each of the
configurations (columns):
```
┌──────────────────────────────┬──────────────────┬────────────────┬──────────────────┐
│ Docstring │ short │ long │ full │
├──────────────────────────────┼──────────────────┼────────────────┼──────────────────┤
│ """Doubles the argument.""" │ None │ None │ Missing argument │
│ │ │ │ Missing return │
│ │ │ │ │
│ │ │ │ │
├──────────────────────────────┼──────────────────┼────────────────┼──────────────────┤
│ """Doubles the argument. │ Missing argument │ None │ Missing argument │
│ │ Missing return │ │ Missing return │
│ Not very pythonic. │ │ │ │
│ │ │ │ │
│ """ │ │ │ │
│ │ │ │ │
├──────────────────────────────┼──────────────────┼────────────────┼──────────────────┤
│ """Doubles the argument. │ Missing return │ Missing return │ Missing return │
│ │ │ │ │
│ Args: │ │ │ │
│ x: The number to double. │ │ │ │
│ │ │ │ │
│ """ │ │ │ │
└──────────────────────────────┴──────────────────┴────────────────┴──────────────────┘
```
In short, if you want to be able to have single-line docstrings, and check
all other docstrings against their described parameters, you would specify
```ini
[darglint]
strictness=short
```
In your configuration file.
### Ignoring common exceptions
We can specify a list of exceptions that don't need to be documented in the
raises section of a docstring. For example,
```ini
[darglint]
ignore_raise=ValueError,MyCustomError
```
### Logging
When *darglint* fails unexpectedly, you can try to gather more
information when submitting a bug by running with logging.
For example,
```bash
darglint --log-level=INFO unexpected_failures.py
```
*Darglint* accepts the levels, `DEBUG`, `INFO`, `WARNING`, `ERROR`, and
`CRITICAL`.
## Usage
### Command Line use
Given a python source file, `serializers.py`, you would check the docstrings
as follows:
```bash
darglint serializers.py
```
You can give an optional verbosity setting to *darglint*. For example,
```bash
darglint -v 2 *.py
```
Would give a description of the error along with information as to this
specific instance. The default verbosity is 1, which gives the filename,
function name, line number, error code, and some general hints.
To use an arbitrary error format, you can pass a message template, which
is a python format string. For example, if we pass the message
template
```bash
darglint -m "{path}:{line} -> {msg_id}" darglint/driver.py
```
Then we would get back error messages like
```bash
darglint/driver.py :61 -> DAR101
```
The following attributes can be passed to the format string:
- *line*: The line number,
- *msg*: The error message,
- *msg_id*: The error code,
- *obj*: The function/method name,
- *path*: The relative file path.
The message template can also be specified in the configuration file
as the value `message_template`.
*darglint* is particularly useful when combined with the utility, `find`.
This allows us to check all of the files in our project at once. For example,
when eating my own dogfood (as I tend to do), I invoke *darglint* as follows:
```bash
find . -name "*.py" | xargs darglint
```
Where I'm searching all files ending in ".py" recursively from the
current directory, and calling *darglint* on each one in turn.
### Ignoring Errors in a Docstring
You can ignore specific errors in a particular docstring. The syntax
is much like that of *pycodestyle*, etc. It generally takes the from
of:
```python
# noqa: <error> <argument>
```
Where `<error>` is the particular error to ignore (`DAR402`, or `DAR201`
for example), and `<argument>` is what (if anything) the ignore
statement refers to (if nothing, then it is not specified).
Let us say that we want to ignore a missing return statement
in the following docstring:
```python
def we_dont_want_a_returns_section():
"""Return the value, 3.
# noqa: DAR201
"""
return 3
```
We put the `noqa` anywhere in the top level of the docstring.
However, this won't work if we are missing something more specific,
like a parameter. We may not want to ignore all missing parameters,
either, just one particular one. For example, we may be writing a
function that takes a class instance as self. (Say, in a bound *celery*
task.) Then we would do something like:
```python
def a_bound_function(self, arg1):
"""Do something interesting.
Args:
arg1: The first argument.
# noqa: DAR101 arg1
"""
arg1.execute(self)
```
So, the argument comes to the right of the error.
We may also want to mark excess documentation as being okay. For example,
we may not want to explicitly catch and raise a `ZeroDivisionError`. We
could do the following:
```python
def always_raises_exception(x):
"""Raise a zero division error or type error.o
Args:
x: The argument which could be a number or could not be.
Raises:
ZeroDivisionError: If x is a number. # noqa: DAR402
TypeError: If x is not a number. # noqa: DAR402
"""
x / 0
```
So, in this case, the argument for `noqa` is really all the way to
the left. (Or whatever description we are parsing.) We could also
have put it on its own line, as `# noqa: DAR402 ZeroDivisionError`.
### Type Annotations
Darglint parses type annotations in docstrings, and can, optionally,
compare the documented type to the actual type annotation. This can
be useful when migrating a codebase to use type annotations.
In order to make these comparisons, Darglint only accepts types
accepted by Python (see [PEP 484](https://www.python.org/dev/peps/pep-0484/).)
That is, it does not accept parentheses in type signatures. (If
parentheses are used in the type signature, Darglint will mark that
argument as missing. See Issue #90.)
### Error Codes
- *DAR001*: The docstring was not parsed correctly due to a syntax error.
- *DAR002*: An argument/exception lacks a description
- *DAR003*: A line is under-indented or over-indented.
- *DAR004*: The docstring contains an extra newline where it shouldn't.
- *DAR005*: The item contains a type section (parentheses), but no type.
- *DAR101*: The docstring is missing a parameter in the definition.
- *DAR102*: The docstring contains a parameter not in function.
- *DAR103*: The docstring parameter type doesn't match function.
- *DAR104*: (disabled) The docstring parameter has no type specified
- *DAR105*: The docstring parameter type is malformed.
- *DAR201*: The docstring is missing a return from definition.
- *DAR202*: The docstring has a return not in definition.
- *DAR203*: The docstring parameter type doesn't match function.
- *DAR301*: The docstring is missing a yield present in definition.
- *DAR302*: The docstring has a yield not in definition.
- *DAR401*: The docstring is missing an exception raised.
- *DAR402*: The docstring describes an exception not explicitly raised.
- *DAR501*: The docstring describes a variable which is not defined.
The number in the hundreds narrows the error by location in the docstring:
- 000: Syntax, formatting, and style
- 100: Args section
- 200: Returns section
- 300: Yields section
- 400: Raises section
- 500: Variables section
You can enable disabled-by-default exceptions in the configuration file
using the `enable` option. It accepts a comma-separated list of error
codes.
```ini
[darglint]
enable=DAR104
```
## Scope
Darglint's primary focus is to identify incorrect and missing documentationd
of a function's signature. Checking style is a stretch goal, and is supported
on a best-effort basis. Darglint does not check stylistic preferences expressed
by tools in the Python Code Quality Authority (through tools such as `pydocstyle`).
So when using Darglint, it may be a good idea to also use `pydocstyle`, if you
want to enforce style. (For example, `pydocstyle` requires the short summary
to be separated from other sections by a line break. Darglint makes no such check.)
## Sphinx
Darglint can handle sphinx-style docstrings, but imposes some restrictions
on top of the Sphinx style. For example, all fields (such as `:returns:`)
must be the last items in the docstring. They must be together, and all
indents should be four spaces. These restrictions may be loosened at a
later date.
To analyze Sphinx-style docstrings, pass the style flag to the command:
```bash
darglint -s sphinx example.py
darglint --docstring-style sphinx example.py
```
Alternatively, you can specify the style in the configuration file using
the setting, "docstring\_style":
```ini
[darglint]
docstring_style=sphinx
```
## Numpy
Darglint now has an initial implementation for Numpy-style docstrings.
Similarly to Sphinx-style docstrings, you can pass a style flag to the
command:
```bash
darglint -s numpy example.py
darglint --docstring-style numpy example.py
```
Or set it in a configuration file:
```ini
[darglint]
docstring_style=numpy
```
The numpy parser and error reporter are not yet fully stabilized.
Add issues or suggestions to the tracking bug, Issue #69.
## Integrations
### Flake8
Darglint can be used in conjunction with Flake8 as a plugin. The only
setup necessary is to install Flake8 and Darglint in the same environment.
Darglint will pull its configuration from Flake8. So, if you would like to
lint Sphinx-style comments, then you should have `docstring_style=sphinx` in a
Flake8 configuration file in the project directory. The settings would
be entered under the flake8 configuration, not a separate configuration
for Darglint. E.g.:
```ini
[flake8]
strictness=short
docstring_style=sphinx
```
To see which options are exposed through Flake8, you can check the Flake8
tool:
```bash
flake8 --help | grep --before-context=2 Darglint
```
### SublimeLinter
A plugin for SublimeLinter can be found [here](https://github.com/raddessi/SublimeLinter-contrib-darglint)
### Pre-commit
Download [pre-commit](https://pre-commit.com/) and
[install](https://pre-commit.com/#install) it. Once it is installed, add this
to `.pre-commit-config.yaml` in your repository:
```yaml
repos:
- repo: https://github.com/terrencepreilly/darglint
rev: master
hooks:
- id: darglint
```
Then run `pre-commit install` and you're ready to go. Before commiting,
`darglint` will be run on the staged files. If it finds any errors, the user
is notified and the commit is aborted. Store necessary configuration (such as
error formatting) in `.darglint`, `setup.cfg` or `tox.ini`.
## Roadmap
Below are some of the current features or efforts. Where a milestone or
issue is associated with the idea, it will be mentioned. Some of these
ideas are moonshots and may not get implemented. They are ordered
roughly according to current priority/feasibility.
- [ ] Expose command-line options through sphinx.
- [ ] Robust logging for errors caused/encountered by *darglint*.
- [ ] Check class docstrings (See Issue #25).
- [ ] Autoformatting docstrings. (See Milestone #3).
- [ ] Optional aggressive style checking through command line flag.
- [ ] ALE support.
- [ ] Syntastic support. (Syntastic is not accepting new checkers until
their next API stabilizes, so this may take some time.)
## Development and Contributions
### Development Setup
Install `darglint`. First, clone the repository:
```bash
git clone https://github.com/terrencepreilly/darglint.git
```
`cd` into the directory, create a virtual environment (optional), then setup:
```bash
cd darglint/
virtualenv -p python3.6 .env
source .env/bin/activate
pip install -e .
```
You can install dependencies using
```bash
pip install poetry
poetry install
```
You can run the tests using
```bash
python setup.py test
```
Or, install `pytest` manually, `cd` to the project's root directory,
and run
```bash
pytest
```
This project tries to conform by the styles imposed by `pycodestyle`
and `pydocstyle`, as well as by `darglint` itself.
A dockerfile exists for testing with Python3.4. Although it's not
officially supported (only 3.6+), it's nice to try to make minor
version numbers support it. You would build the dockerfile and
test using something like
```bash
pushd docker-build
docker build -t darglint-34 -f Dockerfile.test34 .
popd
docker run -it --rm -v $(pwd):/code darglint-34 pytest
```
### Contribution
If you would like to tackle an issue or feature, email me or comment on the
issue to make sure it isn't already being worked on. Contributions will
be accepted through pull requests. New features should include unit tests,
and, of course, properly formatted documentation.
Also, check out the wiki prior to updating the grammar. It includes a
description of darglint's parsing pipline.
Raw data
{
"_id": null,
"home_page": "",
"name": "darglint",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6,<4.0",
"maintainer_email": "",
"keywords": "documentation,linter,development",
"author": "terrencepreilly",
"author_email": "terrencepreilly@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/d4/2c/86e8549e349388c18ca8a4ff8661bb5347da550f598656d32a98eaaf91cc/darglint-1.8.1.tar.gz",
"platform": "",
"description": "[![Build Status](https://travis-ci.com/terrencepreilly/darglint.svg?branch=develop)](https://travis-ci.com/terrencepreilly/darglint)\n\n# Darglint\n\nA functional docstring linter which checks whether a docstring's\ndescription matches the actual function/method implementation.\n*Darglint* expects docstrings to be formatted using the\n[Google Python Style Guide](https://google.github.io/styleguide/pyguide.html),\nor [Sphinx Style Guide](https://pythonhosted.org/an_example_pypi_project/sphinx.html#function-definitions),\nor [Numpy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html).\n\nFeel free to submit an issue/pull request if you spot a problem or\nwould like a feature in *darglint*.\n\n**Table of Contents**:\n\n- [Project Status](#project-status)\n- [Installation](#installation)\n- [Configuration](#configuration)\n- [Usage](#usage)\n- [Scope](#scope)\n- [Sphinx](#sphinx)\n- [Numpy](#numpy)\n- [Integrations](#integrations)\n- [Flake8](#flake8)\n- [Roadmap](#roadmap)\n- [Contribution](#development-and-contributions)\n\n\n## Project Status\n\nI no longer work with Python regularly, and I'd like to spend some more\ntime on other projects. So while I'll continue to maintain darglint,\nI likely won't be adding significant new features. That said, I will\ntry to accept pull requests. See the contribution section for more\ninformation. Consider it in maintenance mode.\n\n\n## Installation\n\nTo install *darglint*, use pip.\n\n```bash\npip install darglint\n```\n\nOr, clone the repository, `cd` to the directory, and\n\n```bash\npip install .\n```\n\n## Configuration\n\n*darglint* can be configured using a configuration file. The configuration\nfile must be named either *.darglint*, *setup.cfg*, or *tox.ini*. It must\nalso have a section starting with the section header, `[darglint]`.\nFinally, the configuration file must be located either in the directory\n*darglint* is called from, or from a parent directory of that working\ndirectory.\n\nCurrently, the configuration file allows us to ignore errors, to specify\nmessage templates, to specify the strictness of checks and to ignore common\nexceptions.\n\n### Error Configuration\n\nIf we would like to ignore `ExcessRaiseError`s (because we know that\nan underlying function will raise an exception), then we would add its\nerror code to a file named *.darglint*:\n\n```ini\n[darglint]\nignore=DAR402\n```\n\nWe can ignore multiple errors by using a comma-separated list:\n\n```ini\n[darglint]\nignore=DAR402,DAR103\n```\n\nInstead of specifying error codes to ignore in general one can also specify a\nregex to exclude certain function names from tests. For example, the following \nconfiguration would disable linting on all private methods.\n```ini\n[darglint]\nignore_regex=^_(.*)\n```\n\n### Message Template Configuration\n\nIf we would like to specify a message template, we may do so as\nfollows:\n\n```ini\n[darglint]\nmessage_template={msg_id}@{path}:{line}\n```\n\nWhich will produce a message such as `DAR102@driver.py:72`.\n\nFinally, we can specify the docstring style type using `docstring_style`\n(\"google\" by default):\n\n```ini\n[darglint]\ndocstring_style=sphinx\n```\n\n### Strictness Configuration\n\nStrictness determines how lax darglint will be when checking docstrings.\nThere are three levels of strictness available:\n\n- short: One-line descriptions are acceptable; anything\nmore and the docstring will be fully checked.\n\n- long: One-line descriptions and descriptions without\narguments/returns/yields/etc. sections will be allowed. Anything more,\nand the docstring will be fully checked.\n\n- full: (Default) Docstrings will be fully checked.\n\nFor example, if we have the following function:\n\n```python\ndef double(x):\n # <docstring>\n return x * 2\n```\n\nThen the following table describes which errors will be raised for\neach of the docstrings (rows) when checked against each of the\nconfigurations (columns):\n\n```\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502 Docstring \u2502 short \u2502 long \u2502 full \u2502\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502 \"\"\"Doubles the argument.\"\"\" \u2502 None \u2502 None \u2502 Missing argument \u2502\n\u2502 \u2502 \u2502 \u2502 Missing return \u2502\n\u2502 \u2502 \u2502 \u2502 \u2502\n\u2502 \u2502 \u2502 \u2502 \u2502\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502 \"\"\"Doubles the argument. \u2502 Missing argument \u2502 None \u2502 Missing argument \u2502\n\u2502 \u2502 Missing return \u2502 \u2502 Missing return \u2502\n\u2502 Not very pythonic. \u2502 \u2502 \u2502 \u2502\n\u2502 \u2502 \u2502 \u2502 \u2502\n\u2502 \"\"\" \u2502 \u2502 \u2502 \u2502\n\u2502 \u2502 \u2502 \u2502 \u2502\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502 \"\"\"Doubles the argument. \u2502 Missing return \u2502 Missing return \u2502 Missing return \u2502\n\u2502 \u2502 \u2502 \u2502 \u2502\n\u2502 Args: \u2502 \u2502 \u2502 \u2502\n\u2502 x: The number to double. \u2502 \u2502 \u2502 \u2502\n\u2502 \u2502 \u2502 \u2502 \u2502\n\u2502 \"\"\" \u2502 \u2502 \u2502 \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n```\n\nIn short, if you want to be able to have single-line docstrings, and check\nall other docstrings against their described parameters, you would specify\n\n```ini\n[darglint]\nstrictness=short\n```\n\nIn your configuration file.\n\n### Ignoring common exceptions\n\nWe can specify a list of exceptions that don't need to be documented in the\nraises section of a docstring. For example,\n\n```ini\n[darglint]\nignore_raise=ValueError,MyCustomError\n```\n\n### Logging\n\nWhen *darglint* fails unexpectedly, you can try to gather more\ninformation when submitting a bug by running with logging.\nFor example,\n\n```bash\ndarglint --log-level=INFO unexpected_failures.py\n```\n\n*Darglint* accepts the levels, `DEBUG`, `INFO`, `WARNING`, `ERROR`, and\n`CRITICAL`.\n\n\n## Usage\n\n\n### Command Line use\n\nGiven a python source file, `serializers.py`, you would check the docstrings\nas follows:\n\n```bash\ndarglint serializers.py\n```\n\nYou can give an optional verbosity setting to *darglint*. For example,\n\n```bash\ndarglint -v 2 *.py\n```\n\nWould give a description of the error along with information as to this\nspecific instance. The default verbosity is 1, which gives the filename,\nfunction name, line number, error code, and some general hints.\n\nTo use an arbitrary error format, you can pass a message template, which\nis a python format string. For example, if we pass the message\ntemplate\n\n```bash\ndarglint -m \"{path}:{line} -> {msg_id}\" darglint/driver.py\n```\n\nThen we would get back error messages like\n\n```bash\ndarglint/driver.py :61 -> DAR101\n```\n\nThe following attributes can be passed to the format string:\n- *line*: The line number,\n- *msg*: The error message,\n- *msg_id*: The error code,\n- *obj*: The function/method name,\n- *path*: The relative file path.\n\nThe message template can also be specified in the configuration file\nas the value `message_template`.\n\n*darglint* is particularly useful when combined with the utility, `find`.\nThis allows us to check all of the files in our project at once. For example,\nwhen eating my own dogfood (as I tend to do), I invoke *darglint* as follows:\n\n```bash\nfind . -name \"*.py\" | xargs darglint\n```\n\nWhere I'm searching all files ending in \".py\" recursively from the\ncurrent directory, and calling *darglint* on each one in turn.\n\n### Ignoring Errors in a Docstring\n\nYou can ignore specific errors in a particular docstring. The syntax\nis much like that of *pycodestyle*, etc. It generally takes the from\nof:\n\n```python\n# noqa: <error> <argument>\n```\n\nWhere `<error>` is the particular error to ignore (`DAR402`, or `DAR201`\nfor example), and `<argument>` is what (if anything) the ignore\nstatement refers to (if nothing, then it is not specified).\n\nLet us say that we want to ignore a missing return statement\nin the following docstring:\n\n```python\ndef we_dont_want_a_returns_section():\n \"\"\"Return the value, 3.\n\n # noqa: DAR201\n\n \"\"\"\n return 3\n```\n\nWe put the `noqa` anywhere in the top level of the docstring.\nHowever, this won't work if we are missing something more specific,\nlike a parameter. We may not want to ignore all missing parameters,\neither, just one particular one. For example, we may be writing a\nfunction that takes a class instance as self. (Say, in a bound *celery*\ntask.) Then we would do something like:\n\n```python\ndef a_bound_function(self, arg1):\n \"\"\"Do something interesting.\n\n Args:\n arg1: The first argument.\n\n # noqa: DAR101 arg1\n\n \"\"\"\n arg1.execute(self)\n```\n\nSo, the argument comes to the right of the error.\n\nWe may also want to mark excess documentation as being okay. For example,\nwe may not want to explicitly catch and raise a `ZeroDivisionError`. We\ncould do the following:\n\n```python\ndef always_raises_exception(x):\n \"\"\"Raise a zero division error or type error.o\n\n Args:\n x: The argument which could be a number or could not be.\n\n Raises:\n ZeroDivisionError: If x is a number. # noqa: DAR402\n TypeError: If x is not a number. # noqa: DAR402\n\n \"\"\"\n x / 0\n```\n\nSo, in this case, the argument for `noqa` is really all the way to\nthe left. (Or whatever description we are parsing.) We could also\nhave put it on its own line, as `# noqa: DAR402 ZeroDivisionError`.\n\n### Type Annotations\n\nDarglint parses type annotations in docstrings, and can, optionally,\ncompare the documented type to the actual type annotation. This can\nbe useful when migrating a codebase to use type annotations.\n\nIn order to make these comparisons, Darglint only accepts types\naccepted by Python (see [PEP 484](https://www.python.org/dev/peps/pep-0484/).)\nThat is, it does not accept parentheses in type signatures. (If\nparentheses are used in the type signature, Darglint will mark that\nargument as missing. See Issue #90.)\n\n\n### Error Codes\n\n- *DAR001*: The docstring was not parsed correctly due to a syntax error.\n- *DAR002*: An argument/exception lacks a description\n- *DAR003*: A line is under-indented or over-indented.\n- *DAR004*: The docstring contains an extra newline where it shouldn't.\n- *DAR005*: The item contains a type section (parentheses), but no type.\n- *DAR101*: The docstring is missing a parameter in the definition.\n- *DAR102*: The docstring contains a parameter not in function.\n- *DAR103*: The docstring parameter type doesn't match function.\n- *DAR104*: (disabled) The docstring parameter has no type specified \n- *DAR105*: The docstring parameter type is malformed.\n- *DAR201*: The docstring is missing a return from definition.\n- *DAR202*: The docstring has a return not in definition.\n- *DAR203*: The docstring parameter type doesn't match function.\n- *DAR301*: The docstring is missing a yield present in definition.\n- *DAR302*: The docstring has a yield not in definition.\n- *DAR401*: The docstring is missing an exception raised.\n- *DAR402*: The docstring describes an exception not explicitly raised.\n- *DAR501*: The docstring describes a variable which is not defined.\n\nThe number in the hundreds narrows the error by location in the docstring:\n\n- 000: Syntax, formatting, and style\n- 100: Args section\n- 200: Returns section\n- 300: Yields section\n- 400: Raises section\n- 500: Variables section\n\nYou can enable disabled-by-default exceptions in the configuration file\nusing the `enable` option. It accepts a comma-separated list of error\ncodes.\n\n```ini\n[darglint]\nenable=DAR104\n```\n\n## Scope\n\nDarglint's primary focus is to identify incorrect and missing documentationd\nof a function's signature. Checking style is a stretch goal, and is supported\non a best-effort basis. Darglint does not check stylistic preferences expressed\nby tools in the Python Code Quality Authority (through tools such as `pydocstyle`).\nSo when using Darglint, it may be a good idea to also use `pydocstyle`, if you\nwant to enforce style. (For example, `pydocstyle` requires the short summary\nto be separated from other sections by a line break. Darglint makes no such check.)\n\n## Sphinx\n\nDarglint can handle sphinx-style docstrings, but imposes some restrictions\non top of the Sphinx style. For example, all fields (such as `:returns:`)\nmust be the last items in the docstring. They must be together, and all\nindents should be four spaces. These restrictions may be loosened at a\nlater date.\n\nTo analyze Sphinx-style docstrings, pass the style flag to the command:\n\n```bash\ndarglint -s sphinx example.py\ndarglint --docstring-style sphinx example.py\n```\n\nAlternatively, you can specify the style in the configuration file using\nthe setting, \"docstring\\_style\":\n\n```ini\n[darglint]\ndocstring_style=sphinx\n```\n\n## Numpy\n\nDarglint now has an initial implementation for Numpy-style docstrings.\nSimilarly to Sphinx-style docstrings, you can pass a style flag to the\ncommand:\n\n```bash\ndarglint -s numpy example.py\ndarglint --docstring-style numpy example.py\n```\n\nOr set it in a configuration file:\n\n```ini\n[darglint]\ndocstring_style=numpy\n```\n\nThe numpy parser and error reporter are not yet fully stabilized.\nAdd issues or suggestions to the tracking bug, Issue #69.\n\n## Integrations\n\n### Flake8\n\nDarglint can be used in conjunction with Flake8 as a plugin. The only\nsetup necessary is to install Flake8 and Darglint in the same environment.\nDarglint will pull its configuration from Flake8. So, if you would like to\nlint Sphinx-style comments, then you should have `docstring_style=sphinx` in a\nFlake8 configuration file in the project directory. The settings would\nbe entered under the flake8 configuration, not a separate configuration\nfor Darglint. E.g.:\n\n```ini\n[flake8]\nstrictness=short\ndocstring_style=sphinx\n```\n\nTo see which options are exposed through Flake8, you can check the Flake8\ntool:\n\n```bash\nflake8 --help | grep --before-context=2 Darglint\n```\n\n### SublimeLinter\n\nA plugin for SublimeLinter can be found [here](https://github.com/raddessi/SublimeLinter-contrib-darglint)\n\n### Pre-commit\n\nDownload [pre-commit](https://pre-commit.com/) and\n[install](https://pre-commit.com/#install) it. Once it is installed, add this\nto `.pre-commit-config.yaml` in your repository:\n\n```yaml\nrepos:\n- repo: https://github.com/terrencepreilly/darglint\n rev: master\n hooks:\n - id: darglint\n```\n\nThen run `pre-commit install` and you're ready to go. Before commiting,\n`darglint` will be run on the staged files. If it finds any errors, the user\nis notified and the commit is aborted. Store necessary configuration (such as\nerror formatting) in `.darglint`, `setup.cfg` or `tox.ini`.\n\n\n## Roadmap\n\nBelow are some of the current features or efforts. Where a milestone or\nissue is associated with the idea, it will be mentioned. Some of these\nideas are moonshots and may not get implemented. They are ordered\nroughly according to current priority/feasibility.\n\n- [ ] Expose command-line options through sphinx.\n- [ ] Robust logging for errors caused/encountered by *darglint*.\n- [ ] Check class docstrings (See Issue #25).\n- [ ] Autoformatting docstrings. (See Milestone #3).\n- [ ] Optional aggressive style checking through command line flag.\n- [ ] ALE support.\n- [ ] Syntastic support. (Syntastic is not accepting new checkers until\ntheir next API stabilizes, so this may take some time.)\n\n\n## Development and Contributions\n\n### Development Setup\n\nInstall `darglint`. First, clone the repository:\n\n```bash\ngit clone https://github.com/terrencepreilly/darglint.git\n```\n\n`cd` into the directory, create a virtual environment (optional), then setup:\n\n```bash\ncd darglint/\nvirtualenv -p python3.6 .env\nsource .env/bin/activate\npip install -e .\n```\n\nYou can install dependencies using\n\n```bash\npip install poetry\npoetry install\n```\n\nYou can run the tests using\n\n```bash\npython setup.py test\n```\n\nOr, install `pytest` manually, `cd` to the project's root directory,\nand run\n\n```bash\npytest\n```\n\nThis project tries to conform by the styles imposed by `pycodestyle`\nand `pydocstyle`, as well as by `darglint` itself.\n\n\nA dockerfile exists for testing with Python3.4. Although it's not\nofficially supported (only 3.6+), it's nice to try to make minor\nversion numbers support it. You would build the dockerfile and\ntest using something like\n\n```bash\npushd docker-build\ndocker build -t darglint-34 -f Dockerfile.test34 .\npopd\ndocker run -it --rm -v $(pwd):/code darglint-34 pytest\n```\n\n### Contribution\n\nIf you would like to tackle an issue or feature, email me or comment on the\nissue to make sure it isn't already being worked on. Contributions will\nbe accepted through pull requests. New features should include unit tests,\nand, of course, properly formatted documentation.\n\nAlso, check out the wiki prior to updating the grammar. It includes a\ndescription of darglint's parsing pipline.\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A utility for ensuring Google-style docstrings stay up to date with the source code.",
"version": "1.8.1",
"split_keywords": [
"documentation",
"linter",
"development"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "8ed8c9bdab56d3f36b2b6d4f1ac2a101",
"sha256": "5ae11c259c17b0701618a20c3da343a3eb98b3bc4b5a83d31cdd94f5ebdced8d"
},
"downloads": -1,
"filename": "darglint-1.8.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8ed8c9bdab56d3f36b2b6d4f1ac2a101",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6,<4.0",
"size": 120767,
"upload_time": "2021-10-18T03:40:35",
"upload_time_iso_8601": "2021-10-18T03:40:35.034675Z",
"url": "https://files.pythonhosted.org/packages/69/28/85d1e0396d64422c5218d68e5cdcc53153aa8a2c83c7dbc3ee1502adf3a1/darglint-1.8.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "584ad85a8b6afd97fa60203f7aadc5e5",
"sha256": "080d5106df149b199822e7ee7deb9c012b49891538f14a11be681044f0bb20da"
},
"downloads": -1,
"filename": "darglint-1.8.1.tar.gz",
"has_sig": false,
"md5_digest": "584ad85a8b6afd97fa60203f7aadc5e5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6,<4.0",
"size": 74435,
"upload_time": "2021-10-18T03:40:37",
"upload_time_iso_8601": "2021-10-18T03:40:37.283691Z",
"url": "https://files.pythonhosted.org/packages/d4/2c/86e8549e349388c18ca8a4ff8661bb5347da550f598656d32a98eaaf91cc/darglint-1.8.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2021-10-18 03:40:37",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "darglint"
}