From ce41a5e3f005dad05f1ddfcca8f94bc77fe12881 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 9 Jan 2022 04:04:31 +0900 Subject: [PATCH] Close #10055: sphinx-build: Create directories when `-w` option given --- CHANGES | 1 + sphinx/cmd/build.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGES b/CHANGES index 6ce3e51f3d0..7e41bb99ef0 100644 --- a/CHANGES +++ b/CHANGES @@ -37,6 +37,7 @@ Features added checking in matched documents. * #9793: sphinx-build: Allow to use the parallel build feature in macOS on macOS and Python3.8+ +* #10055: sphinx-build: Create directories when ``-w`` option given * #9993: std domain: Allow to refer an inline target (ex. ``_`target name```) via :rst:role:`ref` role * #9391: texinfo: improve variable in ``samp`` role diff --git a/sphinx/cmd/build.py b/sphinx/cmd/build.py index 77e3cd44fa5..8de24a364f0 100644 --- a/sphinx/cmd/build.py +++ b/sphinx/cmd/build.py @@ -16,6 +16,7 @@ import pdb import sys import traceback +from os import path from typing import IO, Any, List from docutils.utils import SystemMessage @@ -28,6 +29,7 @@ from sphinx.util import Tee, format_exception_cut_frames, save_traceback from sphinx.util.console import color_terminal, nocolor, red, terminal_safe # type: ignore from sphinx.util.docutils import docutils_namespace, patch_docutils +from sphinx.util.osutil import abspath, ensuredir def handle_exception(app: Sphinx, args: Any, exception: BaseException, stderr: IO = sys.stderr) -> None: # NOQA @@ -240,6 +242,8 @@ def build_main(argv: List[str] = sys.argv[1:]) -> int: if warning and args.warnfile: try: + warnfile = abspath(args.warnfile) + ensuredir(path.dirname(warnfile)) warnfp = open(args.warnfile, 'w') except Exception as exc: parser.error(__('cannot open warning file %r: %s') % (