flake8-diff-only 0.1.5__py3-none-any.whl → 0.1.7__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/checker.py +20 -1
- flake8_diff_only/patch.py +24 -22
- flake8_diff_only/utils.py +40 -40
- {flake8_diff_only-0.1.5.dist-info → flake8_diff_only-0.1.7.dist-info}/METADATA +14 -3
- flake8_diff_only-0.1.7.dist-info/RECORD +10 -0
- flake8_diff_only-0.1.5.dist-info/RECORD +0 -10
- {flake8_diff_only-0.1.5.dist-info → flake8_diff_only-0.1.7.dist-info}/LICENSE.md +0 -0
- {flake8_diff_only-0.1.5.dist-info → flake8_diff_only-0.1.7.dist-info}/WHEEL +0 -0
- {flake8_diff_only-0.1.5.dist-info → flake8_diff_only-0.1.7.dist-info}/entry_points.txt +0 -0
flake8_diff_only/checker.py
CHANGED
@@ -1,12 +1,31 @@
|
|
1
1
|
import ast
|
2
|
+
from typing import Any, ClassVar
|
2
3
|
|
3
4
|
|
4
5
|
class Flake8DiffOnlyChecker:
|
5
6
|
name = "flake8-diff-only"
|
6
|
-
version = "0.1.
|
7
|
+
version = "0.1.7"
|
8
|
+
|
9
|
+
enabled: ClassVar[bool] = False
|
7
10
|
|
8
11
|
def __init__(self, tree: ast.AST, filename: str):
|
9
12
|
pass
|
10
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
|
+
|
11
30
|
def run(self): # type: ignore[no-untyped-def]
|
12
31
|
return []
|
flake8_diff_only/patch.py
CHANGED
@@ -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
|
flake8_diff_only/utils.py
CHANGED
@@ -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
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: flake8-diff-only
|
3
|
-
Version: 0.1.
|
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
|
@@ -30,11 +30,22 @@ Description-Content-Type: text/markdown
|
|
30
30
|
# Project: flake8-diff-only
|
31
31
|
|
32
32
|
## Description
|
33
|
-
|
33
|
+
|
34
|
+
This project provides a plugin for **Flake8** that checks only the modified lines of files for style violations.
|
35
|
+
|
36
|
+
> ⚠️ **Please note:**
|
37
|
+
>
|
38
|
+
> * The [current implementation of `--diff` is fundamentally flawed by design](https://github.com/pycqa/flake8/issues/1389).
|
39
|
+
> * The [`--diff` option was deprecated in Flake8 5.0.0](https://flake8.pycqa.org/en/latest/release-notes/5.0.0.html#deprecations).
|
40
|
+
> * The [`--diff` option was removed entirely in Flake8 6.0.0](https://flake8.pycqa.org/en/latest/release-notes/6.0.0.html#backwards-incompatible-changes).
|
41
|
+
|
42
|
+
This project replicates that deprecated functionality but as a plugin, and naturally inherits the same limitations.
|
43
|
+
However, it has distinct advantages — particularly in **legacy codebases**, where running full Flake8 checks may produce excessive noise.
|
44
|
+
That's why I decided to recreate this feature in the form of a plugin.
|
34
45
|
|
35
46
|
## Usage
|
36
47
|
|
37
|
-
To install the plugin,
|
48
|
+
To install the plugin, run:
|
38
49
|
|
39
50
|
```bash
|
40
51
|
pip install flake8-diff-only
|
@@ -0,0 +1,10 @@
|
|
1
|
+
flake8_diff_only/__init__.py,sha256=N2YaaHCkBqW6hN3QQwL-mqQhhlC2eBqqXcO7n2-m9zQ,50
|
2
|
+
flake8_diff_only/checker.py,sha256=V-hPm7yFO2lR_LckEL3j8k75_BzZFZz-aqe7yI_S65s,741
|
3
|
+
flake8_diff_only/patch.py,sha256=W9ngOwDphcJWL1fQy-TI1QdKI8EwjoAaqxtMMYRNzjM,778
|
4
|
+
flake8_diff_only/types.py,sha256=W-3mb7tKFaZToRHeQZjafUIZhhAUYdr6D8aJE7siIpQ,18
|
5
|
+
flake8_diff_only/utils.py,sha256=M55e_tIqjN0_BT0NjY9C8RF92FOol2SMQuiV1l2D0Bg,1349
|
6
|
+
flake8_diff_only-0.1.7.dist-info/LICENSE.md,sha256=sBI8-TYatRBlqWblXpDP6vKYkA2tKMdxstXkz999qJU,1060
|
7
|
+
flake8_diff_only-0.1.7.dist-info/METADATA,sha256=kifyauMcdf8MTp1527F4HDAfcjy6aww01ntMVVUhAxA,2270
|
8
|
+
flake8_diff_only-0.1.7.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
9
|
+
flake8_diff_only-0.1.7.dist-info/entry_points.txt,sha256=CXw_iI0JlWvRjMglpKBJ04ooVA2r_mSA4cMi9QxV3Ts,71
|
10
|
+
flake8_diff_only-0.1.7.dist-info/RECORD,,
|
@@ -1,10 +0,0 @@
|
|
1
|
-
flake8_diff_only/__init__.py,sha256=N2YaaHCkBqW6hN3QQwL-mqQhhlC2eBqqXcO7n2-m9zQ,50
|
2
|
-
flake8_diff_only/checker.py,sha256=fRQQpFROW4BfCtVC_pwFQJZp3ZsEuU_ekvceLrAmhIk,232
|
3
|
-
flake8_diff_only/patch.py,sha256=flBa-UO1cBGutLyiUKBHefhXepoeJyD2JoVLY2_Nc9A,726
|
4
|
-
flake8_diff_only/types.py,sha256=W-3mb7tKFaZToRHeQZjafUIZhhAUYdr6D8aJE7siIpQ,18
|
5
|
-
flake8_diff_only/utils.py,sha256=yPeTUi2LVYHbwUeaFIuk87ymNhC553Cfr-m0GEPxS1U,1389
|
6
|
-
flake8_diff_only-0.1.5.dist-info/LICENSE.md,sha256=sBI8-TYatRBlqWblXpDP6vKYkA2tKMdxstXkz999qJU,1060
|
7
|
-
flake8_diff_only-0.1.5.dist-info/METADATA,sha256=nr7nTN7FkMOMQUndWZYb1vBLtoyNulnHQIiJATmNTsY,1518
|
8
|
-
flake8_diff_only-0.1.5.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
9
|
-
flake8_diff_only-0.1.5.dist-info/entry_points.txt,sha256=CXw_iI0JlWvRjMglpKBJ04ooVA2r_mSA4cMi9QxV3Ts,71
|
10
|
-
flake8_diff_only-0.1.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|