Skip to content

Commit d677ebb

Browse files
authored
Merge pull request #42 from feldlime/feature/improve_linters
Feature/improve linters
2 parents 4deb180 + fc504a1 commit d677ebb

File tree

14 files changed

+1094
-652
lines changed

14 files changed

+1094
-652
lines changed

.github/workflows/cicd.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Test
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
types: [opened, synchronize]
8+
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-20.04
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
18+
- name: "Setup python"
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: 3.9
22+
23+
- name: Install Poetry
24+
uses: snok/install-poetry@v1
25+
with:
26+
virtualenvs-create: true
27+
virtualenvs-in-project: true
28+
29+
- name: Load cached venv
30+
id: cached-poetry-dependencies
31+
uses: actions/cache@v3
32+
with:
33+
path: .venv
34+
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
35+
36+
- name: Install dependencies
37+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
38+
run: poetry install
39+
40+
- name: Run tests
41+
run: make lint
42+
43+
- name: Run linters
44+
run: make test

.pylintrc

Lines changed: 24 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# A comma-separated list of package or module names from where C extensions
44
# may be loaded. Extensions are loading into the active Python interpreter
55
# and may run arbitrary code.
6-
extension-pkg-whitelist=orjson,
6+
extension-pkg-whitelist=orjson
77

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

5555
# Disable the message, report, category or checker with the given id(s).
56-
disable=print-statement,
57-
parameter-unpacking,
58-
unpacking-in-except,
59-
old-raise-syntax,
60-
backtick,
61-
long-suffix,
62-
old-ne-operator,
63-
old-octal-literal,
64-
import-star-module-level,
65-
non-ascii-bytes-literal,
66-
raw-checker-failed,
56+
disable=arguments-differ,
6757
bad-inline-option,
68-
locally-disabled,
69-
file-ignored,
70-
suppressed-message,
71-
useless-suppression,
7258
deprecated-pragma,
73-
use-symbolic-message-instead,
74-
apply-builtin,
75-
basestring-builtin,
76-
buffer-builtin,
77-
cmp-builtin,
78-
coerce-builtin,
79-
execfile-builtin,
80-
file-builtin,
81-
long-builtin,
82-
raw_input-builtin,
83-
reduce-builtin,
84-
standarderror-builtin,
85-
unicode-builtin,
86-
xrange-builtin,
87-
coerce-method,
88-
delslice-method,
89-
getslice-method,
90-
setslice-method,
91-
no-absolute-import,
92-
old-division,
93-
dict-iter-method,
94-
dict-view-method,
95-
next-method-called,
96-
metaclass-assignment,
97-
indexing-exception,
98-
raising-string,
99-
reload-builtin,
100-
oct-method,
101-
hex-method,
102-
nonzero-method,
103-
cmp-method,
104-
input-builtin,
105-
round-builtin,
106-
intern-builtin,
107-
unichr-builtin,
108-
map-builtin-not-iterating,
109-
zip-builtin-not-iterating,
110-
range-builtin-not-iterating,
111-
filter-builtin-not-iterating,
112-
using-cmp-argument,
113-
eq-without-hash,
114-
div-method,
115-
idiv-method,
116-
rdiv-method,
117-
exception-message-attribute,
118-
invalid-str-codec,
119-
sys-max-int,
120-
bad-python3-import,
121-
deprecated-string-function,
122-
deprecated-str-translate-call,
123-
deprecated-itertools-function,
124-
deprecated-types-field,
125-
next-method-defined,
126-
dict-items-not-iterating,
127-
dict-keys-not-iterating,
128-
dict-values-not-iterating,
129-
deprecated-operator-function,
130-
deprecated-urllib-function,
131-
xreadlines-attribute,
132-
deprecated-sys-function,
133-
exception-escape,
134-
comprehension-escape,
135-
missing-module-docstring,
136-
missing-function-docstring,
137-
missing-class-docstring,
138-
invalid-name,
59+
duplicate-code,
60+
file-ignored,
13961
invalid-envvar-default,
140-
unused-argument,
141-
no-self-use,
142-
arguments-differ,
143-
no-member,
144-
too-many-ancestors,
62+
invalid-name,
63+
locally-disabled,
14564
logging-fstring-interpolation,
146-
too-many-locals,
65+
missing-class-docstring,
66+
missing-function-docstring,
67+
missing-module-docstring,
68+
no-member,
14769
raise-missing-from,
148-
consider-using-with,
149-
no-name-in-module,
150-
duplicate-code,
151-
152-
70+
raw-checker-failed,
71+
suppressed-message,
72+
unused-argument,
73+
use-implicit-booleaness-not-comparison,
74+
use-symbolic-message-instead,
15375

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

219-
# List of optional constructs for which whitespace checking is disabled.
220-
no-space-check=trailing-comma,
221-
dict-separator
222-
223141
# Allow the body of a class to be on the same line as the declaration
224142
# if body contains single statement.
225143
single-line-class-stmt=no
@@ -312,9 +230,6 @@ method-naming-style=snake_case
312230
# Overrides method-naming-style.
313231
# method-rgx=
314232

315-
# Naming hint for argument names.
316-
argument-name-hint=[a-z_][a-z0-9_]{2,15}$
317-
318233
# Naming style matching correct module names.
319234
module-naming-style=snake_case
320235

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

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

344257
# Regular expression matching correct variable names.
345258
# Overrides variable-naming-style.
@@ -483,7 +396,7 @@ ignore-comments=yes
483396
ignore-docstrings=yes
484397

485398
# Ignore imports when computing similarities.
486-
ignore-imports=yes
399+
ignore-imports=no
487400

488401
# Minimum lines number of a similarity.
489402
min-similarity-lines=4
@@ -526,25 +439,25 @@ valid-metaclass-classmethod-first-arg=cls
526439
[DESIGN]
527440

528441
# Maximum number of arguments for function / method.
529-
max-args=11
442+
max-args=15
530443

531444
# Maximum number of attributes for a class (see R0902).
532-
max-attributes=7
445+
max-attributes=12
533446

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

537450
# Maximum number of branch for function / method body.
538-
max-branches=8
451+
max-branches=9
539452

540453
# Maximum number of locals for function / method body.
541-
max-locals=15
454+
max-locals=22
542455

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

546459
# Maximum number of public methods for a class (see R0904).
547-
max-public-methods=20
460+
max-public-methods=22
548461

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

602515
# Exceptions that will emit a warning when being caught.
603516
# Defaults to "BaseException, Exception".
604-
overgeneral-exceptions=BaseException,
605-
Exception,
517+
overgeneral-exceptions=builtins.BaseException,
518+
builtins.Exception,

Makefile

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
VENV := .venv
22

3-
ifeq ($(OS),Windows_NT)
4-
BIN=$(VENV)/Scripts
5-
else
6-
BIN=$(VENV)/bin
7-
endif
8-
9-
export PATH := $(BIN):$(PATH)
10-
113
PROJECT := service
124
TESTS := tests
135

@@ -34,32 +26,39 @@ clean:
3426
# Format
3527

3628
isort_fix: .venv
37-
isort $(PROJECT) $(TESTS)
29+
poetry run isort $(PROJECT) $(TESTS)
30+
3831

39-
format: isort_fix
32+
black_fix:
33+
poetry run black $(PROJECT) $(TESTS)
34+
35+
format: isort_fix black_fix
4036

4137

4238
# Lint
4339

4440
isort: .venv
45-
isort --check $(PROJECT) $(TESTS)
41+
poetry run isort --check $(PROJECT) $(TESTS)
42+
43+
.black:
44+
poetry run black --check --diff $(PROJECT) $(TESTS)
4645

4746
flake: .venv
48-
flake8 $(PROJECT) $(TESTS)
47+
poetry run flake8 $(PROJECT) $(TESTS)
4948

5049
mypy: .venv
51-
mypy $(PROJECT) $(TESTS)
50+
poetry run mypy $(PROJECT) $(TESTS)
5251

5352
pylint: .venv
54-
pylint $(PROJECT) $(TESTS)
53+
poetry run pylint $(PROJECT) $(TESTS)
5554

5655
lint: isort flake mypy pylint
5756

5857

5958
# Test
6059

6160
.pytest:
62-
pytest
61+
poetry run pytest $(TESTS)
6362

6463
test: .venv .pytest
6564

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### Python
66

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

1010
### Make
@@ -61,17 +61,16 @@ make setup
6161

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

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

6967

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

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

7675
### Тесты
7776

0 commit comments

Comments
 (0)