Skip to content

Commit 28859f8

Browse files
authored
Merge pull request #395 from adrn/time-execute
Time notebook execution
2 parents 0d7a2ea + c3e242b commit 28859f8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

scripts/convert.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Standard library
22
from os import path, walk, remove, makedirs, sep
33
import re
4+
import time
45

56
# Third-party
67
from astropy import log as logger
@@ -86,6 +87,7 @@ def execute(self, write=True):
8687
# Execute the notebook
8788
logger.debug('Executing notebook using kwargs '
8889
'"{}"...'.format(self._execute_kwargs))
90+
t0 = time.time()
8991
executor = ExecutePreprocessor(**self._execute_kwargs)
9092

9193
with open(self.nb_path) as f:
@@ -97,6 +99,9 @@ def execute(self, write=True):
9799
# TODO: should we fail fast and raise, or record all errors?
98100
raise
99101

102+
logger.info("Finished running notebook ({:.2f} seconds)"
103+
.format(time.time() - t0))
104+
100105
if write:
101106
logger.debug('Writing executed notebook to file {0}...'
102107
.format(self._executed_nb_path))
@@ -188,7 +193,8 @@ def convert(self, remove_executed=False):
188193

189194
return output_file_path
190195

191-
def process_notebooks(nbfile_or_path, exec_only=False, **kwargs):
196+
def process_notebooks(nbfile_or_path, exec_only=False, verbosity=None,
197+
**kwargs):
192198
"""
193199
Execute and optionally convert the specified notebook file or directory of
194200
notebook files.
@@ -202,11 +208,17 @@ def process_notebooks(nbfile_or_path, exec_only=False, **kwargs):
202208
Either a single notebook filename or a path containing notebook files.
203209
exec_only : bool, optional
204210
Just execute the notebooks, don't run them.
211+
verbosity : int, optional
212+
A ``logging`` verbosity level, e.g., logging.DEBUG or etc. to specify
213+
the log level.
205214
**kwargs
206215
Any other keyword arguments are passed to the ``NBTutorialsConverter``
207216
init.
208217
209218
"""
219+
if verbosity is not None:
220+
logger.setLevel(verbosity)
221+
210222
if path.isdir(nbfile_or_path):
211223
# It's a path, so we need to walk through recursively and find any
212224
# notebook files

0 commit comments

Comments
 (0)