MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / detect_copyrights_from_lines

Function detect_copyrights_from_lines

src/cluecode/copyrights.py:153–224  ·  view source on GitHub ↗

Yield Detection objects detected in a ``numbered_lines`` sequence of tuples of (line number, text). The flags ``include_copyrights``, ``include_holders`` and ``include_authors`` drive which actual detections are done and returned. For copyrights only: - If ``include_copyri

(
    numbered_lines,
    include_copyrights=True,
    include_holders=True,
    include_authors=True,
    include_copyright_years=True,
    include_copyright_allrights=False,
    deadline=sys.maxsize,
)

Source from the content-addressed store, hash-verified

151
152
153def detect_copyrights_from_lines(
154 numbered_lines,
155 include_copyrights=True,
156 include_holders=True,
157 include_authors=True,
158 include_copyright_years=True,
159 include_copyright_allrights=False,
160 deadline=sys.maxsize,
161):
162 """
163 Yield Detection objects detected in a ``numbered_lines`` sequence of
164 tuples of (line number, text).
165
166 The flags ``include_copyrights``, ``include_holders`` and
167 ``include_authors`` drive which actual detections are done and returned.
168
169 For copyrights only:
170 - If ``include_copyright_years`` is True, include years and year ranges.
171 - If ``include_copyright_allrights`` is True, include trailing
172 "all rights reserved"-style mentions
173
174 Run for up to ``deadline`` seconds and return results found so far.
175 """
176 if not numbered_lines:
177 return
178
179 include_copyright_years = include_copyrights and include_copyright_years
180 include_copyright_allrights = include_copyrights and include_copyright_allrights
181
182 global DETECTOR
183
184 if not DETECTOR:
185 DETECTOR = detector = CopyrightDetector()
186 else:
187 detector = DETECTOR
188
189 candidate_lines_groups = list(collect_candidate_lines(numbered_lines))
190
191 if TRACE or TRACE_TOK:
192 candidate_lines_groups = candidate_lines_groups
193 logger_debug(
194 f'detect_copyrights_from_lines: ALL groups of candidate '
195 f'lines collected: {len(candidate_lines_groups)}',
196 )
197
198 for candidate_lines in candidate_lines_groups:
199 if TRACE or TRACE_DEEP:
200 logger_debug(f'\n========================================================================')
201 logger_debug(f'detect_copyrights_from_lines: processing candidate_lines group:')
202
203 for can in candidate_lines:
204 logger_debug(f' {can}')
205
206 detections = detector.detect(
207 numbered_lines=candidate_lines,
208 include_copyrights=include_copyrights,
209 include_holders=include_holders,
210 include_authors=include_authors,

Callers 3

get_ignorablesFunction · 0.90
detect_copyrightsFunction · 0.85

Calls 4

detectMethod · 0.95
CopyrightDetectorClass · 0.85
collect_candidate_linesFunction · 0.85
logger_debugFunction · 0.70

Tested by

no test coverage detected