11""" Functions for running Jupyter Notebooks programmatically."""
2- #pylint: disable=import-outside-toplevel
32import os
43import time
54import json
109import psutil
1110
1211
13- TMP_DIR = '/tmp/nbtools_exec_notebook'
12+ TMP_DIR = '/tmp/nbtools_exec_notebook' # noqa: S108
1413os .makedirs (TMP_DIR , exist_ok = True )
1514
1615
@@ -19,7 +18,6 @@ def run_in_process(func):
1918 """ Decorator to run the ``func`` in a separate process for terminating all related processes properly. """
2019 @wraps (func )
2120 def _wrapper (* args , ** kwargs ):
22- # pylint: disable=broad-exception-caught, broad-exception-raised
2321 _output_queue = Queue ()
2422 kwargs = {** kwargs , '_output_queue' : _output_queue }
2523
@@ -39,7 +37,7 @@ def _wrapper(*args, **kwargs):
3937
4038 output = _output_queue .get ()
4139 process .join ()
42- except (KeyboardInterrupt , Exception ) as e :
40+ except (KeyboardInterrupt , Exception ) as e : # noqa: BLE001
4341 output = {'failed' : True , 'traceback' : e }
4442
4543 # Terminate all relevant processes when something went wrong, e.g. Keyboard Interrupt
@@ -245,7 +243,6 @@ def exec_notebook(path, inputs=None, outputs=None, inputs_pos=1, replace_inputs_
245243 - ``'notebook'`` : :class:`nbformat.notebooknode.NotebookNode`, optional
246244 Executed notebook object. Note that this output is provided only if ``return_notebook`` is ``True``.
247245 """
248- # pylint: disable=bare-except, lost-exception, return-in-finally
249246 import nbformat
250247 from jupyter_client .manager import KernelManager
251248 from nbconvert .preprocessors import ExecutePreprocessor
@@ -321,7 +318,7 @@ def exec_notebook(path, inputs=None, outputs=None, inputs_pos=1, replace_inputs_
321318 exec_failed = False
322319 try :
323320 executor .preprocess (notebook , {'metadata' : {'path' : working_dir }}, km = kernel_manager )
324- except :
321+ except : # noqa: E722
325322 exec_failed = True
326323
327324 # Save notebook outputs in the shelve db
@@ -359,7 +356,7 @@ def exec_notebook(path, inputs=None, outputs=None, inputs_pos=1, replace_inputs_
359356 # Re-raise exception if needed
360357 if raise_exception :
361358 _output_queue .put (exec_res )
362- return None
359+ return None # noqa: RET501
363360 else :
364361 exec_res = {'failed' : failed , 'failed cell number' : None , 'traceback' : '' }
365362
@@ -397,7 +394,7 @@ def exec_notebook(path, inputs=None, outputs=None, inputs_pos=1, replace_inputs_
397394 exec_res ['notebook' ] = notebook
398395
399396 _output_queue .put (exec_res ) # return for parent process
400- return None
397+ return None # noqa: RET501
401398
402399# Functions for database operations cells masking
403400def _display_inputs_reading (notebook , pos ):
0 commit comments