flake8-diff-only 0.1.6__tar.gz → 0.1.7__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: flake8-diff-only
3
- Version: 0.1.6
3
+ Version: 0.1.7
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,31 @@
1
+ import ast
2
+ from typing import Any, ClassVar
3
+
4
+
5
+ class Flake8DiffOnlyChecker:
6
+ name = "flake8-diff-only"
7
+ version = "0.1.7"
8
+
9
+ enabled: ClassVar[bool] = False
10
+
11
+ def __init__(self, tree: ast.AST, filename: str):
12
+ pass
13
+
14
+ @classmethod
15
+ def add_options(cls, parser: Any) -> None:
16
+ parser.add_option(
17
+ "--diff-only",
18
+ action="store_true",
19
+ default=False,
20
+ help=(
21
+ "Enable flake8-diff-only filtering"
22
+ " (only show errors in changed lines)."
23
+ ),
24
+ )
25
+
26
+ @classmethod
27
+ def parse_options(cls, options: Any) -> None:
28
+ cls.enabled = options.diff_only
29
+
30
+ def run(self): # type: ignore[no-untyped-def]
31
+ return []
@@ -1,22 +1,24 @@
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
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
@@ -4,7 +4,7 @@ requires = [ "poetry-core>=2.0" ]
4
4
 
5
5
  [project]
6
6
  name = "flake8-diff-only"
7
- version = "0.1.6"
7
+ version = "0.1.7"
8
8
  description = "Flake8 plugin to show errors only on changed lines"
9
9
  readme = "README.md"
10
10
 
@@ -1,12 +0,0 @@
1
- import ast
2
-
3
-
4
- class Flake8DiffOnlyChecker:
5
- name = "flake8-diff-only"
6
- version = "0.1.6"
7
-
8
- def __init__(self, tree: ast.AST, filename: str):
9
- pass
10
-
11
- def run(self): # type: ignore[no-untyped-def]
12
- return []