-
Notifications
You must be signed in to change notification settings - Fork 436
Expand file tree
/
Copy pathnbvalNotebook.py
More file actions
105 lines (87 loc) · 2.9 KB
/
nbvalNotebook.py
File metadata and controls
105 lines (87 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
'''
Run tests of notebooks using nbval -- called from testDocumentation
Created on May 24, 2017
@author: cuthbert
'''
from __future__ import annotations
import pathlib # for typing
import sys
import subprocess
# noinspection PyPackageRequirements
try:
import pytest
except ImportError: # pragma: no cover
# fail here to get a better message than file-not-found below.
raise ImportError(
'Please install pytest -- in the music21 directory run "pip install ".[dev]"'
)
# noinspection PyPackageRequirements
try:
import nbval
except ImportError: # pragma: no cover
raise ImportError(
'Please install nbval -- in the music21 directory run "pip install ".[dev]"'
)
from music21 import environment
from music21 import common
if pytest is None or nbval is None: # pragma: no cover
# this will never run, but it's important to use pytest and nbval variables
# or some modern code linters will remove the import pytest, import nbval lines.
raise ImportError('Please install pytest and nbval')
# pytest --nbval usersGuide_15_key.ipynb --nbval-sanitize-with ../../nbval-sanitize.cfg -q
skip = ['installJupyter.ipynb']
def getAllFiles() -> list[pathlib.Path]:
sourcePath = common.getRootFilePath() / 'documentation' / 'source'
goodFiles = []
for innerDir in ('about', 'developerReference', 'installing', 'usersGuide'):
fullDir = sourcePath / innerDir
for f in sorted(fullDir.rglob('*.ipynb')):
if f.name in skip:
continue
if 'checkpoint' in str(f):
continue
goodFiles.append(f)
return goodFiles
def runAll():
for f in getAllFiles():
print('Running: ', str(f))
try:
retVal = runOne(f)
except KeyboardInterrupt:
break
if retVal == 512:
return None
def findAndRun(filename: str):
allFiles = getAllFiles()
for f in allFiles:
if filename in str(f):
runOne(f)
def runOne(nbFile):
us = environment.UserSettings()
museScore = us['musescoreDirectPNGPath']
us['musescoreDirectPNGPath'] = '/skip' + str(museScore)
# this config file changes 0x39f3a0 to 0xADDRESS.
sanitize_fn = str(common.getRootFilePath()
/ 'documentation'
/ 'docbuild'
/ 'nbval-sanitize.cfg'
)
try:
retVal = subprocess.run(
['pytest',
'--disable-pytest-warnings',
'--nbval', str(nbFile),
'--nbval-sanitize-with', sanitize_fn,
'-q'],
check=False,
)
# except (Exception, KeyboardInterrupt): # specifically looking at KeyboardInterrupt.
# raise
finally:
us['musescoreDirectPNGPath'] = museScore
return retVal
if __name__ == '__main__':
if len(sys.argv) > 1:
runOne(sys.argv[1])
else:
runAll()