Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux Kernel: TypeError: object of type 'PosixPath' has no len #11629

Closed
severach opened this issue Aug 22, 2023 · 6 comments
Closed

Linux Kernel: TypeError: object of type 'PosixPath' has no len #11629

severach opened this issue Aug 22, 2023 · 6 comments

Comments

@severach
Copy link

severach commented Aug 22, 2023

Describe the bug

Linux Kernel 5.4 to 6.4 make htmldocs fail with TypeError: object of type 'PosixPath' has no len() and unsupported operand type(s) for +: 'PosixPath' and 'str'.

How to Reproduce

Kernel 5.10. Disable make all. Build with make htmldocs

Environment Information

Not working: python-sphinx 7.2.2
Working: python-sphinx 7.1.2


Platform:              linux; (Linux-6.1.46-1-lts-x86_64-with-glibc2.38)
Python version:        3.11.3 (main, Jun  5 2023, 09:32:32) [GCC 13.1.1 20230429])
Python implementation: CPython
Sphinx version:        7.2.0
Docutils version:      0.20.1
Jinja2 version:        3.1.2
Pygments version:      2.16.1


$ pacman -Q python-sphinx
python-sphinx v7.1.1.r11.g49d8304-1

Sphinx extensions

No response

Additional context

Offending commit is 49d8304

Suspiciously similar to #11618.

@AA-Turner
Copy link
Member

Are you able to run with the -T option enabled please?

A

@severach
Copy link
Author

severach commented Aug 22, 2023

[linux-lts510]$ make htmldocs SPHINXOPTS='-T'

Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/sphinx/util/parallel.py", line 76, in _process
    ret = func(arg)
          ^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/sphinx/builders/__init__.py", line 585, in write_process
    self.write_doc(docname, doctree)
  File "/usr/lib/python3.11/site-packages/sphinx/builders/html/__init__.py", line 675, in write_doc
    self.docwriter.write(doctree, destination)
  File "/usr/lib/python3.11/site-packages/docutils/writers/__init__.py", line 80, in write
    self.translate()
  File "/usr/lib/python3.11/site-packages/sphinx/writers/html.py", line 36, in translate
    self.document.walkabout(visitor)
  File "/usr/lib/python3.11/site-packages/docutils/nodes.py", line 186, in walkabout
    if child.walkabout(visitor):
       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/docutils/nodes.py", line 186, in walkabout
    if child.walkabout(visitor):
       ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/docutils/nodes.py", line 178, in walkabout
    visitor.dispatch_visit(self)
  File "/usr/lib/python3.11/site-packages/sphinx/util/docutils.py", line 573, in dispatch_visit
    method(node)
  File "/home/chris/build/linux-lts510/src/linux-5.10.191/Documentation/sphinx/kfigure.py", line 381, in visit_kernel_figure
    convert_image(img_node, self)
  File "/home/chris/build/linux-lts510/src/linux-5.10.191/Documentation/sphinx/kfigure.py", line 269, in convert_image
    _name = dst_fname[len(translator.builder.outdir) + 1:]
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: object of type 'PosixPath' has no len()

-T only catches the len error. The + warning isn't caught.

I can fix and compile with this patch but I don't think it's the right solution. I suspect that there's some places you missed and return a PosixPath rather than str(PosixPath), so rarely used that regular bug checks didn't catch them.

diff -ru a/Documentation/sphinx/kerneldoc.py b/Documentation/sphinx/kerneldoc.py
--- a/Documentation/sphinx/kerneldoc.py 2023-08-16 12:21:03.000000000 -0400
+++ b/Documentation/sphinx/kerneldoc.py 2023-08-22 10:54:28.646583489 -0400
@@ -148,7 +148,7 @@
                     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) + "/" + str(env.docname) + ":" + str(self.lineno)
                     result.append(line, doc + ": " + filename, lineoffset)
                     lineoffset += 1

diff -ru a/Documentation/sphinx/kfigure.py b/Documentation/sphinx/kfigure.py
--- a/Documentation/sphinx/kfigure.py 2023-08-16 12:21:03.000000000 -0400
+++ b/Documentation/sphinx/kfigure.py 2023-08-22 10:54:07.629742553 -0400
@@ -266,7 +266,7 @@
     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,

akiyks added a commit to akiyks/linux that referenced this issue Aug 23, 2023
Forward port of change suggested by @severach in Sphinx github
issue #11629 [1].

Link: [1] sphinx-doc/sphinx#11629
akiyks added a commit to akiyks/linux that referenced this issue Aug 23, 2023
Forward port of change suggested by @severach in Sphinx github
issue #11629 [1].

Link: [1] sphinx-doc/sphinx#11629
@AA-Turner
Copy link
Member

Please test with Sphinx 7.2.3, which should fix this issue.

A

@AA-Turner
Copy link
Member

Duplicates #11605

@AA-Turner AA-Turner closed this as not planned Won't fix, can't repro, duplicate, stale Aug 23, 2023
@severach
Copy link
Author

The kernel compiles with or without my patch on Sphinx 7.2.3 and 7.1.2. The patch eliminates the warnings. Would you say that my patch is good to keep compiles working for current versions and on through the deprecation in 8.x?

@AA-Turner
Copy link
Member

Yes, that'll work for the forseeable (as it unconditionally coerces Path to str).

I'd consider the below, though, assuming the Kernel's documentation requires Python 3.6 or later:

diff -ru a/Documentation/sphinx/kerneldoc.py b/Documentation/sphinx/kerneldoc.py
--- a/Documentation/sphinx/kerneldoc.py 2023-08-16 12:21:03.000000000 -0400
+++ b/Documentation/sphinx/kerneldoc.py 2023-08-22 10:54:28.646583489 -0400
@@ -148,7 +148,7 @@
                     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 = f"{env.srcdir}/{env.docname}:{self.lineno}"
                     result.append(line, doc + ": " + filename, lineoffset)
                     lineoffset += 1

Technically one ought use os.fspath() instead of str, but as it happens pathlib.Path.__fspath__() just calls str internally.

A

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants