@@ -45,7 +45,7 @@ def logger_debug(*args):
45
45
pass
46
46
47
47
48
- if TRACE or TRACE_DEEP or TRACE_TOK :
48
+ if TRACE or TRACE_TOK :
49
49
import logging
50
50
51
51
logger = logging .getLogger (__name__ )
@@ -55,6 +55,9 @@ def logger_debug(*args):
55
55
def logger_debug (* args ):
56
56
return logger .debug (' ' .join (isinstance (a , str ) and a or repr (a ) for a in args ))
57
57
58
+ if TRACE_DEEP :
59
+ logger_debug = print
60
+
58
61
"""
59
62
Detect and collect copyright statements.
60
63
@@ -175,13 +178,11 @@ def detect_copyrights_from_lines(
175
178
)
176
179
177
180
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 } ' )
185
186
186
187
detections = detector .detect (
187
188
numbered_lines = candidates ,
@@ -259,14 +260,17 @@ def detect(self,
259
260
# first, POS tag each token using token regexes
260
261
lexed_text = list (self .lexer .lex_tokens (tokens , trace = TRACE_TOK ))
261
262
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} ' )
264
267
265
268
# then build a parse parse_tree based on tagged tokens
266
269
parse_tree = self .parser .parse (lexed_text )
267
270
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 )} ' )
270
274
271
275
non_copyright_labels = frozenset ()
272
276
if not include_copyright_years :
@@ -316,8 +320,8 @@ def detect(self,
316
320
junk = COPYRIGHTS_JUNK ,
317
321
)
318
322
319
- if TRACE :
320
- logger_debug (f'CopyrightDetector: detection : { copyrght } ' )
323
+ if TRACE or TRACE_DEEP :
324
+ logger_debug (f'CopyrightDetector: final copyright : { copyrght } ' )
321
325
322
326
if copyrght :
323
327
if include_copyrights :
@@ -500,8 +504,6 @@ def build_detection_from_node(
500
504
else :
501
505
leaves = node .leaves ()
502
506
503
- # if TRACE_DEEP: logger_debug(' starting leaves:', leaves)
504
-
505
507
if include_copyright_allrights :
506
508
filtered = leaves
507
509
else :
@@ -3940,15 +3942,13 @@ def candidate_lines(numbered_lines):
3940
3942
3941
3943
if TRACE_TOK :
3942
3944
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} ' )
3945
3946
3946
3947
# the previous line (chars only)
3947
3948
previous_chars = None
3948
3949
for numbered_line in numbered_lines :
3949
3950
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} ' )
3952
3952
3953
3953
_line_number , line = numbered_line
3954
3954
@@ -3962,10 +3962,7 @@ def candidate_lines(numbered_lines):
3962
3962
3963
3963
if TRACE :
3964
3964
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 ' )
3969
3966
3970
3967
yield list (candidates )
3971
3968
candidates_clear ()
@@ -3978,7 +3975,8 @@ def candidate_lines(numbered_lines):
3978
3975
candidates_append (numbered_line )
3979
3976
3980
3977
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' )
3982
3980
3983
3981
elif 's>' in line :
3984
3982
# this is for debian-style <s></s> copyright name tags
@@ -4011,10 +4009,7 @@ def candidate_lines(numbered_lines):
4011
4009
# completely empty or only made of punctuations
4012
4010
if TRACE :
4013
4011
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 ' )
4018
4013
4019
4014
yield list (candidates )
4020
4015
candidates_clear ()
@@ -4031,10 +4026,7 @@ def candidate_lines(numbered_lines):
4031
4026
elif candidates :
4032
4027
if TRACE :
4033
4028
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 ' )
4038
4030
4039
4031
yield list (candidates )
4040
4032
candidates_clear ()
@@ -4045,10 +4037,7 @@ def candidate_lines(numbered_lines):
4045
4037
if candidates :
4046
4038
if TRACE :
4047
4039
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 ' )
4052
4041
4053
4042
yield list (candidates )
4054
4043
0 commit comments