mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Stefan Lengfeld <contact@stefanchrist.eu>
Subject: Re: [PATCH 2/2] Documentation: make gen_commands helper python3 compatible
Date: Tue, 17 Sep 2019 10:33:08 +0200	[thread overview]
Message-ID: <20190917083308.y7xfqlmav3k4ecyy@pengutronix.de> (raw)
In-Reply-To: <20190917080956.16100-2-u.kleine-koenig@pengutronix.de>

On Tue, Sep 17, 2019 at 10:09:56AM +0200, Uwe Kleine-König wrote:
> On some machines the python command is provided by Python 3 while on
> most (at least in my bubble) it is still Python 2. Modify the code to
> make it usable by both Python versions.
> 
> print_function is available in __future__ since Python 2.6.0a2, which
> shouldn't be a relevant restriction.
> 
> The modified script generates the same documentation as the old one;
> independent if the script is called using Python 2 (here: 2.7.16) or
> Python 3 (here: 3.7.3).
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  Documentation/gen_commands.py | 30 ++++++++++++++++++------------
>  1 file changed, 18 insertions(+), 12 deletions(-)
> 
> diff --git a/Documentation/gen_commands.py b/Documentation/gen_commands.py
> index 6251b4f22ed9..ff07ee0297f1 100755
> --- a/Documentation/gen_commands.py
> +++ b/Documentation/gen_commands.py
> @@ -1,5 +1,7 @@
>  #!/usr/bin/python
>  
> +from __future__ import print_function
> +
>  import errno
>  import os
>  import re
> @@ -28,10 +30,15 @@ CONT = re.compile(r"""\s*"(.*?)"\s*\)?\s*$""")
>  
>  CMDS = {}
>  
> +def string_escape(s):
> +  # This used to do s.decode("string_escape") which isn't available on Python 3.
> +  # Actually we only need to drop '\t', so do this here.
> +  return s.replace(r'\t', '')

I just found a change in my working copy that didn't make it into my
patch:

-  # Actually we only need to drop '\t', so do this here.
-  return s.replace(r'\t', '')
+  # Actually we only need to drop '\t' and '\n', so do this here.
+  return s.replace(r'\t', '').replace(r'\n', '')

With this the claim that the generated code is identical actually holds.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2019-09-17  8:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-15 19:31 [PATCH] docs: add python version in shebang Stefan Lengfeld
2019-09-17  8:01 ` Uwe Kleine-König
2019-09-17  8:02   ` [PATCH 1/2] Convert latin1 files to utf-8 Uwe Kleine-König
2019-09-17 10:47     ` Sascha Hauer
2019-09-17  8:09   ` [PATCH 2/2] Documentation: make gen_commands helper python3 compatible Uwe Kleine-König
2019-09-17  8:33     ` Uwe Kleine-König [this message]
2019-09-18 19:25   ` [PATCH] docs: add python version in shebang Stefan Lengfeld

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=20190917083308.y7xfqlmav3k4ecyy@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=contact@stefanchrist.eu \
    /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