Skip to content

Commit 1fc7cea

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

File tree

1 file changed

+26
-37
lines changed

1 file changed

+26
-37
lines changed

src/cluecode/copyrights.py

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def logger_debug(*args):
4545
pass
4646

4747

48-
if TRACE or TRACE_DEEP or TRACE_TOK:
48+
if TRACE or TRACE_TOK:
4949
import logging
5050

5151
logger = logging.getLogger(__name__)
@@ -55,6 +55,9 @@ def logger_debug(*args):
5555
def logger_debug(*args):
5656
return logger.debug(' '.join(isinstance(a, str) and a or repr(a) for a in args))
5757

58+
if TRACE_DEEP:
59+
logger_debug = print
60+
5861
"""
5962
Detect and collect copyright statements.
6063
@@ -175,13 +178,11 @@ def detect_copyrights_from_lines(
175178
)
176179

177180
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-
)
181+
if TRACE or TRACE_DEEP:
182+
logger_debug(f'\n========================================================================')
183+
logger_debug(f'detect_copyrights_from_lines: processing candidates group:')
184+
for can in candidates:
185+
logger_debug(f' {can}')
185186

186187
detections = detector.detect(
187188
numbered_lines=candidates,
@@ -259,14 +260,17 @@ def detect(self,
259260
# first, POS tag each token using token regexes
260261
lexed_text = list(self.lexer.lex_tokens(tokens, trace=TRACE_TOK))
261262

262-
if TRACE:
263-
logger_debug(f'CopyrightDetector: lexed tokens: {lexed_text}')
263+
if TRACE or TRACE_DEEP:
264+
logger_debug(f'CopyrightDetector: lexed tokens:')
265+
for l in lexed_text:
266+
logger_debug(f' {l!r}')
264267

265268
# then build a parse parse_tree based on tagged tokens
266269
parse_tree = self.parser.parse(lexed_text)
267270

268-
if TRACE:
269-
logger_debug(f'CopyrightDetector: parse_tree:\n{tree_pformat(parse_tree)}')
271+
if TRACE or TRACE_DEEP:
272+
logger_debug('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
273+
logger_debug(f'CopyrightDetector: final parse_tree:\n{tree_pformat(parse_tree)}')
270274

271275
non_copyright_labels = frozenset()
272276
if not include_copyright_years:
@@ -316,8 +320,8 @@ def detect(self,
316320
junk=COPYRIGHTS_JUNK,
317321
)
318322

319-
if TRACE:
320-
logger_debug(f'CopyrightDetector: detection: {copyrght}')
323+
if TRACE or TRACE_DEEP:
324+
logger_debug(f'CopyrightDetector: final copyright: {copyrght}')
321325

322326
if copyrght:
323327
if include_copyrights:
@@ -500,8 +504,6 @@ def build_detection_from_node(
500504
else:
501505
leaves = node.leaves()
502506

503-
# if TRACE_DEEP: logger_debug(' starting leaves:', leaves)
504-
505507
if include_copyright_allrights:
506508
filtered = leaves
507509
else:
@@ -3940,15 +3942,13 @@ def candidate_lines(numbered_lines):
39403942

39413943
if TRACE_TOK:
39423944
numbered_lines = list(numbered_lines)
3943-
logger_debug(
3944-
f'candidate_lines: numbered_lines: {numbered_lines!r}')
3945+
logger_debug(f'candidate_lines: numbered_lines: {numbered_lines!r}')
39453946

39463947
# the previous line (chars only)
39473948
previous_chars = None
39483949
for numbered_line in numbered_lines:
39493950
if TRACE:
3950-
logger_debug(
3951-
f'# candidate_lines: evaluating line: {numbered_line!r}')
3951+
logger_debug(f'# candidate_lines: evaluating line: {numbered_line!r}')
39523952

39533953
_line_number, line = numbered_line
39543954

@@ -3962,10 +3962,7 @@ def candidate_lines(numbered_lines):
39623962

39633963
if TRACE:
39643964
cands = list(candidates)
3965-
logger_debug(
3966-
' candidate_lines: is EOS: yielding candidates\n'
3967-
f' {cands}r\n\n'
3968-
)
3965+
logger_debug(f' candidate_lines: is EOS: yielding candidates\n {cands!r}\n')
39693966

39703967
yield list(candidates)
39713968
candidates_clear()
@@ -3978,7 +3975,8 @@ def candidate_lines(numbered_lines):
39783975
candidates_append(numbered_line)
39793976

39803977
previous_chars = chars_only
3981-
if TRACE: logger_debug(' candidate_lines: line is candidate')
3978+
if TRACE:
3979+
logger_debug(' candidate_lines: line is candidate')
39823980

39833981
elif 's>' in line:
39843982
# this is for debian-style <s></s> copyright name tags
@@ -4011,10 +4009,7 @@ def candidate_lines(numbered_lines):
40114009
# completely empty or only made of punctuations
40124010
if TRACE:
40134011
cands = list(candidates)
4014-
logger_debug(
4015-
' candidate_lines: empty: yielding candidates\n'
4016-
f' {cands}r\n\n'
4017-
)
4012+
logger_debug(f' candidate_lines: empty: yielding candidates\n {cands!r}\n')
40184013

40194014
yield list(candidates)
40204015
candidates_clear()
@@ -4031,10 +4026,7 @@ def candidate_lines(numbered_lines):
40314026
elif candidates:
40324027
if TRACE:
40334028
cands = list(candidates)
4034-
logger_debug(
4035-
' candidate_lines: not in COP: yielding candidates\n'
4036-
f' {cands}r\n\n'
4037-
)
4029+
logger_debug(f' candidate_lines: not in COP: yielding candidates\n {cands!r}\n')
40384030

40394031
yield list(candidates)
40404032
candidates_clear()
@@ -4045,10 +4037,7 @@ def candidate_lines(numbered_lines):
40454037
if candidates:
40464038
if TRACE:
40474039
cands = list(candidates)
4048-
logger_debug(
4049-
'candidate_lines: finally yielding candidates\n'
4050-
f' {cands}r\n\n'
4051-
)
4040+
logger_debug(f'candidate_lines: finally yielding candidates\n {cands!r}\n')
40524041

40534042
yield list(candidates)
40544043

0 commit comments

Comments
 (0)