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

Function get_generated_code_hint

src/summarycode/generated.py:212–233  ·  view source on GitHub ↗

Return a line of extracted text from a file if that file is likely generated source code. for each of the first few lines of a source code file if generated keywords are found in the line as lowercase yield the line text as a 'potentially_ generated' annotation

(
    location,
    max_lines=150,
    generated_keywords=GENERATED_KEYWORDS_LOWERED
)

Source from the content-addressed store, hash-verified

210
211
212def get_generated_code_hint(
213 location,
214 max_lines=150,
215 generated_keywords=GENERATED_KEYWORDS_LOWERED
216):
217 """
218 Return a line of extracted text from a file if that file is likely
219 generated source code.
220
221 for each of the first few lines of a source code file
222 if generated keywords are found in the line as lowercase
223 yield the line text as a 'potentially_ generated' annotation
224 """
225 T = typecode.contenttype.get_type(location)
226 if not T.is_text:
227 return
228 with open(location, 'rb') as filein:
229 for line in islice(filein, max_lines):
230 text = toascii(line.strip()).lower()
231 if any(kw in text.lower() for kw in generated_keywords):
232 # yield only the first 100 chars..
233 yield text[:100]
234

Callers 1

generated_scannerFunction · 0.85

Calls 2

toasciiFunction · 0.90
get_typeMethod · 0.80

Tested by

no test coverage detected