Skip to content

Commit

Permalink
Adds configuration docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Aug 28, 2018
1 parent 393c3c3 commit 0709ce5
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 100 deletions.
49 changes: 8 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# wemake-python-styleguide

[![wemake.services](https://img.shields.io/badge/-wemake.services-green.svg?label=&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC%2FxhBQAAAAFzUkdCAK7OHOkAAAAbUExURQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP%2F%2F%2F5TvxDIAAAAIdFJOUwAjRA8xXANAL%2Bv0SAAAADNJREFUGNNjYCAIOJjRBdBFWMkVQeGzcHAwksJnAPPZGOGAASzPzAEHEGVsLExQwE7YswCb7AFZSF3bbAAAAABJRU5ErkJggg%3D%3D)](https://wemake.services)
[![wemake.services](https://img.shields.io/badge/-wemake.services-green.svg?label=%20&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC%2FxhBQAAAAFzUkdCAK7OHOkAAAAbUExURQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP%2F%2F%2F5TvxDIAAAAIdFJOUwAjRA8xXANAL%2Bv0SAAAADNJREFUGNNjYCAIOJjRBdBFWMkVQeGzcHAwksJnAPPZGOGAASzPzAEHEGVsLExQwE7YswCb7AFZSF3bbAAAAABJRU5ErkJggg%3D%3D)](https://wemake.services)
[![Build Status](https://travis-ci.org/wemake-services/wemake-python-styleguide.svg?branch=master)](https://travis-ci.org/wemake-services/wemake-python-styleguide)
[![Coverage](https://coveralls.io/repos/github/wemake-services/wemake-python-styleguide/badge.svg?branch=master)](https://coveralls.io/github/wemake-services/wemake-python-styleguide?branch=master)
[![PyPI version](https://badge.fury.io/py/wemake-python-styleguide.svg)](https://badge.fury.io/py/wemake-python-styleguide)
[![Documentation Status](https://readthedocs.org/projects/wemake-python-styleguide/badge/?version=latest)](https://wemake-python-styleguide.readthedocs.io/en/latest/?badge=latest)
[![Dependencies Status](https://img.shields.io/badge/dependencies-up%20to%20date-brightgreen.svg)](https://github.com/wemake-services/wemake-python-styleguide/pulls?utf8=%E2%9C%93&q=is%3Apr%20author%3Aapp%2Fdependabot)


Welcome to the most opinionated linter ever.
Expand All @@ -21,49 +22,15 @@ pip install wemake-python-styleguide

## Project status

We are in early alpha.
Use it on your own risk.
We are in early alpha. Use it on your own risk.


## Running tests
## Contributing

Clone the repository, install `poetry`, then do from within the project folder:
See [`CONTRIBUTING.md`](/CONTRIBUTING.md) file if you want to contribute.
You can also check which [issues need some help](https://github.com/wemake-services/wemake-python-styleguide/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) right now.

```bash
# Installing dependencies (only required to be run once):
poetry install
poetry develop

# Running tests:
poetry run pytest
poetry run mypy wemake_python_styleguide
poetry run doc8 -q docs
```

It's OK if some tests are skipped.


## Configuration

You can adjust configuration via CLI option:

```sh
flake8 --max-returns 7
```

or configuration option in `tox.ini`/`setup.cfg`.

```ini
max-returns = 7
```

There are the following options:

- `max-returns` - maximum allowed number of `return` statements in one function. Default value is 6.

- `max-local-variables` - maximum allowed number of local variables in one function. Default is 10.

- `max-expressions` - maximum allowed number of expressions in one function. Default value is 10.

- `max-arguments` - maximum allowed number of arguments in one function. Default value is 5.
## License

MIT. See [LICENSE.md](/LICENSE.md) for more details.
11 changes: 11 additions & 0 deletions docs/_pages/options/config.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Config
------

.. automodule:: wemake_python_styleguide.options.config
:members:

Defaults
~~~~~~~~

.. automodule:: wemake_python_styleguide.options.defaults
:members:
5 changes: 0 additions & 5 deletions docs/_pages/options/defaults.rst

This file was deleted.

2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ API Reference
_pages/checker.rst
_pages/errors.rst
_pages/constants.rst
_pages/options/defaults.rst
_pages/options/config.rst


Indices and tables
Expand Down
70 changes: 20 additions & 50 deletions tests/test_checkers/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,28 @@

import subprocess


def test_max_variables_cli_option(absolute_path):
"""Test to check max-local-variables cli option."""
filename = absolute_path('fixtures', 'complexity', 'wrong_variables.py')
option_flag = '--max-local-variables'
option_value = '100'
process = subprocess.Popen(
['flake8', filename, option_flag, option_value],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, _ = process.communicate()
assert stdout.count(b'Z150') == 0


def test_max_arguments_cli_option(absolute_path):
"""Test to check max-arguments cli option."""
filename = absolute_path('fixtures', 'complexity', 'wrong_arguments.py')
option_flag = '--max-arguments'
option_value = '100'
process = subprocess.Popen(
['flake8', filename, option_flag, option_value],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, _ = process.communicate()
assert stdout.count(b'Z151') == 0


def test_max_returns_cli_option(absolute_path):
"""Test to check max-returns cli option."""
filename = absolute_path('fixtures', 'complexity', 'wrong_returns.py')
option_flag = '--max-returns'
option_value = '100'
process = subprocess.Popen(
['flake8', filename, option_flag, option_value],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, _ = process.communicate()
assert stdout.count(b'Z153') == 0


def test_max_expressions_cli_options(absolute_path):
"""Test to check max-expressions cli option."""
filename = absolute_path('fixtures', 'complexity', 'wrong_expressions.py')
option_flag = '--max-expressions'
option_value = '100'
import pytest


@pytest.mark.parametrize('filename, option_flag, option_value, error_code', [
('wrong_variables.py', '--max-local-variables', '100', b'Z150'),
('wrong_arguments.py', '--max-arguments', '100', b'Z151'),
('wrong_returns.py', '--max-returns', '100', b'153'),
('wrong_expressions.py', '--max-expressions', '100', b'154'),
])
def test_max_variables_cli_option(
absolute_path,
filename,
option_flag,
option_value,
error_code,
):
"""Test to check that cli options work."""
fixture = absolute_path('fixtures', 'complexity', filename)
process = subprocess.Popen(
['flake8', filename, option_flag, option_value],
['flake8', fixture, option_flag, option_value],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, _ = process.communicate()
assert stdout.count(b'Z154') == 0
assert stdout.count(error_code) == 0
2 changes: 1 addition & 1 deletion wemake_python_styleguide/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Checker(object):
Main checker class.
Runs all checks that are bundled with this package.
If you want to add new checks they should be added to `ENABLED_VISITORS`.
If you want to add new checks they should be added to ``ENABLED_VISITORS``.
"""

name = 'wemake-python-styleguide'
Expand Down
31 changes: 29 additions & 2 deletions wemake_python_styleguide/options/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,37 @@


class Configuration(object):
"""Provides method for registering options for `Z` flake8 plugin."""
"""
Provides configuration options for `wemake-python-styleguide` plugin.
You can adjust configuration via CLI option:
Example::
flake8 --max-returns 7
You can also provide configuration options in `tox.ini` or `setup.cfg`:
Example::
[flake8]
max-returns = 7
We support the following options:
- `max-returns` - maximum allowed number of `return` statements in one function,
defaults to ``MAX_RETURNS``
- `max-local-variables` - maximum allowed number of local variables in one function,
defaults to ``MAX_LOCAL_VARIABLES``
- `max-expressions` - maximum allowed number of expressions in one function,
defaults to ``MAX_EXPRESSIONS``
- `max-arguments` - maximum allowed number of arguments in one function,
defaults to ``MAX_ARGUMENTS``
"""

def register_options(self, parser) -> None: # TODO: types
"""Registers options for Z plugin."""
"""Registers options for our plugin."""
parser.add_option(
'--max-returns',
parse_from_config=True,
Expand Down

0 comments on commit 0709ce5

Please sign in to comment.