Message ID | 20190520194918.19535-1-blomqvist.janne@gmail.com |
---|---|
State | New |
Headers | show |
Series | Convert contrib/mklog script to Python 3 | expand |
On 5/20/19 1:49 PM, Janne Blomqvist wrote: > Upstream will drop support for Python 2.x on January 1, 2020. This > patch converts the contrib/mklog script to Python 3. The process for > the conversion was as follows. > > - Use the futurize tool (https://python-future.org ) to apply the > print_with_import, except, and dict transformations. > > - Remove the "from __future__ import print_function". > > - Change the shebang line to search for python3 in the environment. > > - Modify the run() function to return a str instead of bytes. > > - Update the copyright year. > > contrib/ChangeLog: > > 2019-05-20 Janne Blomqvist <jb@gcc.gnu.org> > > * mklog: Convert to Python 3. OK jeff
Hi. There's a regression I see after the transition to python3: $ cat /tmp/patch diff --git a/gcc/testsuite/gcc.dg/pr90263.c b/gcc/testsuite/gcc.dg/pr90263.c index acf3db16640..3222a5331c1 100644 --- a/gcc/testsuite/gcc.dg/pr90263.c +++ b/gcc/testsuite/gcc.dg/pr90263.c @@ -1,5 +1,6 @@ /* PR middle-end/90263 */ /* { dg-do compile } */ +/* { dg-options "-O2" } */ /* { dg-require-effective-target glibc } */ int *f (int *p, int *q, long n) $ ~/Programming/gcc/contrib/mklog /tmp/patch Traceback (most recent call last): File "/home/marxin/Programming/gcc/contrib/mklog", line 470, in <module> main() File "/home/marxin/Programming/gcc/contrib/mklog", line 388, in main diffs = parse_patch(contents) File "/home/marxin/Programming/gcc/contrib/mklog", line 273, in parse_patch lines = contents.split('\n') TypeError: a bytes-like object is required, not 'str' Thanks, Martin
On Tue, May 21, 2019 at 10:32 AM Martin Liška <mliska@suse.cz> wrote: > > Hi. > > There's a regression I see after the transition to python3: > > $ cat /tmp/patch > diff --git a/gcc/testsuite/gcc.dg/pr90263.c b/gcc/testsuite/gcc.dg/pr90263.c > index acf3db16640..3222a5331c1 100644 > --- a/gcc/testsuite/gcc.dg/pr90263.c > +++ b/gcc/testsuite/gcc.dg/pr90263.c > @@ -1,5 +1,6 @@ > /* PR middle-end/90263 */ > /* { dg-do compile } */ > +/* { dg-options "-O2" } */ > /* { dg-require-effective-target glibc } */ > > int *f (int *p, int *q, long n) > > $ ~/Programming/gcc/contrib/mklog /tmp/patch > Traceback (most recent call last): > File "/home/marxin/Programming/gcc/contrib/mklog", line 470, in <module> > main() > File "/home/marxin/Programming/gcc/contrib/mklog", line 388, in main > diffs = parse_patch(contents) > File "/home/marxin/Programming/gcc/contrib/mklog", line 273, in parse_patch > lines = contents.split('\n') > TypeError: a bytes-like object is required, not 'str' > > Thanks, > Martin Oof, thanks for the report, looking into it!
On Tue, May 21, 2019 at 10:47 AM Janne Blomqvist <blomqvist.janne@gmail.com> wrote: > > On Tue, May 21, 2019 at 10:32 AM Martin Liška <mliska@suse.cz> wrote: > > > > Hi. > > > > There's a regression I see after the transition to python3: > > > > $ cat /tmp/patch > > diff --git a/gcc/testsuite/gcc.dg/pr90263.c b/gcc/testsuite/gcc.dg/pr90263.c > > index acf3db16640..3222a5331c1 100644 > > --- a/gcc/testsuite/gcc.dg/pr90263.c > > +++ b/gcc/testsuite/gcc.dg/pr90263.c > > @@ -1,5 +1,6 @@ > > /* PR middle-end/90263 */ > > /* { dg-do compile } */ > > +/* { dg-options "-O2" } */ > > /* { dg-require-effective-target glibc } */ > > > > int *f (int *p, int *q, long n) > > > > $ ~/Programming/gcc/contrib/mklog /tmp/patch > > Traceback (most recent call last): > > File "/home/marxin/Programming/gcc/contrib/mklog", line 470, in <module> > > main() > > File "/home/marxin/Programming/gcc/contrib/mklog", line 388, in main > > diffs = parse_patch(contents) > > File "/home/marxin/Programming/gcc/contrib/mklog", line 273, in parse_patch > > lines = contents.split('\n') > > TypeError: a bytes-like object is required, not 'str' > > > > Thanks, > > Martin > > Oof, thanks for the report, looking into it! > > > -- > Janne Blomqvist Committed r271459 as obvious: diff --git a/contrib/mklog b/contrib/mklog index 125f52ef11c..be1dc3a27fc 100755 --- a/contrib/mklog +++ b/contrib/mklog @@ -380,7 +380,7 @@ def main(): if len(args) == 1 and args[0] == '-': input = sys.stdin elif len(args) == 1: - input = open(args[0], 'rb') + input = open(args[0]) else: error("too many arguments; for more details run with -h") @@ -442,7 +442,7 @@ def main(): shutil.copymode(args[0], tmp) # Open the temp file, clearing contents. - out = open(tmp, 'wb') + out = open(tmp, 'w') else: tmp = None out = sys.stdout
diff --git a/contrib/mklog b/contrib/mklog index eb765edcbe2..125f52ef11c 100755 --- a/contrib/mklog +++ b/contrib/mklog @@ -1,6 +1,6 @@ -#!/usr/bin/python +#!/usr/bin/env python3 -# Copyright (C) 2017 Free Software Foundation, Inc. +# Copyright (C) 2017-2019 Free Software Foundation, Inc. # # This file is part of GCC. # @@ -67,7 +67,7 @@ class RegexCache(object): cache = RegexCache() def print_help_and_exit(): - print """\ + print("""\ Usage: %s [-i | --inline] [PATCH] Generate ChangeLog template for PATCH. PATCH must be generated using diff(1)'s -up or -cp options @@ -78,7 +78,7 @@ When PATCH is - or missing, read standard input. When -i is used, prepends ChangeLog to PATCH. If PATCH is not stdin, modifies PATCH in-place, otherwise writes to stdout. -""" % me +""" % me) sys.exit(1) def run(cmd, die_on_error): @@ -87,7 +87,7 @@ def run(cmd, die_on_error): (out, err) = proc.communicate() if die_on_error and proc.returncode != 0: error("`%s` failed:\n" % (cmd, proc.stderr)) - return proc.returncode, out, err + return proc.returncode, out.decode(), err def read_user_info(): dot_mklog_format_msg = """\ @@ -153,9 +153,9 @@ class FileDiff: self.clname, self.relname = get_parent_changelog(filename); def dump(self): - print "Diff for %s:\n ChangeLog = %s\n rel name = %s\n" % (self.filename, self.clname, self.relname) + print("Diff for %s:\n ChangeLog = %s\n rel name = %s\n" % (self.filename, self.clname, self.relname)) for i, h in enumerate(self.hunks): - print "Next hunk %d:" % i + print("Next hunk %d:" % i) h.dump() class Hunk: @@ -167,8 +167,8 @@ class Hunk: self.ctx_diff = is_ctx_hunk_start(hdr) def dump(self): - print '%s' % self.hdr - print '%s' % '\n'.join(self.lines) + print('%s' % self.hdr) + print('%s' % '\n'.join(self.lines)) def is_file_addition(self): """Does hunk describe addition of file?""" @@ -358,7 +358,7 @@ def main(): try: opts, args = getopt.getopt(sys.argv[1:], 'hiv', ['help', 'verbose', 'inline']) - except getopt.GetoptError, err: + except getopt.GetoptError as err: error(str(err)) inline = False @@ -388,7 +388,7 @@ def main(): diffs = parse_patch(contents) if verbose: - print "Parse results:" + print("Parse results:") for d in diffs: d.dump() @@ -449,7 +449,7 @@ def main(): # Print log date = time.strftime('%Y-%m-%d') - for log_name, msg in sorted(logs.iteritems()): + for log_name, msg in sorted(logs.items()): out.write("""\ %s: