Skip to content

Commit

Permalink
Merge pull request #42 from feldlime/feature/improve_linters
Browse files Browse the repository at this point in the history
Feature/improve linters
  • Loading branch information
feldlime authored Nov 7, 2023
2 parents 4deb180 + fc504a1 commit d677ebb
Show file tree
Hide file tree
Showing 14 changed files with 1,094 additions and 652 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/cicd.yml

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Test
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize]


jobs:
test:
runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v2

- name: "Setup python"
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install

- name: Run tests
run: make lint

- name: Run linters
run: make test
135 changes: 24 additions & 111 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# A comma-separated list of package or module names from where C extensions
# may be loaded. Extensions are loading into the active Python interpreter
# and may run arbitrary code.
extension-pkg-whitelist=orjson,
extension-pkg-whitelist=orjson

# Add files or directories to the blacklist.
# They should be base names, not paths.
Expand Down Expand Up @@ -53,103 +53,25 @@ unsafe-load-any-extension=no
confidence=

# Disable the message, report, category or checker with the given id(s).
disable=print-statement,
parameter-unpacking,
unpacking-in-except,
old-raise-syntax,
backtick,
long-suffix,
old-ne-operator,
old-octal-literal,
import-star-module-level,
non-ascii-bytes-literal,
raw-checker-failed,
disable=arguments-differ,
bad-inline-option,
locally-disabled,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead,
apply-builtin,
basestring-builtin,
buffer-builtin,
cmp-builtin,
coerce-builtin,
execfile-builtin,
file-builtin,
long-builtin,
raw_input-builtin,
reduce-builtin,
standarderror-builtin,
unicode-builtin,
xrange-builtin,
coerce-method,
delslice-method,
getslice-method,
setslice-method,
no-absolute-import,
old-division,
dict-iter-method,
dict-view-method,
next-method-called,
metaclass-assignment,
indexing-exception,
raising-string,
reload-builtin,
oct-method,
hex-method,
nonzero-method,
cmp-method,
input-builtin,
round-builtin,
intern-builtin,
unichr-builtin,
map-builtin-not-iterating,
zip-builtin-not-iterating,
range-builtin-not-iterating,
filter-builtin-not-iterating,
using-cmp-argument,
eq-without-hash,
div-method,
idiv-method,
rdiv-method,
exception-message-attribute,
invalid-str-codec,
sys-max-int,
bad-python3-import,
deprecated-string-function,
deprecated-str-translate-call,
deprecated-itertools-function,
deprecated-types-field,
next-method-defined,
dict-items-not-iterating,
dict-keys-not-iterating,
dict-values-not-iterating,
deprecated-operator-function,
deprecated-urllib-function,
xreadlines-attribute,
deprecated-sys-function,
exception-escape,
comprehension-escape,
missing-module-docstring,
missing-function-docstring,
missing-class-docstring,
invalid-name,
duplicate-code,
file-ignored,
invalid-envvar-default,
unused-argument,
no-self-use,
arguments-differ,
no-member,
too-many-ancestors,
invalid-name,
locally-disabled,
logging-fstring-interpolation,
too-many-locals,
missing-class-docstring,
missing-function-docstring,
missing-module-docstring,
no-member,
raise-missing-from,
consider-using-with,
no-name-in-module,
duplicate-code,


raw-checker-failed,
suppressed-message,
unused-argument,
use-implicit-booleaness-not-comparison,
use-symbolic-message-instead,

# Enable the message, report, category or checker with the given id(s).
# You can either give multiple identifier separated by comma (,) or
Expand Down Expand Up @@ -216,10 +138,6 @@ max-line-length=120
# Maximum number of lines in a module.
max-module-lines=1000

# List of optional constructs for which whitespace checking is disabled.
no-space-check=trailing-comma,
dict-separator

# Allow the body of a class to be on the same line as the declaration
# if body contains single statement.
single-line-class-stmt=no
Expand Down Expand Up @@ -312,9 +230,6 @@ method-naming-style=snake_case
# Overrides method-naming-style.
# method-rgx=

# Naming hint for argument names.
argument-name-hint=[a-z_][a-z0-9_]{2,15}$

# Naming style matching correct module names.
module-naming-style=snake_case

Expand All @@ -338,8 +253,6 @@ property-classes=abc.abstractproperty
# Naming style matching correct variable names.
variable-naming-style=snake_case

# Naming hint for variable names.
variable-name-hint=[a-z_][a-z0-9_]{2,15}$

# Regular expression matching correct variable names.
# Overrides variable-naming-style.
Expand Down Expand Up @@ -483,7 +396,7 @@ ignore-comments=yes
ignore-docstrings=yes

# Ignore imports when computing similarities.
ignore-imports=yes
ignore-imports=no

# Minimum lines number of a similarity.
min-similarity-lines=4
Expand Down Expand Up @@ -526,25 +439,25 @@ valid-metaclass-classmethod-first-arg=cls
[DESIGN]

# Maximum number of arguments for function / method.
max-args=11
max-args=15

# Maximum number of attributes for a class (see R0902).
max-attributes=7
max-attributes=12

# Maximum number of boolean expressions in an if statement (see R0916).
max-bool-expr=4
max-bool-expr=2

# Maximum number of branch for function / method body.
max-branches=8
max-branches=9

# Maximum number of locals for function / method body.
max-locals=15
max-locals=22

# Maximum number of parents for a class (see R0901).
max-parents=10

# Maximum number of public methods for a class (see R0904).
max-public-methods=20
max-public-methods=22

# Maximum number of return / yield for function / method body.
max-returns=5
Expand Down Expand Up @@ -601,5 +514,5 @@ preferred-modules=

# Exceptions that will emit a warning when being caught.
# Defaults to "BaseException, Exception".
overgeneral-exceptions=BaseException,
Exception,
overgeneral-exceptions=builtins.BaseException,
builtins.Exception,
29 changes: 14 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
VENV := .venv

ifeq ($(OS),Windows_NT)
BIN=$(VENV)/Scripts
else
BIN=$(VENV)/bin
endif

export PATH := $(BIN):$(PATH)

PROJECT := service
TESTS := tests

Expand All @@ -34,32 +26,39 @@ clean:
# Format

isort_fix: .venv
isort $(PROJECT) $(TESTS)
poetry run isort $(PROJECT) $(TESTS)


format: isort_fix
black_fix:
poetry run black $(PROJECT) $(TESTS)

format: isort_fix black_fix


# Lint

isort: .venv
isort --check $(PROJECT) $(TESTS)
poetry run isort --check $(PROJECT) $(TESTS)

.black:
poetry run black --check --diff $(PROJECT) $(TESTS)

flake: .venv
flake8 $(PROJECT) $(TESTS)
poetry run flake8 $(PROJECT) $(TESTS)

mypy: .venv
mypy $(PROJECT) $(TESTS)
poetry run mypy $(PROJECT) $(TESTS)

pylint: .venv
pylint $(PROJECT) $(TESTS)
poetry run pylint $(PROJECT) $(TESTS)

lint: isort flake mypy pylint


# Test

.pytest:
pytest
poetry run pytest $(TESTS)

test: .venv .pytest

Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### Python

В данном шаблоне используется Python3.8, однако вы можете использовать более свежие версии, если хотите.
В данном шаблоне используется Python3.9, однако вы можете использовать и другие версии, если хотите.
Но мы не гарантируем, что все будет работать.

### Make
Expand Down Expand Up @@ -61,17 +61,16 @@ make setup

Командой `make format` можно запустить автоматическое форматирование вашего кода.

Сейчас ее выполнение приведет лишь к запуску [isort](https://github.com/PyCQA/isort) - утилиты
для сортировки импортов в нужном порядке.
При желании вы также можете добавить другие инструменты, например [black](https://github.com/psf/black) или
[yapf](https://github.com/google/yapf), которые могут действительно отформатировать код.
Ее выполнение приведет к запуску [isort](https://github.com/PyCQA/isort) - утилиты
для сортировки импортов в нужном порядке, и [black](https://github.com/psf/black) - одного из самых популярных форматтеров для `Python`.


### Статическая проверка кода

Командой `make lint` вы запустите проверку линтерами - инструментами для статического анализа кода.
Они помогают выявить ошибки в коде еще до его запуска, а также обнаруживают несоответствия стандарту
[PEP8](https://peps.python.org/pep-0008).
[PEP8](https://peps.python.org/pep-0008).
Среди линтеров есть те же `isort` и `black`, только в данном случае они уже ничего не исправляют, а просто проверяют, что код отформатирован правильно.

### Тесты

Expand Down
Loading

0 comments on commit d677ebb

Please sign in to comment.