flake8-diff-only 0.1.6__tar.gz → 0.1.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flake8_diff_only-0.1.6 → flake8_diff_only-0.1.8}/PKG-INFO +3 -1
- {flake8_diff_only-0.1.6 → flake8_diff_only-0.1.8}/README.md +2 -0
- {flake8_diff_only-0.1.6 → flake8_diff_only-0.1.8}/flake8_diff_only/__init__.py +1 -1
- flake8_diff_only-0.1.8/flake8_diff_only/checker.py +34 -0
- {flake8_diff_only-0.1.6 → flake8_diff_only-0.1.8}/flake8_diff_only/patch.py +24 -22
- {flake8_diff_only-0.1.6 → flake8_diff_only-0.1.8}/flake8_diff_only/utils.py +40 -40
- {flake8_diff_only-0.1.6 → flake8_diff_only-0.1.8}/pyproject.toml +1 -1
- flake8_diff_only-0.1.6/flake8_diff_only/checker.py +0 -12
- {flake8_diff_only-0.1.6 → flake8_diff_only-0.1.8}/LICENSE.md +0 -0
- {flake8_diff_only-0.1.6 → flake8_diff_only-0.1.8}/flake8_diff_only/types.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: flake8-diff-only
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.8
|
4
4
|
Summary: Flake8 plugin to show errors only on changed lines
|
5
5
|
License: MIT
|
6
6
|
Keywords: flake8,plugin,quotes,code quality
|
@@ -51,3 +51,5 @@ To install the plugin, run:
|
|
51
51
|
pip install flake8-diff-only
|
52
52
|
```
|
53
53
|
|
54
|
+
To activate this plugin you need to add `--diff-only` on `flake8` calling.
|
55
|
+
|
@@ -1 +1 @@
|
|
1
|
-
from flake8_diff_only import patch # noqa: F401
|
1
|
+
from flake8_diff_only import patch # noqa: F401
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import ast
|
2
|
+
from importlib.metadata import version as _version
|
3
|
+
from typing import Any, ClassVar
|
4
|
+
|
5
|
+
__version__ = _version("flake8-diff-only")
|
6
|
+
|
7
|
+
|
8
|
+
class Flake8DiffOnlyChecker:
|
9
|
+
name = "flake8-diff-only"
|
10
|
+
version = __version__
|
11
|
+
|
12
|
+
enabled: ClassVar[bool] = False
|
13
|
+
|
14
|
+
def __init__(self, tree: ast.AST, filename: str):
|
15
|
+
pass
|
16
|
+
|
17
|
+
@classmethod
|
18
|
+
def add_options(cls, parser: Any) -> None:
|
19
|
+
parser.add_option(
|
20
|
+
"--diff-only",
|
21
|
+
action="store_true",
|
22
|
+
default=False,
|
23
|
+
help=(
|
24
|
+
"Enable flake8-diff-only filtering"
|
25
|
+
" (only show errors in changed lines)."
|
26
|
+
),
|
27
|
+
)
|
28
|
+
|
29
|
+
@classmethod
|
30
|
+
def parse_options(cls, options: Any) -> None:
|
31
|
+
cls.enabled = options.diff_only
|
32
|
+
|
33
|
+
def run(self): # type: ignore[no-untyped-def]
|
34
|
+
return []
|
@@ -1,22 +1,24 @@
|
|
1
|
-
import flake8.checker
|
2
|
-
|
3
|
-
from flake8_diff_only.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
self.
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
1
|
+
import flake8.checker
|
2
|
+
|
3
|
+
from flake8_diff_only.checker import Flake8DiffOnlyChecker
|
4
|
+
from flake8_diff_only.utils import get_changed_lines
|
5
|
+
|
6
|
+
_original_run_checks = flake8.checker.FileChecker.run_checks
|
7
|
+
|
8
|
+
|
9
|
+
def _patched_run_checks(self) -> tuple[str, list, list] | None: # type: ignore
|
10
|
+
if not hasattr(self, "_changed_lines"):
|
11
|
+
self._changed_lines = get_changed_lines(self.filename)
|
12
|
+
|
13
|
+
results = _original_run_checks(self)
|
14
|
+
if results is None:
|
15
|
+
return None
|
16
|
+
|
17
|
+
self.filename, self.results, self.statistics = results
|
18
|
+
if Flake8DiffOnlyChecker.enabled:
|
19
|
+
self.results = list(filter(lambda r: r[1] in self._changed_lines, self.results))
|
20
|
+
|
21
|
+
return self.filename, self.results, self.statistics
|
22
|
+
|
23
|
+
|
24
|
+
flake8.checker.FileChecker.run_checks = _patched_run_checks
|
@@ -1,40 +1,40 @@
|
|
1
|
-
import subprocess
|
2
|
-
|
3
|
-
from flake8_diff_only.types import LineNumber
|
4
|
-
|
5
|
-
|
6
|
-
def get_changed_lines(filename: str) -> set[LineNumber]:
|
7
|
-
"""
|
8
|
-
Получаем множество изменённых строк из git diff.
|
9
|
-
"""
|
10
|
-
changed_lines: set[LineNumber] = set()
|
11
|
-
|
12
|
-
diff_cmd = ["git", "diff", "--unified=0", "--no-color", "--cached", filename]
|
13
|
-
try:
|
14
|
-
output = subprocess.check_output(diff_cmd, stderr=subprocess.DEVNULL).decode()
|
15
|
-
except subprocess.CalledProcessError:
|
16
|
-
return changed_lines
|
17
|
-
|
18
|
-
for line in output.splitlines():
|
19
|
-
if line.startswith("@@"):
|
20
|
-
# Парсим хедер ханка: @@ -old,+new @@
|
21
|
-
try:
|
22
|
-
new_section = line.split(" ")[2]
|
23
|
-
start_line, length = _parse_diff_range(new_section)
|
24
|
-
lines = set(range(start_line, start_line + length))
|
25
|
-
changed_lines.update(lines)
|
26
|
-
except Exception:
|
27
|
-
continue
|
28
|
-
return changed_lines
|
29
|
-
|
30
|
-
|
31
|
-
def _parse_diff_range(range_str: str) -> tuple[LineNumber, int]:
|
32
|
-
"""
|
33
|
-
Парсит формат вроде '+12,3' или '+45' → (start_line, length)
|
34
|
-
"""
|
35
|
-
range_str = range_str.lstrip("+")
|
36
|
-
if "," in range_str:
|
37
|
-
start, length = map(int, range_str.split(","))
|
38
|
-
else:
|
39
|
-
start, length = int(range_str), 1
|
40
|
-
return start, length
|
1
|
+
import subprocess
|
2
|
+
|
3
|
+
from flake8_diff_only.types import LineNumber
|
4
|
+
|
5
|
+
|
6
|
+
def get_changed_lines(filename: str) -> set[LineNumber]:
|
7
|
+
"""
|
8
|
+
Получаем множество изменённых строк из git diff.
|
9
|
+
"""
|
10
|
+
changed_lines: set[LineNumber] = set()
|
11
|
+
|
12
|
+
diff_cmd = ["git", "diff", "--unified=0", "--no-color", "--cached", filename]
|
13
|
+
try:
|
14
|
+
output = subprocess.check_output(diff_cmd, stderr=subprocess.DEVNULL).decode()
|
15
|
+
except subprocess.CalledProcessError:
|
16
|
+
return changed_lines
|
17
|
+
|
18
|
+
for line in output.splitlines():
|
19
|
+
if line.startswith("@@"):
|
20
|
+
# Парсим хедер ханка: @@ -old,+new @@
|
21
|
+
try:
|
22
|
+
new_section = line.split(" ")[2]
|
23
|
+
start_line, length = _parse_diff_range(new_section)
|
24
|
+
lines = set(range(start_line, start_line + length))
|
25
|
+
changed_lines.update(lines)
|
26
|
+
except Exception:
|
27
|
+
continue
|
28
|
+
return changed_lines
|
29
|
+
|
30
|
+
|
31
|
+
def _parse_diff_range(range_str: str) -> tuple[LineNumber, int]:
|
32
|
+
"""
|
33
|
+
Парсит формат вроде '+12,3' или '+45' → (start_line, length)
|
34
|
+
"""
|
35
|
+
range_str = range_str.lstrip("+")
|
36
|
+
if "," in range_str:
|
37
|
+
start, length = map(int, range_str.split(","))
|
38
|
+
else:
|
39
|
+
start, length = int(range_str), 1
|
40
|
+
return start, length
|
File without changes
|
File without changes
|