python-code-validator 0.1.3__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.
@@ -13,7 +13,7 @@ import sys
13
13
 
14
14
  from ..components.definitions import Constraint, Rule, Selector
15
15
  from ..config import FullRuleConfig, ShortRuleConfig
16
- from ..output import Console, LogLevel
16
+ from ..output import Console, LogLevel, log_initialization
17
17
 
18
18
 
19
19
  class CheckSyntaxRule(Rule):
@@ -27,6 +27,7 @@ class CheckSyntaxRule(Rule):
27
27
  formally defined in the JSON configuration.
28
28
  """
29
29
 
30
+ @log_initialization(level=LogLevel.TRACE)
30
31
  def __init__(self, config: ShortRuleConfig, console: Console):
31
32
  """Initializes the syntax check rule handler.
32
33
 
@@ -45,7 +46,7 @@ class CheckSyntaxRule(Rule):
45
46
  Returns:
46
47
  Always returns True.
47
48
  """
48
- self._console.print(f"Rule {self.config.rule_id}: Syntax is valid.", level=LogLevel.DEBUG)
49
+ self._console.print(f"Rule {self.config.rule_id}: Syntax is valid.", level=LogLevel.INFO)
49
50
  return True
50
51
 
51
52
 
@@ -57,6 +58,7 @@ class CheckLinterRule(Rule):
57
58
  configurable via the 'params' field in the JSON rule.
58
59
  """
59
60
 
61
+ @log_initialization(level=LogLevel.TRACE)
60
62
  def __init__(self, config: ShortRuleConfig, console: Console):
61
63
  """Initializes a PEP8 linter check rule handler."""
62
64
  self.config = config
@@ -80,7 +82,7 @@ class CheckLinterRule(Rule):
80
82
  self._console.print("Source code is empty, skipping PEP8 check.", level=LogLevel.WARNING)
81
83
  return True
82
84
 
83
- self._console.print(f"Rule {self.config.rule_id}: Running flake8 linter...", level=LogLevel.DEBUG)
85
+ self._console.print(f"Rule {self.config.rule_id}: Running PEP8 linter...", level=LogLevel.INFO)
84
86
 
85
87
  params = self.config.params
86
88
  args = [sys.executable, "-m", "flake8", "-"]
@@ -90,6 +92,8 @@ class CheckLinterRule(Rule):
90
92
  elif ignore_list := params.get("ignore"):
91
93
  args.append(f"--ignore={','.join(ignore_list)}")
92
94
 
95
+ self._console.print(f"Arguments for flake8: {args}", level=LogLevel.TRACE)
96
+
93
97
  try:
94
98
  process = subprocess.run(
95
99
  args,
@@ -102,7 +106,7 @@ class CheckLinterRule(Rule):
102
106
 
103
107
  if process.returncode != 0 and process.stdout:
104
108
  linter_output = process.stdout.strip()
105
- self._console.print(f"Flake8 found issues:\n{linter_output}", level=LogLevel.DEBUG)
109
+ self._console.print(f"Flake8 found issues:\n{linter_output}", level=LogLevel.WARNING, show_user=True)
106
110
  return False
107
111
  elif process.returncode != 0:
108
112
  self._console.print(
@@ -110,7 +114,7 @@ class CheckLinterRule(Rule):
110
114
  )
111
115
  return False
112
116
 
113
- self._console.print("PEP8 check passed.", level=LogLevel.ERROR)
117
+ self._console.print("PEP8 check passed.", level=LogLevel.INFO)
114
118
  return True
115
119
  except FileNotFoundError:
116
120
  self._console.print("flake8 not found. Is it installed in the venv?", level=LogLevel.CRITICAL)
@@ -134,6 +138,7 @@ class FullRuleHandler(Rule):
134
138
  _console (Console): The console handler for logging.
135
139
  """
136
140
 
141
+ @log_initialization(level=LogLevel.TRACE)
137
142
  def __init__(self, config: FullRuleConfig, selector: Selector, constraint: Constraint, console: Console):
138
143
  """Initializes a full rule handler.
139
144
 
@@ -162,8 +167,8 @@ class FullRuleHandler(Rule):
162
167
  self._console.print("AST not available, skipping rule.", level=LogLevel.WARNING)
163
168
  return True
164
169
 
165
- self._console.print(f"Applying selector: {self._selector.__class__.__name__}", level=LogLevel.DEBUG)
170
+ self._console.print(f"Applying selector: {self._selector.__class__.__name__}", level=LogLevel.TRACE)
166
171
  selected_nodes = self._selector.select(tree)
167
172
 
168
- self._console.print(f"Applying constraint: {self._constraint.__class__.__name__}", level=LogLevel.DEBUG)
173
+ self._console.print(f"Applying constraint: {self._constraint.__class__.__name__}", level=LogLevel.TRACE)
169
174
  return self._constraint.check(selected_nodes)