linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC] docs: fix automarkup regression on Python 2
@ 2020-10-30 15:51 Jonathan Corbet
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Corbet @ 2020-10-30 15:51 UTC (permalink / raw)
  To: linux-doc
  Cc: Dafna Hirschfeld, Nícolas F. R. A. Prado,
	Mauro Carvalho Chehab, lkcamp, andrealmeid

It turns out that the Python 2 re module lacks the ASCII flag, so don't try
to use it there.

Fixes: f66e47f98c1e ("docs: automarkup.py: Fix regexes to solve sphinx 3 warnings")
Reported-by: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
---
 Documentation/sphinx/automarkup.py | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/Documentation/sphinx/automarkup.py b/Documentation/sphinx/automarkup.py
index 409dbc4100de..3e81ebab26ed 100644
--- a/Documentation/sphinx/automarkup.py
+++ b/Documentation/sphinx/automarkup.py
@@ -15,6 +15,14 @@ else:
 import re
 from itertools import chain
 
+#
+# Python 2 lacks re.ASCII...
+#
+try:
+    ascii_p3 = re.ASCII
+except AttributeError:
+    ascii_p3 = 0
+
 #
 # Regex nastiness.  Of course.
 # Try to identify "function()" that's not already marked up some
@@ -22,22 +30,22 @@ from itertools import chain
 # :c:func: block (i.e. ":c:func:`mmap()`s" flakes out), so the last
 # bit tries to restrict matches to things that won't create trouble.
 #
-RE_function = re.compile(r'\b(([a-zA-Z_]\w+)\(\))', flags=re.ASCII)
+RE_function = re.compile(r'\b(([a-zA-Z_]\w+)\(\))', flags=ascii_p3)
 
 #
 # Sphinx 2 uses the same :c:type role for struct, union, enum and typedef
 #
 RE_generic_type = re.compile(r'\b(struct|union|enum|typedef)\s+([a-zA-Z_]\w+)',
-                             flags=re.ASCII)
+                             flags=ascii_p3)
 
 #
 # Sphinx 3 uses a different C role for each one of struct, union, enum and
 # typedef
 #
-RE_struct = re.compile(r'\b(struct)\s+([a-zA-Z_]\w+)', flags=re.ASCII)
-RE_union = re.compile(r'\b(union)\s+([a-zA-Z_]\w+)', flags=re.ASCII)
-RE_enum = re.compile(r'\b(enum)\s+([a-zA-Z_]\w+)', flags=re.ASCII)
-RE_typedef = re.compile(r'\b(typedef)\s+([a-zA-Z_]\w+)', flags=re.ASCII)
+RE_struct = re.compile(r'\b(struct)\s+([a-zA-Z_]\w+)', flags=ascii_p3)
+RE_union = re.compile(r'\b(union)\s+([a-zA-Z_]\w+)', flags=ascii_p3)
+RE_enum = re.compile(r'\b(enum)\s+([a-zA-Z_]\w+)', flags=ascii_p3)
+RE_typedef = re.compile(r'\b(typedef)\s+([a-zA-Z_]\w+)', flags=ascii_p3)
 
 #
 # Detects a reference to a documentation page of the form Documentation/... with
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH RFC] docs: fix automarkup regression on Python 2
@ 2020-10-30 16:12 Nícolas F. R. A. Prado
  0 siblings, 0 replies; 2+ messages in thread
From: Nícolas F. R. A. Prado @ 2020-10-30 16:12 UTC (permalink / raw)
  To: Jonathan Corbet, linux-doc
  Cc: Dafna Hirschfeld, Mauro Carvalho Chehab, lkcamp, andrealmeid

On Fri Oct 30, 2020 at 12:51 PM -03, Jonathan Corbet wrote:
>
> It turns out that the Python 2 re module lacks the ASCII flag, so don't
> try
> to use it there.
>
> Fixes: f66e47f98c1e ("docs: automarkup.py: Fix regexes to solve sphinx 3
> warnings")
> Reported-by: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
> ---
> Documentation/sphinx/automarkup.py | 20 ++++++++++++++------
> 1 file changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/Documentation/sphinx/automarkup.py
> b/Documentation/sphinx/automarkup.py
> index 409dbc4100de..3e81ebab26ed 100644
> --- a/Documentation/sphinx/automarkup.py
> +++ b/Documentation/sphinx/automarkup.py
> @@ -15,6 +15,14 @@ else:
> import re
> from itertools import chain
>
> +#
> +# Python 2 lacks re.ASCII...
> +#
> +try:
> + ascii_p3 = re.ASCII
> +except AttributeError:
> + ascii_p3 = 0
> +
> #
> # Regex nastiness. Of course.
> # Try to identify "function()" that's not already marked up some
> @@ -22,22 +30,22 @@ from itertools import chain
> # :c:func: block (i.e. ":c:func:`mmap()`s" flakes out), so the last
> # bit tries to restrict matches to things that won't create trouble.
> #
> -RE_function = re.compile(r'\b(([a-zA-Z_]\w+)\(\))', flags=re.ASCII)
> +RE_function = re.compile(r'\b(([a-zA-Z_]\w+)\(\))', flags=ascii_p3)
>
> #
> # Sphinx 2 uses the same :c:type role for struct, union, enum and
> typedef
> #
> RE_generic_type =
> re.compile(r'\b(struct|union|enum|typedef)\s+([a-zA-Z_]\w+)',
> - flags=re.ASCII)
> + flags=ascii_p3)
>
> #
> # Sphinx 3 uses a different C role for each one of struct, union, enum
> and
> # typedef
> #
> -RE_struct = re.compile(r'\b(struct)\s+([a-zA-Z_]\w+)', flags=re.ASCII)
> -RE_union = re.compile(r'\b(union)\s+([a-zA-Z_]\w+)', flags=re.ASCII)
> -RE_enum = re.compile(r'\b(enum)\s+([a-zA-Z_]\w+)', flags=re.ASCII)
> -RE_typedef = re.compile(r'\b(typedef)\s+([a-zA-Z_]\w+)',
> flags=re.ASCII)
> +RE_struct = re.compile(r'\b(struct)\s+([a-zA-Z_]\w+)', flags=ascii_p3)
> +RE_union = re.compile(r'\b(union)\s+([a-zA-Z_]\w+)', flags=ascii_p3)
> +RE_enum = re.compile(r'\b(enum)\s+([a-zA-Z_]\w+)', flags=ascii_p3)
> +RE_typedef = re.compile(r'\b(typedef)\s+([a-zA-Z_]\w+)',
> flags=ascii_p3)
>
> #
> # Detects a reference to a documentation page of the form
> Documentation/... with
> --
> 2.26.2

Looks good to me.

Thanks,
Nícolas


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-30 16:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-30 15:51 [PATCH RFC] docs: fix automarkup regression on Python 2 Jonathan Corbet
2020-10-30 16:12 Nícolas F. R. A. Prado

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).