Skip to contentSkip to conversation

docs/sphinx: Explicitly convert Sphinx paths to str

PATCH Applied Oliver Faso 4 participants 5 messages Sep 10, 2023 – Oct 3, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 docs/sphinx: Explicitly convert Sphinx paths to str

Sphinx 7.2+ is switching to using pathlib.Path instead of str to represent paths. This fixes the current deprecation warnings and eventual breakage. This conversion will be a no-op when using older Sphinx versions.

---
 Documentation/sphinx/kerneldoc.py | 2 +-
 Documentation/sphinx/kfigure.py   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Documentation/sphinx/kerneldoc.py +1 -1
index 9395892c7ba3..d26155990ec3 100644
@@ -138,7 +138,7 @@ class KernelDocDirective(Directive):
                     lineoffset = int(match.group(1)) - 1
                     # we must eat our comments since the upset the markup
                 else:
-                    doc = env.srcdir + "/" + env.docname + ":" + str(self.lineno)
+                    doc = str(env.srcdir) + "/" + env.docname + ":" + str(self.lineno)
                     result.append(line, doc + ": " + filename, lineoffset)
                     lineoffset += 1
 
Documentation/sphinx/kfigure.py +1 -1
index cefdbb7e7523..13e885bbd499 100644
@@ -309,7 +309,7 @@ def convert_image(img_node, translator, src_fname=None):
     if dst_fname:
         # the builder needs not to copy one more time, so pop it if exists.
         translator.builder.images.pop(img_node['uri'], None)
-        _name = dst_fname[len(translator.builder.outdir) + 1:]
+        _name = dst_fname[len(str(translator.builder.outdir)) + 1:]
 
         if isNewer(dst_fname, src_fname):
             kernellog.verbose(app,
Signature · 1 line
2.42.0
#1 lore raw

Documentation/sphinx/kerneldoc.py class KernelDocDirective(Directive): · line 141

Quoted 3 lines · Oliver Faso

else:

Documentation/sphinx/kerneldoc.py +1 -1
-                    doc = env.srcdir + "/" + env.docname + ":" + str(self.lineno)
+                    doc = str(env.srcdir) + "/" + env.docname + ":" + str(self.lineno)

Would we be better off doing the path manipulation in Path, then converting to string? ie:

doc = str(env.srcdir / env.docname) + ":" + str(self.lineno)

author
#2 lore raw
Quoted 11 lines · Matthew Wilcox

Documentation/sphinx/kerneldoc.py class KernelDocDirective(Directive): · line 141

Quoted 3 lines · Oliver Faso

else:

Documentation/sphinx/kerneldoc.py +1 -1
-                    doc = env.srcdir + "/" + env.docname + ":" + str(self.lineno)
+                    doc = str(env.srcdir) + "/" + env.docname + ":" + str(self.lineno)

Would we be better off doing the path manipulation in Path, then converting to string? ie:

doc = str(env.srcdir / env.docname) + ":" + str(self.lineno)

That would be incompatible with earlier Sphinx versions, which most people are probably using.
The benefits would be supporting non-'/' separators, and invalid uft8 in paths. But, I think those things don't matter here.

(sorry Matthew for double mail, I hit the wrong reply button)

Tested-by on v1 1/1
#3 lore raw
In reply to Oliver Faso

Hi,

Quoted 7 lines · Oliver Faso

Sphinx 7.2+ is switching to using pathlib.Path instead of str to represent paths. This fixes the current deprecation warnings and eventual breakage. This conversion will be a no-op when using older Sphinx versions.

Belatedly tested against Sphinx versions 2.4.5, 4.2.0, 5.3.0, and 7.2.6 (latest).

HTH, Akira

Quoted 34 lines
---
 Documentation/sphinx/kerneldoc.py | 2 +-
 Documentation/sphinx/kfigure.py   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
Documentation/sphinx/kerneldoc.py +1 -1
index 9395892c7ba3..d26155990ec3 100644
@@ -138,7 +138,7 @@ class KernelDocDirective(Directive):
                     lineoffset = int(match.group(1)) - 1
                     # we must eat our comments since the upset the markup
                 else:
-                    doc = env.srcdir + "/" + env.docname + ":" + str(self.lineno)
+                    doc = str(env.srcdir) + "/" + env.docname + ":" + str(self.lineno)
                     result.append(line, doc + ": " + filename, lineoffset)
                     lineoffset += 1
 
Documentation/sphinx/kfigure.py +1 -1
index cefdbb7e7523..13e885bbd499 100644
@@ -309,7 +309,7 @@ def convert_image(img_node, translator, src_fname=None):
     if dst_fname:
         # the builder needs not to copy one more time, so pop it if exists.
         translator.builder.images.pop(img_node['uri'], None)
-        _name = dst_fname[len(translator.builder.outdir) + 1:]
+        _name = dst_fname[len(str(translator.builder.outdir)) + 1:]
 
         if isNewer(dst_fname, src_fname):
             kernellog.verbose(app,
Signature · 1 line
2.42.0
maintainer Applied
#4 lore raw
In reply to Oliver Faso
Quoted 11 lines · Oliver Faso

Sphinx 7.2+ is switching to using pathlib.Path instead of str to represent paths. This fixes the current deprecation warnings and eventual breakage. This conversion will be a no-op when using older Sphinx versions.

---
 Documentation/sphinx/kerneldoc.py | 2 +-
 Documentation/sphinx/kfigure.py   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

I've applied this, thanks.

jon