flake8-diff-only 0.1.3__py3-none-any.whl → 0.1.4__py3-none-any.whl

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.
@@ -0,0 +1 @@
1
+ from flake8_diff_only import patch # noqa: F401
@@ -1,99 +1,12 @@
1
- from __future__ import annotations
2
-
3
1
  import ast
4
- import subprocess
5
- from typing import ClassVar
6
-
7
- FilePath = str
8
- LineNumber = int
9
2
 
10
3
 
11
4
  class Flake8DiffOnlyChecker:
12
5
  name = "flake8-diff-only"
13
- version = "0.1.3"
14
-
15
- _instance: ClassVar[Flake8DiffOnlyChecker | None] = None
16
- _diff_lines: ClassVar[dict[FilePath, set[LineNumber]]]
17
-
18
- def __new__( # type: ignore[no-untyped-def]
19
- cls, *args, **kwargs
20
- ) -> Flake8DiffOnlyChecker:
21
- if cls._instance is None:
22
- cls._instance = super().__new__(cls)
23
- cls._diff_lines = cls._load_git_diff()
24
- return cls._instance
6
+ version = "0.1.4"
25
7
 
26
8
  def __init__(self, tree: ast.AST, filename: str):
27
- self.filename = filename
28
- self.tree = tree
9
+ pass
29
10
 
30
11
  def run(self): # type: ignore[no-untyped-def]
31
- # Если файл не изменён — пропускаем
32
- if self.filename not in self._diff_lines:
33
- return
34
-
35
- # Получаем список изменённых строк
36
- changed_lines = Flake8DiffOnlyChecker._diff_lines[self.filename]
37
-
38
- # Получаем все ошибки от других плагинов
39
- for lineno, col_offset, message, checker in self._original_errors():
40
- if lineno in changed_lines:
41
- yield lineno, col_offset, message, checker
42
-
43
- def _original_errors(self) -> list: # type: ignore[type-arg]
44
- """
45
- Заглушка: Этот метод не реализует собственную логику проверки.
46
- Он нужен только как перехватчик для других плагинов.
47
- Фактически, flake8 вызовет ВСЕ плагины, а наш просто отфильтрует их вывод.
48
- Поэтому мы не генерируем ошибок тут.
49
- """
50
- return []
51
-
52
- @classmethod
53
- def _load_git_diff(cls) -> dict[FilePath, set[LineNumber]]:
54
- """
55
- Получаем список изменённых строк из git diff.
56
- Возвращает словарь: { 'filename': set(linenos) }
57
- """
58
- diff_cmd = ["git", "diff", "--unified=0", "--no-color", "--cached"]
59
- try:
60
- output = subprocess.check_output(
61
- diff_cmd, stderr=subprocess.DEVNULL
62
- ).decode()
63
- except subprocess.CalledProcessError:
64
- return {}
65
-
66
- result: dict[FilePath, set[LineNumber]] = {}
67
- current_file: str | None = None
68
-
69
- for line in output.splitlines():
70
- if line.startswith("+++ b/"):
71
- current_file = line[6:]
72
- elif line.startswith("@@"):
73
- # Парсим хедер ханка: @@ -old,+new @@
74
- try:
75
- new_section = line.split(" ")[2]
76
- start_line, length = Flake8DiffOnlyChecker._parse_diff_range(
77
- new_section
78
- )
79
- lines = set(range(start_line, start_line + length))
80
- if current_file:
81
- current_file_lines: set[LineNumber] = result.setdefault(
82
- current_file, set()
83
- )
84
- current_file_lines.update(lines)
85
- except Exception:
86
- continue
87
- return result
88
-
89
- @staticmethod
90
- def _parse_diff_range(range_str: str) -> tuple[LineNumber, int]:
91
- """
92
- Парсит формат вроде '+12,3' или '+45' → (start_line, length)
93
- """
94
- range_str = range_str.lstrip("+")
95
- if "," in range_str:
96
- start, length = map(int, range_str.split(","))
97
- else:
98
- start, length = int(range_str), 1
99
- return start, length
12
+ pass
@@ -0,0 +1,22 @@
1
+ import flake8.checker
2
+
3
+ from flake8_diff_only.utils import get_changed_lines
4
+
5
+ _original_run_checks = flake8.checker.FileChecker.run_checks
6
+
7
+
8
+ def _patched_run_checks(self) -> tuple[str, list, list] | None: # type: ignore
9
+ if not hasattr(self, "_changed_lines"):
10
+ self._changed_lines = get_changed_lines(self.filename)
11
+
12
+ results = _original_run_checks(self)
13
+ if results is None or not self._changed_lines:
14
+ return None
15
+
16
+ self.filename, self.results, self.statistics = results
17
+ self.results = list(filter(lambda r: r[1] in self._changed_lines, self.results))
18
+
19
+ return self.filename, self.results, self.statistics
20
+
21
+
22
+ flake8.checker.FileChecker.run_checks = _patched_run_checks
@@ -0,0 +1 @@
1
+ LineNumber = int
@@ -0,0 +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,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: flake8-diff-only
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: Flake8 plugin to show errors only on changed lines
5
5
  License: MIT
6
6
  Keywords: flake8,plugin,quotes,code quality
@@ -0,0 +1,10 @@
1
+ flake8_diff_only/__init__.py,sha256=mY8HBYGvPU1W5pMYGPcYWFUvslzDwVNUVe4CI38eMxg,49
2
+ flake8_diff_only/checker.py,sha256=wtu1MQQXdbaseRSDKWdKcQEQ2aTFrJHxEbRUP2hYZPk,227
3
+ flake8_diff_only/patch.py,sha256=uQ2BA6pbxFK9pve_IxSeYCmHcmk5IskbxGvCZeB92l0,704
4
+ flake8_diff_only/types.py,sha256=zmwrvxKU9fP21rdQMkGnPELmTxEh2QNXxDPQ8JjI4bU,17
5
+ flake8_diff_only/utils.py,sha256=M55e_tIqjN0_BT0NjY9C8RF92FOol2SMQuiV1l2D0Bg,1349
6
+ flake8_diff_only-0.1.4.dist-info/LICENSE.md,sha256=sBI8-TYatRBlqWblXpDP6vKYkA2tKMdxstXkz999qJU,1060
7
+ flake8_diff_only-0.1.4.dist-info/METADATA,sha256=a3joHa7F0QJWW_k7q435q0dzQG2vbuGXqZupLSolKYw,1518
8
+ flake8_diff_only-0.1.4.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
9
+ flake8_diff_only-0.1.4.dist-info/entry_points.txt,sha256=CXw_iI0JlWvRjMglpKBJ04ooVA2r_mSA4cMi9QxV3Ts,71
10
+ flake8_diff_only-0.1.4.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- flake8_diff_only/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- flake8_diff_only/checker.py,sha256=d4FpxE7vbsabF4oxvz1jigo5ae-oi_s1O7b9Ba6BDSs,3780
3
- flake8_diff_only-0.1.3.dist-info/LICENSE.md,sha256=sBI8-TYatRBlqWblXpDP6vKYkA2tKMdxstXkz999qJU,1060
4
- flake8_diff_only-0.1.3.dist-info/METADATA,sha256=ubiEwAPpz0wVCFwgYAUK6DLeUW0aOwCzK69C8jUqUhM,1518
5
- flake8_diff_only-0.1.3.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
6
- flake8_diff_only-0.1.3.dist-info/entry_points.txt,sha256=CXw_iI0JlWvRjMglpKBJ04ooVA2r_mSA4cMi9QxV3Ts,71
7
- flake8_diff_only-0.1.3.dist-info/RECORD,,