Skip to content

Commit eb35a6c

Browse files
authored
Merge pull request #2419 from jelmer/slim-licensedcode
Allow calling copyright detection from text lines
2 parents 2e69fc2 + f4a58ad commit eb35a6c

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/cluecode/copyrights.py

+26-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from cluecode import copyrights_hint
1818
from commoncode.text import toascii
1919
from commoncode.text import unixlinesep
20-
from textcode import analysis
2120

2221
# Tracing flags
2322
TRACE = False or os.environ.get('SCANCODE_DEBUG_COPYRIGHT', False)
@@ -60,6 +59,7 @@ def logger_debug(*args):
6059

6160
def detect_copyrights(location, copyrights=True, holders=True, authors=True,
6261
include_years=True, include_allrights=False,
62+
demarkup=True,
6363
deadline=sys.maxsize):
6464
"""
6565
Yield tuples of (detection type, detected string, start line, end line)
@@ -68,14 +68,36 @@ def detect_copyrights(location, copyrights=True, holders=True, authors=True,
6868
Valid detection types are: copyrights, authors, holders.
6969
These are included in the yielded tuples based on the values of `copyrights=True`, `holders=True`, `authors=True`,
7070
"""
71-
detector = CopyrightDetector()
72-
numbered_lines = analysis.numbered_text_lines(location, demarkup=True)
71+
from textcode.analysis import numbered_text_lines
72+
numbered_lines = numbered_text_lines(location, demarkup=demarkup)
7373
numbered_lines = list(numbered_lines)
7474
if TRACE:
7575
numbered_lines = list(numbered_lines)
7676
for nl in numbered_lines:
7777
logger_debug('numbered_line:', repr(nl))
7878

79+
yield from detect_copyrights_from_lines(
80+
numbered_lines,
81+
copyrights=copyrights,
82+
holders=holders,
83+
authors=authors,
84+
include_years=include_years,
85+
include_allrights=include_allrights,
86+
deadline=deadline)
87+
88+
89+
def detect_copyrights_from_lines(numbered_lines, copyrights=True, holders=True, authors=True,
90+
include_years=True, include_allrights=False,
91+
deadline=sys.maxsize):
92+
"""
93+
Yield tuples of (detection type, detected string, start line, end line)
94+
detected in numbered lines
95+
Include years in copyrights if include_years is True.
96+
Valid detection types are: copyrights, authors, holders.
97+
These are included in the yielded tuples based on the values of `copyrights=True`, `holders=True`, `authors=True`,
98+
"""
99+
detector = CopyrightDetector()
100+
79101
for candidates in candidate_lines(numbered_lines):
80102

81103
detections = detector.detect(
@@ -93,6 +115,7 @@ def detect_copyrights(location, copyrights=True, holders=True, authors=True,
93115
if time() > deadline:
94116
break
95117

118+
96119
################################################################################
97120
# DETECTION PROPER
98121
################################################################################

0 commit comments

Comments
 (0)