代码拉取完成,页面将自动刷新
import glob
import subprocess
import sys
import nbformat
from nbconvert.preprocessors import ExecutePreprocessor
def is_grid_search(notebook_path):
with open(notebook_path) as f:
nb = nbformat.read(f, as_version=4)
for cell in nb.cells:
if cell.cell_type == 'code' and 'perform_grid_search' in cell.source:
return True
return False
def run_notebook(notebook_path):
try:
with open(notebook_path) as f:
nb = nbformat.read(f, as_version=4)
ep = ExecutePreprocessor(timeout=600, kernel_name='python3')
ep.preprocess(nb, {'metadata': {'path': './'}})
return True
except Exception as e:
print(f"Error running {notebook_path}: {e}")
return False
def main():
notebooks = glob.glob('**/*.ipynb', recursive=True)
failing_notebooks = []
for notebook in notebooks:
if not is_grid_search(notebook):
print(f"Running {notebook}...")
if not run_notebook(notebook):
failing_notebooks.append(notebook)
else:
# TODO remove
print(f"Skipping {notebook} (grid search notebook)...")
if failing_notebooks:
print("Failing notebooks:")
for notebook in failing_notebooks:
print(notebook)
sys.exit(1)
else:
print("All notebooks ran successfully.")
sys.exit(0)
if __name__ == "__main__":
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。