8000 Small cleanups to sphinxext.plot_directive. · matplotlib/matplotlib@6be4ab9 · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6be4ab9

Browse files
committed
Small cleanups to sphinxext.plot_directive.
1 parent 87b9118 commit 6be4ab9

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -589,10 +589,7 @@ def render_figures(code, code_path, output_dir, output_base, context,
589589
# We didn't find the files, so build them
590590

591591
results = []
592-
if context:
593-
ns = plot_context
594-
else:
595-
ns = {}
592+
ns = plot_context if context else {}
596593

597594
if context_reset:
598595
clear_state(config.plot_rcparams)
@@ -717,9 +714,7 @@ def run(arguments, content, options, state_machine, state, lineno):
717714

718715
# determine output directory name fragment
719716
source_rel_name = relpath(source_file_name, setup.confdir)
720-
source_rel_dir = os.path.dirname(source_rel_name)
721-
while source_rel_dir.startswith(os.path.sep):
722-
source_rel_dir = source_rel_dir[1:]
717+
source_rel_dir = os.path.dirname(source_rel_name).lstrip(os.path.sep)
723718

724719
# build_dir: where to place output files (temporarily)
725720
build_dir = os.path.join(os.path.dirname(setup.app.doctreedir),
@@ -729,15 +724,12 @@ def run(arguments, content, options, state_machine, state, lineno):
729724
# see note in Python docs for warning about symbolic links on Windows.
730725
# need to compare source and dest paths at end
731726
build_dir = os.path.normpath(build_dir)
732-
733-
if not os.path.exists(build_dir):
734-
os.makedirs(build_dir)
727+
os.makedirs(build_dir, exist_ok=True)
735728

736729
# output_dir: final location in the builder's directory
737730
dest_dir = os.path.abspath(os.path.join(setup.app.builder.outdir,
738731
source_rel_dir))
739-
if not os.path.exists(dest_dir):
740-
os.makedirs(dest_dir) # no problem here for me, but just use built-ins
732+
os.makedirs(dest_dir, exist_ok=True)
741733

742734
# how to link to files from the RST file
743735
dest_dir_link = os.path.join(relpath(setup.confdir, rst_dir),

0 commit comments

Comments
 (0)
0