From ec4d0d7fd4fb13c98689f0e7f41648eefce84336 Mon Sep 17 00:00:00 2001 From: Daniel Clarke Date: Mon, 23 Nov 2020 16:56:55 -0500 Subject: [PATCH] Ensure notebooks are cleaned in PRs Fixes #436 --- validate/requirements.txt | 1 + validate/validate_merge.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/validate/requirements.txt b/validate/requirements.txt index df589e98a..d009fd7e8 100644 --- a/validate/requirements.txt +++ b/validate/requirements.txt @@ -1,4 +1,5 @@ click git+git://github.com/Maayanlab/appyter.git jsonschema +nbformat Pillow \ No newline at end of file diff --git a/validate/validate_merge.py b/validate/validate_merge.py index 7da92439e..f940725bd 100644 --- a/validate/validate_merge.py +++ b/validate/validate_merge.py @@ -3,6 +3,7 @@ import sys import json import click +import nbformat as nbf import traceback import jsonschema import urllib.request, urllib.error @@ -79,6 +80,16 @@ def validate_appyter(appyter): # nbfile = config['appyter']['file'] # + print(f"{appyter}: Checking notebook for issues..") + nb = nbf.read(open(nbfile, 'r'), as_version=4) + for cell in nb.cells: + if cell['cell_type'] == 'code': + assert not cell.get('execution_count'), "Please clear all notebook output & metadata" + assert not cell.get('metadata'), "Please clear all notebook output & metadata" + assert not cell.get('outputs'), "Please clear all notebook output & metadata" + assert not nb['metadata'].get('widgets'), "Please clear all notebook output & metadata" + assert not nb['metadata'].get('execution_info'), "Please clear all notebook output & metadata" + # print(f"{appyter}: Preparing docker to run `{nbfile}`...") assert os.path.isfile(os.path.join('appyters', appyter, nbfile)), f"Missing appyters/{appyter}/{nbfile}" try: