From ee28d64eb96a0370170953bf8dd91ad0fce0e0f3 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Sun, 31 Mar 2024 16:51:27 +0100 Subject: [PATCH] Avoid `RemovedInSphinx80Warning` in path-manipulation code. In recent versions of Sphinx, code that treats Sphinx application paths such as `Sphinx.confdir` and `Sphinx.doctreedir` as strings emits the warning "Sphinx 8 will drop support for representing paths as strings". This commit updates path-manipulation code to use functions in the `os.path` module, which accept path-like objects as well as strings. This fixes issue #974. --- breathe/project.py | 5 ++--- breathe/renderer/sphinxrenderer.py | 9 +++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/breathe/project.py b/breathe/project.py index 865236e8..5c2b65d3 100644 --- a/breathe/project.py +++ b/breathe/project.py @@ -110,10 +110,9 @@ def __init__(self, app: Sphinx): self.app = app # note: don't access self.app.config now, as we are instantiated at setup-time. - # Assume general build directory is the doctree directory without the last component. - # We strip off any trailing slashes so that dirname correctly drops the last part. + # Assume general build directory is the parent of the doctree directory. # This can be overridden with the breathe_build_directory config variable - self._default_build_dir = os.path.dirname(app.doctreedir.rstrip(os.sep)) + self._default_build_dir = os.path.dirname(os.path.normpath(app.doctreedir)) self.project_count = 0 self.project_info_store: Dict[str, ProjectInfo] = {} self.project_info_for_auto_store: Dict[str, AutoProjectInfo] = {} diff --git a/breathe/renderer/sphinxrenderer.py b/breathe/renderer/sphinxrenderer.py index dff0c982..a87fe0f2 100644 --- a/breathe/renderer/sphinxrenderer.py +++ b/breathe/renderer/sphinxrenderer.py @@ -2402,12 +2402,9 @@ def visit_docdotfile(self, node) -> List[Node]: # Use self.project_info.project_path as the XML_OUTPUT path, and # make it absolute with consideration to the conf.py path project_path = self.project_info.project_path() - if os.path.isabs(project_path): - dot_file_path = os.path.abspath(project_path + os.sep + dot_file_path) - else: - dot_file_path = os.path.abspath( - self.app.confdir + os.sep + project_path + os.sep + dot_file_path - ) + dot_file_path = os.path.abspath( + os.path.join(self.app.confdir, project_path, dot_file_path) + ) try: with open(dot_file_path, encoding="utf-8") as fp: dotcode = fp.read()