diff --git a/tools/code_format/header_order.py b/tools/code_format/header_order.py index 9962d825a3f50..427fb0c053b10 100755 --- a/tools/code_format/header_order.py +++ b/tools/code_format/header_order.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Enforce header order in a given file. This will only reorder in the first sequence of contiguous # #include statements, so it will not play well with #ifdef. @@ -12,17 +12,15 @@ # enough to handle block splitting and correctly detecting the main header subject to the Envoy # canonical paths. -from __future__ import print_function - import argparse import common +import pathlib import re import sys def ReorderHeaders(path): - with open(path, 'r') as f: - source = f.read() + source = pathlib.Path(path).read_text(encoding='utf-8') all_lines = iter(source.split('\n')) before_includes_lines = [] @@ -117,7 +115,6 @@ def regex_filter(regex): include_dir_order = args.include_dir_order.split(',') reorderd_source = ReorderHeaders(target_path) if args.rewrite: - with open(target_path, 'w') as f: - f.write(reorderd_source) + pathlib.Path(target_path).write_text(reorderd_source, encoding='utf-8') else: - sys.stdout.write(reorderd_source) + sys.stdout.buffer.write(reorderd_source.encode('utf-8')) diff --git a/tools/code_format/requirements.txt b/tools/code_format/requirements.txt index 4ab3842b87d92..c27e0d44afaa2 100644 --- a/tools/code_format/requirements.txt +++ b/tools/code_format/requirements.txt @@ -1,2 +1,2 @@ -flake8==3.7.8 -yapf==0.28.0 +flake8==3.8.3 +yapf==0.30.0 diff --git a/tools/protoxform/migrate.py b/tools/protoxform/migrate.py index e7481b0ccbbbf..10d6be2740144 100644 --- a/tools/protoxform/migrate.py +++ b/tools/protoxform/migrate.py @@ -57,8 +57,8 @@ def UpgradeType(match): # We need to deal with envoy.api.* normalization in the v2 API. We won't # need this in v3+, so rather than churn docs, we just have this workaround. type_desc = self._typedb.types[api_v2_type_name] - repl_type = type_desc.next_version_type_name[len( - 'envoy.'):] if type_desc.next_version_type_name else normalized_type_name + repl_type = type_desc.next_version_type_name[ + len('envoy.'):] if type_desc.next_version_type_name else normalized_type_name # TODO(htuch): this should really either go through the type database or # via the descriptor pool and annotations, but there are only two of these # we need for the initial v2 -> v3 docs cut, so hard coding for now.