Skip to content

Commit 1e669cf

Browse files
committed
Improve copyright tracing
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent 8cd3796 commit 1e669cf

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

src/cluecode/copyrights.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,12 @@ def detect_copyrights_from_lines(
175175
)
176176

177177
for candidates in candidate_lines_groups:
178-
if TRACE:
179-
from pprint import pformat
180-
can = pformat(candidates, width=160)
181-
logger_debug(
182-
f' detect_copyrights_from_lines: processing candidates group:\n'
183-
f' {can}'
184-
)
178+
if TRACE or TRACE_DEEP:
179+
logger_debug(f'========================================================================')
180+
logger_debug(f' detect_copyrights_from_lines: processing candidates group:')
181+
for can in candidates:
182+
logger_debug(f' {can}')
183+
185184

186185
detections = detector.detect(
187186
numbered_lines=candidates,
@@ -246,27 +245,27 @@ def detect(self,
246245
return
247246

248247
if TRACE or TRACE_TOK:
249-
logger_debug(f'CopyrightDetector: numbered_lines: {numbered_lines}')
248+
logger_debug(f' CopyrightDetector: numbered_lines: {numbered_lines}')
250249

251250
tokens = list(get_tokens(numbered_lines))
252251

253252
if TRACE:
254-
logger_debug(f'CopyrightDetector: initial tokens: {tokens}')
253+
logger_debug(f' CopyrightDetector: initial tokens: {tokens}')
255254

256255
if not tokens:
257256
return
258257

259258
# first, POS tag each token using token regexes
260259
lexed_text = list(self.lexer.lex_tokens(tokens, trace=TRACE_TOK))
261260

262-
if TRACE:
263-
logger_debug(f'CopyrightDetector: lexed tokens: {lexed_text}')
261+
if TRACE or TRACE_DEEP:
262+
logger_debug(f' CopyrightDetector: lexed tokens:\n{lexed_text}')
264263

265264
# then build a parse parse_tree based on tagged tokens
266265
parse_tree = self.parser.parse(lexed_text)
267266

268-
if TRACE:
269-
logger_debug(f'CopyrightDetector: parse_tree:\n{tree_pformat(parse_tree)}')
267+
if TRACE or TRACE_DEEP:
268+
logger_debug(f' CopyrightDetector: final parse_tree:\n{tree_pformat(parse_tree)}')
270269

271270
non_copyright_labels = frozenset()
272271
if not include_copyright_years:
@@ -312,7 +311,7 @@ def detect(self,
312311
junk=COPYRIGHTS_JUNK,
313312
)
314313

315-
if TRACE:
314+
if TRACE or TRACE_DEEP:
316315
logger_debug(f'CopyrightDetector: detection: {copyrght}')
317316

318317
if copyrght:
@@ -3879,15 +3878,13 @@ def candidate_lines(numbered_lines):
38793878

38803879
if TRACE_TOK:
38813880
numbered_lines = list(numbered_lines)
3882-
logger_debug(
3883-
f'candidate_lines: numbered_lines: {numbered_lines!r}')
3881+
logger_debug(f'candidate_lines: numbered_lines: {numbered_lines!r}')
38843882

38853883
# the previous line (chars only)
38863884
previous_chars = None
38873885
for numbered_line in numbered_lines:
38883886
if TRACE:
3889-
logger_debug(
3890-
f'# candidate_lines: evaluating line: {numbered_line!r}')
3887+
logger_debug(f'# candidate_lines: evaluating line: {numbered_line!r}')
38913888

38923889
_line_number, line = numbered_line
38933890

0 commit comments

Comments
 (0)