From 4498aa8ac7d81ac75624f647bd6aaca70c39a4ea Mon Sep 17 00:00:00 2001 From: John Stiles Date: Mon, 16 Aug 2021 18:14:52 -0400 Subject: [PATCH] Fix rewrite_includes to work in both Python 2 and 3. This is patterned after http://review.skia.org/439776, but uses the `six` library for Python 2/3 cross-compatibility. Change-Id: If64c48c35d86b83c77316bb5536be6e7bd24c967 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/439936 Auto-Submit: John Stiles Commit-Queue: Kevin Lubick Reviewed-by: Kevin Lubick --- tools/rewrite_includes.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/rewrite_includes.py b/tools/rewrite_includes.py index 2d3946f766..b24450e450 100755 --- a/tools/rewrite_includes.py +++ b/tools/rewrite_includes.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2 +#!/usr/bin/python # # Copyright 2019 Google Inc. # @@ -6,12 +6,13 @@ # found in the LICENSE file. -from __future__ import print_function -import StringIO import argparse import os +import six import sys +from six import StringIO + parser = argparse.ArgumentParser() parser.add_argument('-n', '--dry-run', action='store_true', @@ -89,7 +90,7 @@ for file_path in to_rewrite(): lines = open(file_path).readlines() # Write it back out again line by line with substitutions for #includes. - output = StringIO.StringIO() if args.dry_run else open(file_path, 'wb') + output = StringIO() if args.dry_run else open(file_path, 'w') includes = [] for line in lines: