Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 72a8ec4

Browse files
committed
Handling potential plot_working_directory errors
Handling potential invalid directory path and invalid type errors.
1 parent e8a18a1 commit 72a8ec4

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,16 @@ def run_code(code, code_path, ns=None, function_name=None):
466466
pwd = os.getcwd()
467467
old_sys_path = list(sys.path)
468468
if setup.config.plot_working_directory is not None:
469-
os.chdir(setup.config.plot_working_directory)
469+
try:
470+
os.chdir(setup.config.plot_working_directory)
471+
except OSError as err:
472+
raise OSError(str(err) + '\n`plot_working_directory` option in'
473+
'Sphinx configuration file must be a valid '
474+
'directory path')
475+
except TypeError as err:
476+
raise TypeError(str(err) + '\n`plot_working_directory` option in '
477+
'Sphinx configuration file must be a string or '
478+
'None')
470479
sys.path.insert(0, setup.config.plot_working_directory)
471480
elif code_path is not None:
472481
dirname = os.path.abspath(os.path.dirname(code_path))

0 commit comments

Comments
 (0)