in cdk-project/lib/images/codebuild-image/python/src/notebooks/parse.py [0:0]
def contains_code(notebook, regex_list):
"""Check whether a notebook contains any of a list of code snippets in any of its code cells.
Args:
notebook (Path): The notebook to check for code snippets.
regex_list ([str]): The list of regexes to check for.
Returns:
bool: Whether any of the code snippets exist in the notebook's code cells.
"""
source = code_cells(notebook)
for cell_source in source:
for line in cell_source:
# Ignore comments
if line.startswith('#'):
continue
# if the line contains any of the regexes, return True
for regex in regex_list:
if re.search(regex, line, re.IGNORECASE):
return True
return False