* [LTP] [PATCH 1/1] doc/conf.py: Replace all titles
@ 2025-02-18 12:15 Petr Vorel
2025-02-18 12:32 ` Andrea Cervesato via ltp
0 siblings, 1 reply; 3+ messages in thread
From: Petr Vorel @ 2025-02-18 12:15 UTC (permalink / raw)
To: ltp
This fixes titles like "[Race Description]".
Fixes: 1bf344a3db ("doc: add tests catalog page")
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
doc/conf.py | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/doc/conf.py b/doc/conf.py
index 03fcff67e8..e1d02d63e8 100644
--- a/doc/conf.py
+++ 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)
+ desc_text.append(line)
text.extend([
'\n'.join(desc_text),
--
2.47.2
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [LTP] [PATCH 1/1] doc/conf.py: Replace all titles
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
0 siblings, 1 reply; 3+ messages in thread
From: Andrea Cervesato via ltp @ 2025-02-18 12:32 UTC (permalink / raw)
To: Petr Vorel, ltp
Hi Petr,
On 2/18/25 13:15, Petr Vorel wrote:
> This fixes titles like "[Race Description]".
>
> Fixes: 1bf344a3db ("doc: add tests catalog page")
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
> doc/conf.py | 8 ++------
> 1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/doc/conf.py b/doc/conf.py
> index 03fcff67e8..e1d02d63e8 100644
> --- a/doc/conf.py
> +++ 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.
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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [LTP] [PATCH 1/1] doc/conf.py: Replace all titles
2025-02-18 12:32 ` Andrea Cervesato via ltp
@ 2025-02-18 13:26 ` Petr Vorel
0 siblings, 0 replies; 3+ messages in thread
From: Petr Vorel @ 2025-02-18 13:26 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-18 13:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox