Skip to contentSkip to conversation

docs/sphinx/depfile.py: Handle env.doc2path() returning a Path not a str

PATCH In review Peter Maydell 2 participants 3 messages Jul 29, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 docs/sphinx/depfile.py: Handle env.doc2path() returning a Path not a str

In newer versions of Sphinx the env.doc2path() API is going to change to return a Path object rather than a str. This was originally visible in Sphinx 8.0.0rc1, but has been rolled back for the final 8.0.0 release. However it will probably emit a deprecation warning and is likely to change for good in 9.0:
https://github.com/sphinx-doc/sphinx/issues/12686

Our use in depfile.py assumes a str, and if it is passed a Path
it will fall over:
Handler <function write_depfile at 0x77a1775ff560> for event 'build-finished' threw an exception (exception: unsupported operand type(s) for +: 'PosixPath' and 'str')

Wrapping the env.doc2path() call in str() will coerce a Path object to the str we expect, and have no effect in older Sphinx versions that do return a str.

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2458

---
 docs/sphinx/depfile.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
docs/sphinx/depfile.py +1 -1
index afdcbcec6e7..e74be6af98b 100644
@@ -19,7 +19,7 @@
 
 def get_infiles(env):
     for x in env.found_docs:
-        yield env.doc2path(x)
+        yield str(env.doc2path(x))
         yield from ((os.path.join(env.srcdir, dep)
                     for dep in env.dependencies[x]))
     for mod in sys.modules.values():
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Peter Maydell

In newer versions of Sphinx the env.doc2path() API is going to change to return a Path object rather than a str. This was originally visible in Sphinx 8.0.0rc1, but has been rolled back for the final 8.0.0 release. However it will probably emit a deprecation warning and is likely to change for good in 9.0:

   https://github.com/sphinx-doc/sphinx/issues/12686

Our use in depfile.py assumes a str, and if it is passed a Path
it will fall over:
Handler <function write_depfile at 0x77a1775ff560> for event 'build-finished' threw an exception (exception: unsupported operand type(s) for +: 'PosixPath' and 'str')

Wrapping the env.doc2path() call in str() will coerce a Path object to the str we expect, and have no effect in older Sphinx versions that do return a str.

Quoted 6 lines

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2458

---
  docs/sphinx/depfile.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
#2 lore raw
Quoted 16 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Peter Maydell

In newer versions of Sphinx the env.doc2path() API is going to change to return a Path object rather than a str. This was originally visible in Sphinx 8.0.0rc1, but has been rolled back for the final 8.0.0 release. However it will probably emit a deprecation warning and is likely to change for good in 9.0:
   https://github.com/sphinx-doc/sphinx/issues/12686

Our use in depfile.py assumes a str, and if it is passed a Path
it will fall over:
  Handler <function write_depfile at 0x77a1775ff560> for event 'build-finished' threw an exception (exception: unsupported operand type(s) for +: 'PosixPath' and 'str')

Wrapping the env.doc2path() call in str() will coerce a Path object to the str we expect, and have no effect in older Sphinx versions that do return a str.

Quoted 9 lines
Quoted 6 lines

Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2458

---
  docs/sphinx/depfile.py | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)

I'm queuing this patch since have another docs/ related one in my next pull request.