Permalink
Browse files

Handling potential plot_working_directory errors

Handling potential invalid directory path and invalid type errors.
  • Loading branch information...
1 parent e8a18a1 commit 72a8ec44bd3e9a665a6ae9be977a8c5acad9b372 @abakan abakan committed Jul 27, 2012
Showing with 10 additions and 1 deletion.
  1. +10 −1 lib/matplotlib/sphinxext/plot_directive.py
@@ -466,7 +466,16 @@ def run_code(code, code_path, ns=None, function_name=None):
pwd = os.getcwd()
old_sys_path = list(sys.path)
if setup.config.plot_working_directory is not None:
- os.chdir(setup.config.plot_working_directory)
+ try:
+ os.chdir(setup.config.plot_working_directory)
+ except OSError as err:
+ raise OSError(str(err) + '\n`plot_working_directory` option in'
+ 'Sphinx configuration file must be a valid '
+ 'directory path')
+ except TypeError as err:
+ raise TypeError(str(err) + '\n`plot_working_directory` option in '
+ 'Sphinx configuration file must be a string or '
+ 'None')
sys.path.insert(0, setup.config.plot_working_directory)
elif code_path is not None:
dirname = os.path.abspath(os.path.dirname(code_path))

0 comments on commit 72a8ec4

Please sign in to comment.