vidartf / nbsphinx-link

A sphinx extension for including notebook files from outside sphinx source root.
BSD 3-Clause "New" or "Revised" License
37 stars 15 forks source link

BUG: AttributeError: module 'docutils.nodes' has no attribute 'reprunicode' #22

Closed antoinecollet5 closed 2 months ago

antoinecollet5 commented 6 months ago

It seems that this line causes an error https://github.com/vidartf/nbsphinx-link/blob/f1682a8b5bfd884bfed7ef7dfaf0810c6ae8a543/nbsphinx_link/__init__.py#L192

because docutils removed reprunicode in v0.21.

From b059be87d593687210a409a5be1ecd6d28941a62 Mon Sep 17 00:00:00 2001
From: Chris Sewell <chrisj_sewell@hotmail.com>
Date: Tue, 30 Apr 2024 20:58:56 +0200
Subject: [PATCH] fix sphinx docs build

---
 Documentation/sphinx/kernel_include.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/Documentation/sphinx/kernel_include.py b/Documentation/sphinx/kernel_include.py
index abe768088377..638762442336 100755
--- a/Documentation/sphinx/kernel_include.py
+++ b/Documentation/sphinx/kernel_include.py
@@ -97,7 +97,6 @@ class KernelInclude(Include):
         # HINT: this is the only line I had to change / commented out:
         #path = utils.relative_path(None, path)

-        path = nodes.reprunicode(path)
         encoding = self.options.get(
             'encoding', self.state.document.settings.input_encoding)
         e_handler=self.state.document.settings.input_encoding_error_handler
-- 
2.41.0

See the change in docutils here: https://github.com/live-clones/docutils/commit/d979a5dad7df1f97dfa306a4a3c53d4e45b0db22

I do not known if nbsphinx-link supports python 2? If so, it can probably be solved using something like:

# Note: reprunicode is a compatibility hack for python 2. It has been removed 
# from docutils in v0.21.
is_py2 = int(platform.python_version()) == 2
if is_py2:
    path = nodes.reprunicode(path)

and

target_root = env.config.nbsphinx_link_target_root
target = utils.relative_path(target_root, abs_path)
if is_py2:
    target = nodes.reprunicode(target)
target = target.replace(os.path.sep, '/')
env.metadata[env.docname]['nbsphinx-link-target'] = target

If you agree, I open a PR.

Antoine

vidartf commented 2 months ago

New release (1.3.1) should be out with the contributed fix. Please ping me if there are any issues with it.

antoinecollet5 commented 2 months ago

@vidartf 1.3.1 seems to solve the issue :)