linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zhixu Liu <zhixu.liu@gmail.com>
To: Jonathan Corbet <corbet@lwn.net>
Cc: linux-doc@vger.kernel.org
Subject: Re: [PATCH v2] docs: sphinx: handle removal of utils.error_reporting in docutils 0.22
Date: Sat, 6 Sep 2025 22:38:21 +0800	[thread overview]
Message-ID: <CALMA0xYMNcD8UN5ykJALMskFGnNaau3cxJ1E5=bDE_mGS+bZBQ@mail.gmail.com> (raw)
In-Reply-To: <87a53cx4r0.fsf@trenco.lwn.net>

Hi Jonathan,

How about the v3 patch? I still think try/except is more robust,
but I can switch to version comparison if you prefer, e.g.:

if docutils.__version_info__ >= (0, 22):
    ...
else:
    ...

My preference for try/except:

1. Reflects the actual runtime environment, while version checks can
be broken by backported patches.
2. Avoids parsing non-standard version strings (e.g. 0.21a1,
0.21.dev0); try/except is simpler and has no extra dependencies.
(__version_info__ mitigates this somewhat.)
3. More Pythonic and straightforward.

I’m fine with either approach—please let me know which you’d like me to go with.

On Tue, Sep 2, 2025 at 11:18 PM Jonathan Corbet <corbet@lwn.net> wrote:
>
> Zhixu Liu <zhixu.liu@gmail.com> writes:
>
> > docutils.utils.error_reporting was removed in docutils v0.22, causing sphinx
> > extensions (e.g. kernel_include) to fail with:
> >
> >>   File "/usr/lib/python3.12/site-packages/sphinx/registry.py", line 544, in load_extension
> >>     raise ExtensionError(
> >> sphinx.errors.ExtensionError: Could not import extension kernel_include (exception: No module named 'docutils.utils.error_reporting')
> >
> > Add compatibility handling with try/except (more robust than checking
> > version numbers):
> > - SafeString  -> str
> > - ErrorString -> docutils.io.error_string()
> >
> > Signed-off-by: Z. Liu <zhixu.liu@gmail.com>
> > ---
> >  Documentation/sphinx/kernel_feat.py         | 6 +++++-
> >  Documentation/sphinx/kernel_include.py      | 7 ++++++-
> >  Documentation/sphinx/maintainers_include.py | 6 +++++-
> >  3 files changed, 16 insertions(+), 3 deletions(-)
> >
> > diff --git a/Documentation/sphinx/kernel_feat.py
> > b/Documentation/sphinx/kernel_feat.py
> > index e3a51867f27bd..d077645254cd4 100644
> > --- a/Documentation/sphinx/kernel_feat.py
> > +++ b/Documentation/sphinx/kernel_feat.py
> > @@ -40,7 +40,11 @@ import sys
> >  from docutils import nodes, statemachine
> >  from docutils.statemachine import ViewList
> >  from docutils.parsers.rst import directives, Directive
> > -from docutils.utils.error_reporting import ErrorString
> > +try:
> > +    from docutils.utils.error_reporting import ErrorString
> > +except ImportError:
> > +    # docutils >= 0.22
> > +    from docutils.io import error_string as ErrorString
> >  from sphinx.util.docutils import switch_source_input
>
> This is a step in the right direction ... but the exception you report
> in the changelog is sphinx.errors.ExtensionError; why a different
> exception here?
>
> I would still rather just look at the docutils version in any case,
> rather than trying to interpret exceptions.
>
> Thanks,
>
> jon



-- 
Z. Liu

      parent reply	other threads:[~2025-09-06 14:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-02 14:51 [PATCH v2] docs: sphinx: handle removal of utils.error_reporting in docutils 0.22 Zhixu Liu
2025-09-02 15:18 ` Jonathan Corbet
2025-09-02 15:56   ` Zhixu Liu
2025-09-04  3:42     ` [PATCH v3] " Zhixu Liu
2025-09-06 14:38   ` Zhixu Liu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CALMA0xYMNcD8UN5ykJALMskFGnNaau3cxJ1E5=bDE_mGS+bZBQ@mail.gmail.com' \
    --to=zhixu.liu@gmail.com \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).