patchwise 0.2.0__py3-none-any.whl → 0.2.1__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.
patchwise/__init__.py CHANGED
@@ -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('.')[0]
9
+ PACKAGE_NAME = __name__.split(".")[0]
10
10
 
11
- # Define the sandbox/workspace path relative to the package location
12
- SANDBOX_PATH = PACKAGE_PATH / "sandbox"
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"
patchwise/logger_setup.py CHANGED
@@ -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
- def setup_logger(
49
- log_file: str = LOG_PATH, log_level: str = "INFO"
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(parser_or_group: argparse.ArgumentParser | argparse._ArgumentGroup):
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",
patchwise/main.py CHANGED
@@ -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 setup_logger, add_logging_arguments
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
- import logging
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 . import static_analysis, ai_review
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 ..patch_review.decorators import (
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__}")