Skip to content

Commit aca6735

Browse files
author
Isac Byeonghoon Yoo
authored
Prune dependencies (#46)
* ♻️ - Refactor * 🔖 - Bump up version to 1.1.0
1 parent b7da2f4 commit aca6735

File tree

7 files changed

+68
-60
lines changed

7 files changed

+68
-60
lines changed

pyproject.toml

+26-19
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.masonry.api"
44

55
[tool.poetry]
66
name = "buzzvil-python-styleguide"
7-
version = "1.0.2"
7+
version = "1.1.0"
88
description = "Buzzvil's shared style preset"
99
authors = ["Isac Byeonghoon Yoo <[email protected]>"]
1010
maintainers = ["Isac Byeonghoon Yoo <[email protected]>"]
@@ -17,41 +17,42 @@ classifiers = [
1717
"Framework :: Flake8",
1818
"Intended Audience :: Developers",
1919
"Natural Language :: English",
20-
"Programming Language :: Python :: 2",
21-
"Programming Language :: Python :: 2.7",
2220
"Programming Language :: Python :: 3",
2321
"Programming Language :: Python :: 3.6",
2422
"Programming Language :: Python :: 3.7",
2523
"Programming Language :: Python :: 3.8",
2624
"Programming Language :: Python :: 3.9",
25+
"Programming Language :: Python :: 3.10",
2726
"Topic :: Software Development :: Libraries :: Python Modules",
2827
"Topic :: Software Development :: Quality Assurance",
2928
]
3029

3130

3231
[tool.poetry.dependencies]
3332
python = "^3.6.2"
34-
flake8 = ">=3.5"
3533
black = "^21.9b0"
36-
flake8-builtins = "^1.5.3"
37-
mypy = ">=0.910"
34+
django-stubs = { version = "^1.9.0", optional = true }
35+
flake8 = ">=3.8"
36+
flake8-annotations-complexity = "^0.0.6"
37+
flake8-bandit = "^2.1.2"
38+
flake8-black = "^0.2.3"
39+
flake8-breakpoint = "^1.1.0"
3840
flake8-bugbear = "^21.9.2"
41+
flake8-builtins = "^1.5.3"
3942
flake8-comprehensions = "^3.7.0"
4043
flake8-django = { version = "^1.1.2", optional = true }
41-
flake8-eradicate = "^1.1.0"
42-
flake8-mutable = "^1.2.0"
43-
flake8-pytest-style = "^1.5.0"
44-
pep8-naming = "^0.12.1"
44+
flake8-eradicate = "^1.2.0"
45+
flake8-force-keyword-arguments = "^1.0.0"
4546
flake8-functions = "^0.0.6"
46-
flake8-annotations-complexity = "^0.0.6"
47-
dlint = "^0.11.0"
48-
django-stubs = { version = "^1.9.0", optional = true }
49-
flake8-black = "^0.2.3"
50-
flake8-blind-except = "^0.2.0"
5147
flake8-future-import = "^0.4.6"
48+
flake8-logging-format = "^0.6.0"
49+
flake8-print = "^4.0.0"
50+
flake8-pytest-style = "^1.5.0"
51+
flake8-return = "^1.1.3"
52+
importlib-metadata = {version = "*", python = "<3.8"}
53+
mypy = ">=0.910"
5254
nitpick = "^0.27.0"
53-
flake8-keyword-arguments = "^0.1.0"
54-
importlib-metadata = {version = "^4.8.1", python = "<3.10"}
55+
pep8-naming = "^0.12.1"
5556
typing-extensions = { version = "^3.7.4.3", python = "<3.8" }
5657

5758
[tool.poetry.dev-dependencies]
@@ -69,17 +70,17 @@ BZ = "buzzvil_python_styleguide:RequestsTimeoutPlugin"
6970
force-exclude = "(\n /(\n \\.eggs\n | \\.git\n | \\.hg\n | \\.mypy_cache\n | \\.tox\n | \\.venv\n | _build\n | buck-out\n | build\n | dist\n )/\n | migrations/\n | venv.?\n)\n"
7071
line-length = 120
7172
skip-string-normalization = true
72-
target-version = ["py39"]
73+
target-version = ["py36", "py37", "py38", "py39"]
7374

7475

7576
[tool.nitpick]
7677
style = "src/buzzvil_python_styleguide/styles/nitpick-style.toml"
78+
cache = "never"
7779

7880
[tool.mypy]
7981
allow_redefinition = true
8082
disallow_any_decorated = true
8183
disallow_any_explicit = true
82-
disallow_any_expr = true
8384
disallow_any_generics = true
8485
disallow_incomplete_defs = true
8586
disallow_subclassing_any = true
@@ -94,3 +95,9 @@ warn_redundant_casts = true
9495
warn_return_any = true
9596
warn_unreachable = true
9697
warn_unused_ignores = true
98+
99+
# Output configuration
100+
show_error_context = true
101+
show_column_numbers = true
102+
show_error_codes = true
103+
pretty = true

setup.cfg

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
[flake8]
22
exclude = venv*,**/migrations/
3-
ignore = W503,E203,FI12,FI15,FI16,FI17,FI55,FI58,PT003,C408,C400,C401
3+
ignore = W503,E203,FI12,FI15,FI16,FI17,FI55,FI58,PT003,C408,C400,C401,CFQ004
44

55
max-line-length = 120
66
require-code = True
77
max-parameters-amount = 10
88
max-annotations-complexity = 4
99
min-version = 3.6.2
10-
max-pos_args = 2
1110
per-file-ignores =
12-
**/tests/**.py:FI18,CFQ001,E501,
11+
**/tests/**.py:FI18,CFQ001,E501,S101,
12+
tests/**.py:FI18,CFQ001,E501,S101,
1313
__init__.py:F401
1414
# flake8-pytest-style
1515
pytest-parametrize-values-type = tuple
1616
eradicate-whitelist = mypy:#noqa:
17+
# flake8-force-keyword-arguments
18+
kwargs-max-positional-arguments = 2
19+
kwargs-ignore-function-pattern-extend = ^pytest.mark.parametrize$

src/buzzvil_python_styleguide/__init__.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
from typing_extensions import Final
1+
# mypy: allow_untyped_calls
22

3-
try:
4-
from importlib.metadata import version
5-
except ModuleNotFoundError:
3+
import sys
4+
5+
if sys.version_info < (3, 8):
6+
from typing_extensions import Final
67
from importlib_metadata import version
8+
else:
9+
from typing import Final
10+
from importlib.metadata import version
711

812
__version__: Final[str] = version(__name__)
913

src/buzzvil_python_styleguide/plugin.py

+14-26
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
11
import ast
2-
from collections import deque
3-
from typing import ClassVar, Deque, Iterable, Tuple, Type
2+
from typing import ClassVar, Iterable, Tuple, Type
43

54
import buzzvil_python_styleguide
65

76

8-
class FuncCallVisitor(ast.NodeVisitor):
9-
_name: Deque[str]
7+
def get_invocation_line(c: ast.Call) -> str:
8+
def dfs(a: ast.AST) -> str:
9+
child = getattr(a, 'value', None)
10+
name = getattr(a, 'id', getattr(a, 'attr', None))
1011

11-
def __init__(self) -> None:
12-
self._name = deque()
12+
if child is None or not isinstance(child, ast.AST):
13+
if name is None or not isinstance(name, str):
14+
return ''
15+
return name
1316

14-
@property
15-
def name(self) -> str:
16-
return '.'.join(self._name)
17+
return '.'.join(filter(None, (dfs(child), name)))
1718

18-
@name.deleter
19-
def name(self) -> None:
20-
self._name.clear()
21-
22-
def visit_Name(self, node: ast.Name) -> None: # noqa: N802
23-
self._name.appendleft(node.id)
24-
25-
def visit_Attribute(self, node: ast.Attribute) -> None: # noqa: N802
26-
self._name.appendleft(node.attr)
27-
if isinstance(node.value, ast.Name): # type: ignore[misc]
28-
self._name.appendleft(node.value.id)
29-
else:
30-
self.generic_visit(node)
19+
return dfs(c.func)
3120

3221

3322
class RequestsTimeoutPlugin:
@@ -44,13 +33,12 @@ def run(self) -> Iterable[Tuple[int, int, str, Type['RequestsTimeoutPlugin']]]:
4433
:return: (lineno, col_offset, error_string, Type)
4534
"""
4635
for node in ast.walk(self.tree):
47-
if not isinstance(node, ast.Call): # type: ignore[misc]
36+
if not isinstance(node, ast.Call):
4837
continue
4938

50-
callvisitor = FuncCallVisitor()
51-
callvisitor.visit(node.func)
39+
invocation_line = get_invocation_line(node)
5240
# There can be different ways of calling requests method but this covers almost all cases.
53-
if callvisitor.name not in ('requests.get', 'requests.post', 'session.get', 'session.post'):
41+
if invocation_line not in ('requests.get', 'requests.post', 'session.get', 'session.post'):
5442
continue
5543

5644
if 'timeout' not in [k.arg for k in node.keywords]:

src/buzzvil_python_styleguide/styles/flake8.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ max-line-length = 120
55
require-code = true
66

77
exclude = "venv*,**/migrations/"
8-
per-file-ignores = "**/tests/**.py:FI18,CFQ001,E501,__init__.py:F401"
8+
per-file-ignores = "**/tests/**.py:FI18,CFQ001,E501,S101,tests/**.py:FI18,CFQ001,E501,S101,__init__.py:F401"
99

1010
# flake8-functions
1111
max-parameters-amount = 10
1212
# flake8-annotations-complexity
1313
max-annotations-complexity = 4
14-
max-pos_args = 2
1514
# flake8-pytest-style
1615
pytest-parametrize-values-type = 'tuple'
1716
eradicate-whitelist = 'mypy:#noqa:'
17+
# flake8-force-keyword-arguments
18+
kwargs-max-positional-arguments = 2
19+
kwargs-ignore-function-pattern-extend = '^pytest.mark.parametrize$'
1820

1921
[nitpick.files."setup.cfg"]
20-
comma_separated_values = ["flake8.ignore", "flake8.exclude", "flake8.per-file-ignores"]
22+
comma_separated_values = ["flake8.ignore", "flake8.exclude", "flake8.per-file-ignores", "flake8.kwargs-ignore-function-pattern-extend"]

src/buzzvil_python_styleguide/styles/mypy.toml

+6
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ no_implicit_reexport = true
1818
##
1919

2020
allow_redefinition = true
21+
22+
# Output configuration
23+
show_error_context = true
24+
show_column_numbers = true
25+
show_error_codes = true
26+
pretty = true

tests/test_func_call_visitor.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44

5-
from buzzvil_python_styleguide.plugin import FuncCallVisitor, RequestsTimeoutPlugin
5+
from buzzvil_python_styleguide.plugin import RequestsTimeoutPlugin, get_invocation_line
66

77

88
class TestFucCallVisitor:
@@ -21,10 +21,8 @@ class TestFucCallVisitor:
2121
),
2222
)
2323
def test_name(self, source: str, expected: str) -> None:
24-
v = FuncCallVisitor()
25-
tree = ast.parse(source)
26-
v.visit(tree)
27-
assert expected == v.name
24+
c = ast.parse(source).body[0].value # type: ignore[attr-defined]
25+
assert expected == get_invocation_line(c)
2826

2927

3028
class TestRequestsTimeoutPlugin:

0 commit comments

Comments
 (0)