Linux Test Project
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 1/1] doc/conf.py: Replace all titles
Date: Tue, 18 Feb 2025 14:26:00 +0100	[thread overview]
Message-ID: <20250218132600.GA2452309@pevik> (raw)
In-Reply-To: <74a3b1f1-922f-4f5b-9265-879ca926dd05@suse.com>

Hi Andrea,

> > +++ b/doc/conf.py
> > @@ -455,12 +455,8 @@ def generate_test_catalog(_):
> >           if desc:
> >               desc_text = []
> >               for line in desc:
> > -                if line.startswith("[Description]"):
> > -                    desc_text.append("**Description**")
> > -                elif line.startswith("[Algorithm]"):
> > -                    desc_text.append("**Algorithm**")
> > -                else:
> > -                    desc_text.append(line)
> > +                line = re.sub(r'^\[([A-Za-z][\w\W]+)\]', r'**\1**', line)

> The idea is good, but the implementation can be optimized. We can
> "re.compile()" the regex __before__ reading all the lines, then we can use
> the compiled object to substitute the string. In this way we won't compile
> the regexp for each line and the string processing will be faster.

Thanks for improving my python fu! I knew about re.compile(), I just wasn't able
to find an example where it is combined with re.sub().

Kind regards,
Petr

> https://docs.python.org/3/library/re.html#re.compile
> https://docs.python.org/3/library/re.html#re.Pattern.sub

> > +                desc_text.append(line)
> >               text.extend([
> >                   '\n'.join(desc_text),
> Andrea

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

      reply	other threads:[~2025-02-18 13:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-18 12:15 [LTP] [PATCH 1/1] doc/conf.py: Replace all titles Petr Vorel
2025-02-18 12:32 ` Andrea Cervesato via ltp
2025-02-18 13:26   ` Petr Vorel [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=20250218132600.GA2452309@pevik \
    --to=pvorel@suse.cz \
    --cc=andrea.cervesato@suse.com \
    --cc=ltp@lists.linux.it \
    /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