Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quantum-kittens
GitHub Repository: quantum-kittens/platypus
Path: blob/main/scripts/content_checks/blips.py
3855 views
1
# This script checks that each quiz in NB_PATHS has a unique goal name, and that
2
# no notebook uses the internal provider
3
import os
4
from typing import List
5
6
7
NB_ROOT = './notebooks'
8
9
def check_file(filename: str, goal_names: List[str]) -> None:
10
with open(filename, encoding='utf-8') as f:
11
content: str = f.read()
12
for line in content.split('\n'):
13
if '(goal=\\"' in line:
14
name = line.split('"')[2].strip('\\')
15
if name in goal_names:
16
raise ValueError(
17
f'Found multiple quizzes with goal name "{name}"'
18
)
19
else:
20
goal_names.append(name)
21
22
if 'ibm-q-internal' in content:
23
raise ValueError(
24
f"Found use of non-open provider ('ibm-q-internal') in '{filename}',"
25
" please use 'ibm-q'."
26
)
27
28
29
if __name__ == '__main__':
30
goal_names: List[str] = []
31
for root, dirs, files in os.walk(NB_ROOT):
32
for name in files:
33
if name.endswith('-checkpoint.ipynb'):
34
continue
35
if name.endswith('.ipynb'):
36
check_file(os.path.join(root, name), goal_names)
37
38