flake8-diff-only 0.1.0__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.
- flake8_diff_only/__init__.py +0 -0
- flake8_diff_only/checker.py +99 -0
- flake8_diff_only-0.1.0.dist-info/LICENSE.md +7 -0
- flake8_diff_only-0.1.0.dist-info/METADATA +43 -0
- flake8_diff_only-0.1.0.dist-info/RECORD +7 -0
- flake8_diff_only-0.1.0.dist-info/WHEEL +4 -0
- flake8_diff_only-0.1.0.dist-info/entry_points.txt +3 -0
File without changes
|
@@ -0,0 +1,99 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import ast
|
4
|
+
import subprocess
|
5
|
+
from typing import ClassVar
|
6
|
+
|
7
|
+
FilePath = str
|
8
|
+
LineNumber = int
|
9
|
+
|
10
|
+
|
11
|
+
class Flake8DiffOnlyChecker:
|
12
|
+
name = "flake8-diff-only"
|
13
|
+
version = "0.1.0"
|
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
|
25
|
+
|
26
|
+
def __init__(self, tree: ast.AST, filename: str):
|
27
|
+
self.filename = filename
|
28
|
+
self.tree = tree
|
29
|
+
|
30
|
+
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"]
|
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
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2011-2025 GitHub Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,43 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: flake8-diff-only
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: Flake8 plugin to show errors on changed lines
|
5
|
+
License: MIT
|
6
|
+
Keywords: flake8,plugin,quotes,code quality
|
7
|
+
Author: Холоднов Эмиль
|
8
|
+
Author-email: emil.kholod@gmail.com
|
9
|
+
Requires-Python: >=3.9.0
|
10
|
+
Classifier: Environment :: Console
|
11
|
+
Classifier: Framework :: Flake8
|
12
|
+
Classifier: Intended Audience :: Developers
|
13
|
+
Classifier: Operating System :: OS Independent
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
15
|
+
Classifier: Programming Language :: Python
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
23
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
24
|
+
Requires-Dist: flake8 (>=5.0.0,<7.3.0)
|
25
|
+
Project-URL: Homepage, https://github.com/emilkholod/flake8-diff-only
|
26
|
+
Project-URL: Issues, https://github.com/emilkholod/flake8-diff-only/issues
|
27
|
+
Project-URL: Repository, https://github.com/emilkholod/flake8-diff-only
|
28
|
+
Description-Content-Type: text/markdown
|
29
|
+
|
30
|
+
# Project: flake8-diff-only
|
31
|
+
|
32
|
+
## Description
|
33
|
+
This project provides a plugin for Flake8 that checks only the modified lines of files for Flake8 violations.
|
34
|
+
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
To install the plugin, use the following command:
|
39
|
+
|
40
|
+
```bash
|
41
|
+
pip install flake8-diff-only
|
42
|
+
```
|
43
|
+
|
@@ -0,0 +1,7 @@
|
|
1
|
+
flake8_diff_only/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
+
flake8_diff_only/checker.py,sha256=W13vao_VUpEoCA-kTBJvPp56AUx-HqarCBaQQph65bg,3768
|
3
|
+
flake8_diff_only-0.1.0.dist-info/LICENSE.md,sha256=sBI8-TYatRBlqWblXpDP6vKYkA2tKMdxstXkz999qJU,1060
|
4
|
+
flake8_diff_only-0.1.0.dist-info/METADATA,sha256=GAgT1Ti0YmE5K2H6hLOnzhx1VZFbEAfWthkzOFkcHb0,1514
|
5
|
+
flake8_diff_only-0.1.0.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
6
|
+
flake8_diff_only-0.1.0.dist-info/entry_points.txt,sha256=l7MFGcU7okKDCm2Ta8x8-xGb5kTvPfPM8sUE0Z8v_t8,72
|
7
|
+
flake8_diff_only-0.1.0.dist-info/RECORD,,
|