patchwise 0.2.0__tar.gz → 0.2.1__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.
- {patchwise-0.2.0 → patchwise-0.2.1}/PKG-INFO +3 -4
- {patchwise-0.2.0 → patchwise-0.2.1}/README.md +8 -21
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise/__init__.py +3 -3
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise/logger_setup.py +8 -6
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise/main.py +15 -10
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise/patch_review/__init__.py +14 -15
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise/patch_review/ai_review/ai_code_review.py +333 -198
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise/patch_review/ai_review/ai_review.py +41 -57
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise/patch_review/ai_review/llm_commit_audit.py +2 -2
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise/patch_review/decorators.py +3 -3
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise/patch_review/kernel_tree.py +18 -10
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise/patch_review/patch_review.py +14 -6
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise/patch_review/static_analysis/checkpatch.py +6 -1
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise/patch_review/static_analysis/coccicheck.py +7 -6
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise/patch_review/static_analysis/dt_check.py +14 -7
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise/patch_review/static_analysis/dtbs_check.py +17 -11
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise/patch_review/static_analysis/sparse.py +24 -9
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise/patch_review/static_analysis/static_analysis.py +9 -3
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise.egg-info/PKG-INFO +3 -4
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise.egg-info/requires.txt +1 -2
- {patchwise-0.2.0 → patchwise-0.2.1}/pyproject.toml +4 -4
- {patchwise-0.2.0 → patchwise-0.2.1}/LICENSE.txt +0 -0
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise/patch_review/ai_review/__init__.py +0 -0
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise/patch_review/static_analysis/__init__.py +0 -0
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise.egg-info/SOURCES.txt +0 -0
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise.egg-info/dependency_links.txt +0 -0
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise.egg-info/entry_points.txt +0 -0
- {patchwise-0.2.0 → patchwise-0.2.1}/patchwise.egg-info/top_level.txt +0 -0
- {patchwise-0.2.0 → patchwise-0.2.1}/setup.cfg +0 -0
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: patchwise
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: A tool for reviewing kernel patches
|
|
5
|
-
Author-email: David Gantman <dgantman@
|
|
5
|
+
Author-email: David Gantman <dgantman@qti.qualcomm.com>
|
|
6
6
|
Requires-Python: >=3.10
|
|
7
7
|
License-File: LICENSE.txt
|
|
8
8
|
Requires-Dist: Sphinx>=8.1.3
|
|
9
|
-
Requires-Dist: litellm>=1.
|
|
9
|
+
Requires-Dist: litellm>=1.74
|
|
10
10
|
Requires-Dist: cachetools>=5.5.2
|
|
11
|
-
Requires-Dist: dtschema>=2025.2
|
|
12
11
|
Requires-Dist: yamllint>=1.26.3
|
|
13
12
|
Requires-Dist: ply>=3.11
|
|
14
13
|
Requires-Dist: GitPython>=3.1.44
|
|
@@ -42,13 +42,6 @@
|
|
|
42
42
|
|
|
43
43
|
### Installation
|
|
44
44
|
|
|
45
|
-
1. **Clone the repository:**
|
|
46
|
-
|
|
47
|
-
```bash
|
|
48
|
-
git clone https://github.com/qualcomm/PatchWise.git
|
|
49
|
-
cd PatchWise
|
|
50
|
-
```
|
|
51
|
-
|
|
52
45
|
1. **Create and activate a virtual environment:**
|
|
53
46
|
|
|
54
47
|
```bash
|
|
@@ -56,10 +49,10 @@
|
|
|
56
49
|
source .venv/bin/activate
|
|
57
50
|
```
|
|
58
51
|
|
|
59
|
-
1. **Install
|
|
52
|
+
1. **Install PatchWise:**
|
|
60
53
|
|
|
61
54
|
```bash
|
|
62
|
-
pip install
|
|
55
|
+
pip install patchwise
|
|
63
56
|
```
|
|
64
57
|
|
|
65
58
|
1. **Set up your API key:**
|
|
@@ -115,27 +108,21 @@
|
|
|
115
108
|
### Example Workflow
|
|
116
109
|
|
|
117
110
|
```bash
|
|
118
|
-
# Replace with a path on your system where you would like to download patchwise
|
|
119
|
-
cd /local/mnt/workspace/dgantman/kernel-tools
|
|
120
|
-
|
|
121
|
-
### Clone the repository
|
|
122
|
-
git clone https://github.com/qualcomm/PatchWise.git
|
|
123
|
-
cd /local/mnt/workspace/dgantman/kernel-tools/PatchWise
|
|
124
|
-
|
|
125
111
|
### Create and activate a virtual environment
|
|
126
112
|
python3.10 -m venv .venv
|
|
127
113
|
# Required every time you start a new shell session
|
|
128
|
-
source
|
|
129
|
-
|
|
130
|
-
pip install
|
|
114
|
+
source .venv/bin/activate
|
|
115
|
+
### Install PatchWise
|
|
116
|
+
pip install patchwise
|
|
117
|
+
|
|
131
118
|
# Required every time you start a new shell session
|
|
132
119
|
# unless you've added it to your shell profile (e.g., ~/.bashrc or ~/.zshrc)
|
|
133
120
|
# You can find your API key from your provider
|
|
134
121
|
export OPENAI_API_KEY=<your-api-key>
|
|
135
122
|
|
|
136
123
|
### Run PatchWise in your kernel workspace that has the patch you want to review already applied
|
|
137
|
-
cd
|
|
138
|
-
patchwise
|
|
124
|
+
cd linux-next
|
|
125
|
+
patchwise
|
|
139
126
|
```
|
|
140
127
|
|
|
141
128
|
---
|
|
@@ -6,10 +6,10 @@ from pathlib import Path
|
|
|
6
6
|
# Get the path of the patchwise package
|
|
7
7
|
PACKAGE_PATH = Path(__file__).resolve().parent
|
|
8
8
|
|
|
9
|
-
PACKAGE_NAME = __name__.split(
|
|
9
|
+
PACKAGE_NAME = __name__.split(".")[0]
|
|
10
10
|
|
|
11
|
-
# Define the sandbox/workspace path
|
|
12
|
-
SANDBOX_PATH =
|
|
11
|
+
# Define the sandbox/workspace path in tmp directory
|
|
12
|
+
SANDBOX_PATH = Path("/tmp") / PACKAGE_NAME / "sandbox"
|
|
13
13
|
SANDBOX_BIN = SANDBOX_PATH / "bin"
|
|
14
14
|
# Define the kernel workspace path
|
|
15
15
|
KERNEL_PATH = SANDBOX_PATH / "kernel"
|
|
@@ -21,6 +21,7 @@ RED = "\033[31m"
|
|
|
21
21
|
GRAY = "\033[232m"
|
|
22
22
|
BOLD = "\033[1m"
|
|
23
23
|
|
|
24
|
+
|
|
24
25
|
class ColorFormatter(logging.Formatter):
|
|
25
26
|
def format(self, record):
|
|
26
27
|
msg = super().format(record)
|
|
@@ -30,7 +31,7 @@ class ColorFormatter(logging.Formatter):
|
|
|
30
31
|
# Color everything up to and including the first ": "
|
|
31
32
|
split_idx = msg.find(": ")
|
|
32
33
|
if split_idx != -1:
|
|
33
|
-
header = msg[:split_idx + 2]
|
|
34
|
+
header = msg[: split_idx + 2]
|
|
34
35
|
message = msg[split_idx + 2 :]
|
|
35
36
|
else:
|
|
36
37
|
return msg
|
|
@@ -45,9 +46,8 @@ class ColorFormatter(logging.Formatter):
|
|
|
45
46
|
else:
|
|
46
47
|
return msg
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
):
|
|
49
|
+
|
|
50
|
+
def setup_logger(log_file: str = LOG_PATH, log_level: str = "INFO"):
|
|
51
51
|
"""
|
|
52
52
|
Sets up the logger with the specified log file and log level.
|
|
53
53
|
"""
|
|
@@ -66,12 +66,14 @@ def setup_logger(
|
|
|
66
66
|
logging.getLogger(__name__.split(".")[0]).setLevel(log_level)
|
|
67
67
|
|
|
68
68
|
|
|
69
|
-
def add_logging_arguments(
|
|
69
|
+
def add_logging_arguments(
|
|
70
|
+
parser_or_group: argparse.ArgumentParser | argparse._ArgumentGroup,
|
|
71
|
+
):
|
|
70
72
|
parser_or_group.add_argument(
|
|
71
73
|
"--log-level",
|
|
72
74
|
choices=("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"),
|
|
73
75
|
default="INFO",
|
|
74
|
-
help="Set the logging level. (default: %(default)s)"
|
|
76
|
+
help="Set the logging level. (default: %(default)s)",
|
|
75
77
|
)
|
|
76
78
|
parser_or_group.add_argument(
|
|
77
79
|
"--log-file",
|
|
@@ -4,24 +4,27 @@
|
|
|
4
4
|
import argparse
|
|
5
5
|
import logging
|
|
6
6
|
from pathlib import Path
|
|
7
|
+
|
|
7
8
|
from git import Repo
|
|
8
9
|
from git.objects.commit import Commit
|
|
9
10
|
from rich_argparse import RichHelpFormatter
|
|
10
11
|
|
|
11
|
-
from .logger_setup import
|
|
12
|
+
from .logger_setup import add_logging_arguments, setup_logger
|
|
13
|
+
from .patch_review import (
|
|
14
|
+
add_review_arguments,
|
|
15
|
+
get_selected_reviews_from_args,
|
|
16
|
+
install_missing_dependencies,
|
|
17
|
+
review_patch,
|
|
18
|
+
)
|
|
19
|
+
from .patch_review.ai_review.ai_review import add_ai_arguments, apply_ai_args
|
|
12
20
|
from .patch_review.kernel_tree import create_git_worktree
|
|
13
21
|
from .patch_review.patch_review import PATCH_PATH
|
|
14
|
-
from .patch_review import review_patch, add_review_arguments, get_selected_reviews_from_args, install_missing_dependencies
|
|
15
|
-
from .patch_review.ai_review.ai_review import add_ai_arguments, apply_ai_args
|
|
16
|
-
|
|
17
22
|
|
|
18
23
|
logger = logging.getLogger(__name__)
|
|
19
24
|
|
|
20
25
|
|
|
21
26
|
def parse_args() -> argparse.Namespace:
|
|
22
|
-
parser = argparse.ArgumentParser(
|
|
23
|
-
formatter_class=RichHelpFormatter
|
|
24
|
-
)
|
|
27
|
+
parser = argparse.ArgumentParser(formatter_class=RichHelpFormatter)
|
|
25
28
|
|
|
26
29
|
review_group = parser.add_argument_group("Patch Review Options")
|
|
27
30
|
|
|
@@ -29,7 +32,7 @@ def parse_args() -> argparse.Namespace:
|
|
|
29
32
|
"--commits",
|
|
30
33
|
nargs="*",
|
|
31
34
|
default=["HEAD"],
|
|
32
|
-
help="Space separated list of commit SHAs/refs, or a single commit range in start..end format. (default: %(default)s)"
|
|
35
|
+
help="Space separated list of commit SHAs/refs, or a single commit range in start..end format. (default: %(default)s)",
|
|
33
36
|
)
|
|
34
37
|
review_group.add_argument(
|
|
35
38
|
"--repo-path",
|
|
@@ -39,7 +42,6 @@ def parse_args() -> argparse.Namespace:
|
|
|
39
42
|
|
|
40
43
|
add_review_arguments(review_group)
|
|
41
44
|
|
|
42
|
-
|
|
43
45
|
ai_group = parser.add_argument_group("AI Review Options")
|
|
44
46
|
add_ai_arguments(ai_group)
|
|
45
47
|
|
|
@@ -48,6 +50,7 @@ def parse_args() -> argparse.Namespace:
|
|
|
48
50
|
|
|
49
51
|
return parser.parse_args()
|
|
50
52
|
|
|
53
|
+
|
|
51
54
|
def get_patches(repo: Repo, commits: list[Commit]):
|
|
52
55
|
dest_dir = PATCH_PATH / "user"
|
|
53
56
|
dest_dir.mkdir(parents=True, exist_ok=True)
|
|
@@ -57,6 +60,7 @@ def get_patches(repo: Repo, commits: list[Commit]):
|
|
|
57
60
|
logger.debug(f"Writing patch for commit {commit} to {patch_file}")
|
|
58
61
|
patch_file.write_text(diff)
|
|
59
62
|
|
|
63
|
+
|
|
60
64
|
def get_commits(repo: Repo, commits: list[str]) -> list[Commit]:
|
|
61
65
|
"""
|
|
62
66
|
Given a repo and a list of commit refs or a commit range, return a list of Commit objects.
|
|
@@ -75,8 +79,8 @@ def get_commits(repo: Repo, commits: list[str]) -> list[Commit]:
|
|
|
75
79
|
# List of refs/SHAs
|
|
76
80
|
return [repo.commit(ref) for ref in commits]
|
|
77
81
|
|
|
78
|
-
def main():
|
|
79
82
|
|
|
83
|
+
def main():
|
|
80
84
|
args = parse_args()
|
|
81
85
|
|
|
82
86
|
setup_logger(log_file=args.log_file, log_level=args.log_level)
|
|
@@ -97,5 +101,6 @@ def main():
|
|
|
97
101
|
logger.info(f"Reviewing commit {commit.hexsha}...")
|
|
98
102
|
review_patch(reviews, commit)
|
|
99
103
|
|
|
104
|
+
|
|
100
105
|
if __name__ == "__main__":
|
|
101
106
|
main()
|
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
3
3
|
|
|
4
4
|
import argparse
|
|
5
|
-
|
|
6
|
-
from typing import Iterable
|
|
7
|
-
from git.objects.commit import Commit
|
|
5
|
+
|
|
8
6
|
# Automatically import all patch review modules so all @register_patch_review classes are registered
|
|
9
7
|
import importlib
|
|
8
|
+
import logging
|
|
10
9
|
import pkgutil
|
|
11
|
-
from
|
|
10
|
+
from typing import Iterable
|
|
11
|
+
|
|
12
|
+
from git.objects.commit import Commit
|
|
13
|
+
|
|
14
|
+
from . import ai_review, static_analysis
|
|
12
15
|
|
|
13
16
|
# Import all modules in static_analysis subpackage
|
|
14
17
|
for _, modname, ispkg in pkgutil.iter_modules(static_analysis.__path__):
|
|
@@ -20,18 +23,19 @@ for _, modname, ispkg in pkgutil.iter_modules(ai_review.__path__):
|
|
|
20
23
|
if not ispkg:
|
|
21
24
|
importlib.import_module(f"{__name__}.ai_review.{modname}")
|
|
22
25
|
|
|
23
|
-
from
|
|
26
|
+
from patchwise.patch_review.decorators import (
|
|
24
27
|
AVAILABLE_PATCH_REVIEWS,
|
|
25
28
|
LLM_REVIEWS,
|
|
26
|
-
STATIC_ANALYSIS_REVIEWS,
|
|
27
|
-
SHORT_REVIEWS,
|
|
28
29
|
LONG_REVIEWS,
|
|
30
|
+
SHORT_REVIEWS,
|
|
31
|
+
STATIC_ANALYSIS_REVIEWS,
|
|
29
32
|
)
|
|
30
|
-
from .patch_review import PatchReview
|
|
31
33
|
|
|
34
|
+
from .patch_review import PatchReview
|
|
32
35
|
|
|
33
36
|
logger = logging.getLogger(__name__)
|
|
34
37
|
|
|
38
|
+
|
|
35
39
|
class PatchReviewResults:
|
|
36
40
|
def __init__(self, commit: Commit):
|
|
37
41
|
self.commit = commit
|
|
@@ -63,11 +67,8 @@ def run_patch_review(
|
|
|
63
67
|
|
|
64
68
|
|
|
65
69
|
def review_patch(reviews: set[str], commit: Commit) -> PatchReviewResults:
|
|
66
|
-
|
|
67
70
|
all_reviews = {cls.__name__: cls for cls in AVAILABLE_PATCH_REVIEWS}
|
|
68
|
-
selected_reviews = [
|
|
69
|
-
all_reviews[name] for name in reviews if name in all_reviews
|
|
70
|
-
]
|
|
71
|
+
selected_reviews = [all_reviews[name] for name in reviews if name in all_reviews]
|
|
71
72
|
|
|
72
73
|
for review_cls in selected_reviews:
|
|
73
74
|
logger.debug(f"Verifying dependencies for: {review_cls.__name__}")
|
|
@@ -83,9 +84,7 @@ def install_missing_dependencies(reviews: set[str]) -> None:
|
|
|
83
84
|
Install missing dependencies for the specified reviews.
|
|
84
85
|
"""
|
|
85
86
|
all_reviews = {cls.__name__: cls for cls in AVAILABLE_PATCH_REVIEWS}
|
|
86
|
-
selected_reviews = [
|
|
87
|
-
all_reviews[name] for name in reviews if name in all_reviews
|
|
88
|
-
]
|
|
87
|
+
selected_reviews = [all_reviews[name] for name in reviews if name in all_reviews]
|
|
89
88
|
|
|
90
89
|
for review_cls in selected_reviews:
|
|
91
90
|
logger.info(f"Installing dependencies for: {review_cls.__name__}")
|