diff --git a/sphinx/environment.py b/sphinx/environment.py index 8d0789cfa..9e5a870a4 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -40,7 +40,7 @@ from sphinx import addnodes from sphinx.util import url_re, get_matching_docs, docname_join, split_into, \ FilenameUniqDict, get_figtype, import_object, split_index_msg from sphinx.util.nodes import clean_astext, make_refnode, WarningStream, is_translatable -from sphinx.util.osutil import SEP, getcwd, fs_encoding +from sphinx.util.osutil import SEP, getcwd, fs_encoding, ensuredir from sphinx.util.i18n import find_catalog_files from sphinx.util.console import bold, purple from sphinx.util.matching import compile_matchers @@ -855,9 +855,7 @@ class BuildEnvironment: # save the parsed doctree doctree_filename = self.doc2path(docname, self.doctreedir, '.doctree') - dirname = path.dirname(doctree_filename) - if not path.isdir(dirname): - os.makedirs(dirname) + ensuredir(path.dirname(doctree_filename)) f = open(doctree_filename, 'wb') try: pickle.dump(doctree, f, pickle.HIGHEST_PROTOCOL)