in notebooks/notebook_template_review.py [0:0]
def validate(self, notebook: Notebook) -> bool:
"""
Parse the installation cells
"""
ret = True
cell = notebook.get()
if 'Install' not in cell['source'][0]:
return notebook.report_error(ErrorCode.ERROR_INSTALLATION_NOTFOUND, "Installation section not found")
if not cell['source'][0].startswith("## Install"):
ret = notebook.report_error(ErrorCode.ERROR_INSTALLATION_HEADING, "Installation section needs to be H2 heading")
cell = notebook.get()
if cell['cell_type'] != 'code':
ret = notebook.report_error(ErrorCode.ERROR_INSTALLATION_NOTFOUND, "Installation section not found")
else:
if cell['source'][0].startswith('! mkdir'):
cell = notebook.get()
if 'requirements.txt' in cell['source'][0]:
cell = notebook.get()
text = ''
for line in cell['source']:
text += line
if 'pip ' in line:
if 'pip3' not in line:
notebook.report_error(ErrorCode.ERROR_INSTALLATION_PIP3, "Installation code section: use pip3")
if line.endswith('\\\n'):
continue
if '-q' not in line and '--quiet' not in line :
notebook.report_error(ErrorCode.ERROR_INSTALLATION_QUIET, "Installation code section: use -q with pip3")
if 'USER_FLAG' not in line and 'sh(' not in line:
notebook.report_error(ErrorCode.ERROR_INSTALLATION_USER_FLAG, "Installation code section: use {USER_FLAG} with pip3")
if 'required_packages <' in text:
pass # R kernel
elif 'if IS_WORKBENCH_NOTEBOOK:' not in text:
ret = notebook.report_error(ErrorCode.ERROR_INSTALLATION_CODE_TEMPLATE, "Installation code section out of date (see template)")
return ret