[LTP] [PATCH 1/1] doc/conf.py: Replace all titles
Petr Vorel
pvorel@suse.cz
Tue Feb 18 14:26:00 CET 2025
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
More information about the ltp
mailing list