Skip to content

Commit

Permalink
Adds layer-linter, closes #452
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Jan 19, 2019
1 parent e4d2659 commit 14243b6
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 27 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ install:
script:
- poetry run flake8 wemake_python_styleguide tests docs
- poetry run mypy wemake_python_styleguide
- poetry run layer-lint --quiet wemake_python_styleguide
- poetry run pytest
- poetry run doc8 -q docs
- poetry check
Expand Down
11 changes: 3 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,15 @@ We used to have incremental versioning before `0.1.0`.
- Improves docs: we have added a special graph to show our architecure
- Improves docs: we now have a clean page for `checker` without extra junk
- Improves docs: we now have a tutorial for creating new rules


## Version 0.6.2

### Bugfixes

- Fixes a [crash](https://github.com/wemake-services/wemake-python-styleguide/issues/423) with class attributes assignment
- Refactoring: moves `presets` package to the root
- Improves tests: we now lint our layered architecure with `layer-lint`


## Version 0.6.3

### Bugfixes

- Fixes a [crash](https://github.com/wemake-services/wemake-python-styleguide/issues/450) with `dict`s with just values and no keys
- Fixes an [issue-450](https://github.com/wemake-services/wemake-python-styleguide/issues/450) with `dict`s with just values and no keys


## Version 0.6.2
Expand Down
16 changes: 15 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ flake8 wemake_python_styleguide tests docs
These steps are mandatory during the CI.


## Architecture

We use [`layer-lint`](https://layer-linter.readthedocs.io/en/latest/usage.html)
to enforce strict layered architecture.

```bash
layer-lint wemake_python_styleguide
```

All contracts must be valid for each commit.
This step is mandatory during the CI.


## Type checks

We use `mypy` to run type checks on our code.
Expand Down Expand Up @@ -122,7 +135,8 @@ Before submitting your code please do the following steps:
7. Run `pytest` again to make sure it is still working
8. Run `mypy` to ensure that types are correct
9. Run `flake8` to ensure that style is correct
10. Run `doc8` to ensure that docs are correct
10. Run `layer-lint` to ensure that architecture contracts are correct
11. Run `doc8` to ensure that docs are correct


## Other help
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ build: off
test_script:
- "poetry run flake8 wemake_python_styleguide tests docs"
- "poetry run mypy wemake_python_styleguide"
- "poetry run layer-lint --quiet wemake_python_styleguide"
- "poetry run pytest"
- "poetry run doc8 -q docs"
- "poetry check"
Expand Down
7 changes: 6 additions & 1 deletion docs/pages/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ our linter. This is a very simplified architecture that will help you
to understand how all components are bound together.

.. mermaid::
:caption: Architecture overview
:caption: Architecture overview.

sequenceDiagram
participant flake8
Expand All @@ -65,6 +65,11 @@ to understand how all components are bound together.
Visitor->>Violation: Visitors raise violations when they find bad code
Violation-->>flake8: Raised violations are shown to user by flake8

We use a layered architecture that follows this contract:

.. literalinclude :: ../../layers.yml
:language: yaml
Contributing
------------

Expand Down
10 changes: 10 additions & 0 deletions layers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Linting process:
containers:
- wemake_python_styleguide
layers:
- checker
- transformations
- presets
- visitors
- violations
- logics
49 changes: 42 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ added-value = "^0.14"
tomlkit = "^0.5"
safety = "^1.8"
sphinxcontrib-mermaid = "^0.3"
layer-linter = "^0.12.0"
2 changes: 1 addition & 1 deletion tests/test_checker/test_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _import_module_by_path(path: str):


def _visitors_paths():
base_path = Path('wemake_python_styleguide', 'visitors')
base_path = Path('wemake_python_styleguide')
excluded_paths = list(Path(base_path, 'presets').glob('**/*.py'))
return [
path for path in
Expand Down
4 changes: 2 additions & 2 deletions wemake_python_styleguide/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
from wemake_python_styleguide.options.config import Configuration
from wemake_python_styleguide.transformations.ast_tree import transform
from wemake_python_styleguide.visitors import base
from wemake_python_styleguide.visitors.presets import (
from wemake_python_styleguide.presets import (
complexity,
general,
tokens,
)
from wemake_python_styleguide.presets import tokens

VisitorClass = Type[base.BaseVisitor]

Expand Down
3 changes: 3 additions & 0 deletions wemake_python_styleguide/presets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

"""See :term:`preset` in the docs."""
File renamed without changes.
File renamed without changes.
8 changes: 2 additions & 6 deletions wemake_python_styleguide/visitors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,13 @@

import ast
import tokenize
from typing import TYPE_CHECKING, List, Sequence, Type
from typing import List, Sequence, Type

from wemake_python_styleguide import constants
from wemake_python_styleguide.logics.filenames import get_stem
from wemake_python_styleguide.types import ConfigurationOptions, final
from wemake_python_styleguide.violations.base import BaseViolation

if TYPE_CHECKING: # pragma: no cover
# Hack to remove circular imports:
from wemake_python_styleguide.checker import Checker # noqa: Z435


class BaseVisitor(object):
"""
Expand All @@ -101,7 +97,7 @@ def __init__(
@classmethod
def from_checker(
cls: Type['BaseVisitor'],
checker: 'Checker',
checker,
) -> 'BaseVisitor':
"""
Constructs visitor instance from the checker.
Expand Down
1 change: 0 additions & 1 deletion wemake_python_styleguide/visitors/presets/__init__.py

This file was deleted.

0 comments on commit 14243b6

Please sign in to comment.