From ac125564b9d2f41acbc9479228a30f0ebaeec7fb Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Mon, 23 Aug 2021 21:19:24 -0700 Subject: [PATCH] build: Fix pylint 2.10 issues, use python3 where possible The newest pylint release complained about several issues that the older release did not. This resolves those issues: - removes unneeded "u" prefix from strings - adds "encoding" parameter for all open() calls - because "encoding" is a python3-only parameter, use python3 in all the scripts that we control Unfortunately, python2 is required for any scripts that import modules from the ancient Chromium build system we're using (referenced by DEPS), as well as kokoro scripts. Change-Id: I2e9f97af508efe58b5a71de21740e59b1528affd --- docs/source/conf.py | 18 +++++++++--------- gyp_packager.py | 4 +--- kokoro/deps_replacer.py | 4 ++++ packager/app/test/packager_test.py | 4 ++-- packager/protoc.gypi | 2 +- packager/third_party/yasm/yasm.gyp | 2 +- packager/tools/extract_from_changelog.py | 6 ++---- packager/tools/generate_license_notice.py | 6 +++--- packager/tools/git/check_formatting.py | 2 -- packager/tools/license_notice.gyp | 2 +- packager/version/generate_version_string.py | 4 +--- packager/version/version.gyp | 2 +- 12 files changed, 26 insertions(+), 30 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 529f3a449f..5a35ff599f 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -54,18 +54,18 @@ source_suffix = ['.rst', '.md'] master_doc = 'index' # General information about the project. -project = u'Shaka Packager' -copyright = u'2017, Google' # pylint: disable=redefined-builtin -author = u'Google' +project = 'Shaka Packager' +copyright = '2017, Google' # pylint: disable=redefined-builtin +author = 'Google' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -# version = u'2.0' +# version = '2.0' # The full version, including alpha/beta/rc tags. -# release = u'2.0' +# release = '2.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -150,8 +150,8 @@ latex_elements = { # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'ShakaPackager.tex', u'Shaka Packager Documentation', - u'Google', 'manual'), + (master_doc, 'ShakaPackager.tex', 'Shaka Packager Documentation', + 'Google', 'manual'), ] @@ -160,7 +160,7 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'shakapackager', u'Shaka Packager Documentation', + (master_doc, 'shakapackager', 'Shaka Packager Documentation', [author], 1) ] @@ -171,7 +171,7 @@ man_pages = [ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'ShakaPackager', u'Shaka Packager Documentation', + (master_doc, 'ShakaPackager', 'Shaka Packager Documentation', author, 'ShakaPackager', 'One line description of project.', 'Miscellaneous'), ] diff --git a/gyp_packager.py b/gyp_packager.py index 1152bbd905..fe7991f6ca 100755 --- a/gyp_packager.py +++ b/gyp_packager.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # # Copyright 2014 Google Inc. All rights reserved. # @@ -26,8 +26,6 @@ Step 1 is only required if there is any gyp file change. Otherwise, you may just run ninja. """ -from __future__ import print_function - import os import sys diff --git a/kokoro/deps_replacer.py b/kokoro/deps_replacer.py index 81c6b4512d..92923b9265 100644 --- a/kokoro/deps_replacer.py +++ b/kokoro/deps_replacer.py @@ -7,6 +7,10 @@ Usage: this_script.py search_text replacement_text """ +# This runs on a Windows kokoro host where we don't control the python version. +# Because this runs in python2, we can't specify an encoding in open(). +# pylint: disable=unspecified-encoding + import os import sys diff --git a/packager/app/test/packager_test.py b/packager/app/test/packager_test.py index 1334b93609..113a582482 100755 --- a/packager/app/test/packager_test.py +++ b/packager/app/test/packager_test.py @@ -169,10 +169,10 @@ class DiffFilesPolicy(object): dump_b = os.path.join(out_dir, os.path.basename(file_b) + '.dump.actual') try: cmd = ['mp4dump', '--verbosity', '2', file_a] - with open(dump_a, 'w') as f: + with open(dump_a, 'w', encoding='utf8') as f: subprocess.check_call(cmd, stdout=f) cmd = ['mp4dump', '--verbosity', '2', file_b] - with open(dump_b, 'w') as f: + with open(dump_b, 'w', encoding='utf8') as f: subprocess.check_call(cmd, stdout=f) except (OSError, subprocess.CalledProcessError): # If the program isn't available or returns an error, just ignore it and diff --git a/packager/protoc.gypi b/packager/protoc.gypi index a57294a90f..4f6ce43a9f 100644 --- a/packager/protoc.gypi +++ b/packager/protoc.gypi @@ -77,7 +77,7 @@ '<(protoc)', ], 'action': [ - 'python', + 'python3', '<(protoc_wrapper)', # If no cc_include specified --protobuf option will be ignored. '--include', diff --git a/packager/third_party/yasm/yasm.gyp b/packager/third_party/yasm/yasm.gyp index 6a5e6920bb..8ad8c7a02b 100644 --- a/packager/third_party/yasm/yasm.gyp +++ b/packager/third_party/yasm/yasm.gyp @@ -428,7 +428,7 @@ '<(shared_generated_dir)/x86insn_nasm.gperf', ], 'action': [ - 'python', + 'python3', '<(gen_insn_path)', '<(shared_generated_dir)', ], diff --git a/packager/tools/extract_from_changelog.py b/packager/tools/extract_from_changelog.py index a9f8df77f1..55d976a32a 100755 --- a/packager/tools/extract_from_changelog.py +++ b/packager/tools/extract_from_changelog.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # # Copyright 2018 Google Inc. All rights reserved. # @@ -7,8 +7,6 @@ # https://developers.google.com/open-source/licenses/bsd """This script extracts a version or release notes from the changelog.""" -from __future__ import print_function - import argparse import re import sys @@ -22,7 +20,7 @@ def main(): args = parser.parse_args() - with open('CHANGELOG.md', 'r') as f: + with open('CHANGELOG.md', 'r', encoding='utf8') as f: contents = f.read() # This excludes the header line with the release name and date, to match the diff --git a/packager/tools/generate_license_notice.py b/packager/tools/generate_license_notice.py index 2455cb81d4..d90c818ce4 100755 --- a/packager/tools/generate_license_notice.py +++ b/packager/tools/generate_license_notice.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # # Copyright 2018 Google Inc. All rights reserved. # @@ -134,11 +134,11 @@ def GenerateLicenseNotice(output_dir, output_license_file_name): if output_dir: cc_file_path = os.path.join(output_dir, 'license_notice.cc') - with open(cc_file_path, 'w') as output: + with open(cc_file_path, 'w', encoding='utf8') as output: output.write(CC_FILE_TEMPLATE.format(content_array_text)) h_file_path = os.path.join(output_dir, 'license_notice.h') - with open(h_file_path, 'w') as output: + with open(h_file_path, 'w', encoding='utf8') as output: output.write(H_FILE_TEMPLATE.format(len(content))) diff --git a/packager/tools/git/check_formatting.py b/packager/tools/git/check_formatting.py index 2cb76dece8..e6553cf4dc 100755 --- a/packager/tools/git/check_formatting.py +++ b/packager/tools/git/check_formatting.py @@ -32,8 +32,6 @@ Steps to install clang-format on your system if you don't have it already: """ -from __future__ import print_function - import subprocess import sys diff --git a/packager/tools/license_notice.gyp b/packager/tools/license_notice.gyp index ee37e214ce..7dd24620bc 100644 --- a/packager/tools/license_notice.gyp +++ b/packager/tools/license_notice.gyp @@ -23,7 +23,7 @@ '<(generated_dir)/license_notice.h', ], 'action': [ - 'python', 'generate_license_notice.py', '<(generated_dir)', + 'python3', 'generate_license_notice.py', '<(generated_dir)', ], 'process_outputs_as_sources': 1, 'message': 'Generating embeddable license', diff --git a/packager/version/generate_version_string.py b/packager/version/generate_version_string.py index c5ddcf9a2b..ae263873e7 100755 --- a/packager/version/generate_version_string.py +++ b/packager/version/generate_version_string.py @@ -7,8 +7,6 @@ # https://developers.google.com/open-source/licenses/bsd """This script is used to generate version string for packager.""" -from __future__ import print_function - import subprocess if __name__ == '__main__': @@ -29,4 +27,4 @@ if __name__ == '__main__': if version_tag: print('{0}-{1}'.format(version_tag, version_hash)) else: - print(version_hash) + print(version_hash.decode('utf8')) diff --git a/packager/version/version.gyp b/packager/version/version.gyp index 8ec850ee50..cf011f473c 100644 --- a/packager/version/version.gyp +++ b/packager/version/version.gyp @@ -13,7 +13,7 @@ 'target_name': 'version', 'type': '<(component)', 'defines': [ - 'PACKAGER_VERSION="