Path: blob/main/scripts/content_checks/blips.py
3855 views
# This script checks that each quiz in NB_PATHS has a unique goal name, and that1# no notebook uses the internal provider2import os3from typing import List456NB_ROOT = './notebooks'78def check_file(filename: str, goal_names: List[str]) -> None:9with open(filename, encoding='utf-8') as f:10content: str = f.read()11for line in content.split('\n'):12if '(goal=\\"' in line:13name = line.split('"')[2].strip('\\')14if name in goal_names:15raise ValueError(16f'Found multiple quizzes with goal name "{name}"'17)18else:19goal_names.append(name)2021if 'ibm-q-internal' in content:22raise ValueError(23f"Found use of non-open provider ('ibm-q-internal') in '{filename}',"24" please use 'ibm-q'."25)262728if __name__ == '__main__':29goal_names: List[str] = []30for root, dirs, files in os.walk(NB_ROOT):31for name in files:32if name.endswith('-checkpoint.ipynb'):33continue34if name.endswith('.ipynb'):35check_file(os.path.join(root, name), goal_names)363738