Skip to content

Commit

Permalink
Merge pull request grpc#24781 from grpc/revert-24767-revert-24673-mod…
Browse files Browse the repository at this point in the history
…ernize-several-scripts

Revert "Revert "Resolve warnings and deprecations in several scripts in tools""
  • Loading branch information
lidizheng authored Nov 19, 2020
2 parents 7384b96 + da399bc commit 6046624
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/abseil-cpp/gen_build_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
BUILDS_YAML_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)),
'preprocessed_builds.yaml')
with open(BUILDS_YAML_PATH) as f:
builds = yaml.load(f)
builds = yaml.load(f, Loader=yaml.FullLoader)

for build in builds:
build['build'] = 'private'
Expand Down
2 changes: 1 addition & 1 deletion test/cpp/naming/gen_build_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _resolver_test_cases(resolver_component_data):
def main():
resolver_component_data = ''
with open('test/cpp/naming/resolver_test_record_groups.yaml') as f:
resolver_component_data = yaml.load(f)
resolver_component_data = yaml.load(f, Loader=yaml.FullLoader)

json = {
'resolver_tests_common_zone_name':
Expand Down
4 changes: 2 additions & 2 deletions tools/buildgen/build_cleaner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
# Copyright 2015 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -83,7 +83,7 @@ def cleaned_build_yaml_dict_as_string(indict):
if __name__ == '__main__':
for filename in sys.argv[1:]:
with open(filename) as f:
js = yaml.load(f)
js = yaml.load(f, Loader=yaml.FullLoader)
output = cleaned_build_yaml_dict_as_string(js)
if TEST:
with open(filename) as f:
Expand Down
3 changes: 3 additions & 0 deletions tools/buildgen/generate_projects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ set -e

export TEST=${TEST:-false}

# Upgrade Python's YAML library
python3 -m pip install --upgrade --ignore-installed PyYAML --user

echo "Generating build_autogenerated.yaml from bazel BUILD file"
rm -f build_autogenerated.yaml
python3 tools/buildgen/extract_metadata_from_bazel_xml.py
Expand Down
23 changes: 14 additions & 9 deletions tools/buildgen/mako_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,31 @@
"""Simple Mako renderer.
Just a wrapper around the mako rendering library.
"""

import getopt
import imp
import importlib.util
import os
import pickle
import shutil
import sys

import yaml
from mako.lookup import TemplateLookup
from mako.runtime import Context
from mako.template import Template

import bunch
import yaml


# Imports a plugin
def import_plugin(name):
_, base_ex = os.path.split(name)
base, _ = os.path.splitext(base_ex)
return imp.load_source(base, name)
def import_plugin(path):
module_name = os.path.basename(path).replace('.py', '')
spec = importlib.util.spec_from_file_location(module_name, path)
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
spec.loader.exec_module(module)
return module


def out(msg):
Expand Down Expand Up @@ -104,7 +107,9 @@ def main(argv):
elif opt == '-d':
assert not got_preprocessed_input
with open(arg, 'r') as dict_file:
bunch.merge_json(json_dict, yaml.load(dict_file.read()))
bunch.merge_json(
json_dict,
yaml.load(dict_file.read(), Loader=yaml.FullLoader))
elif opt == '-p':
plugins.append(import_plugin(arg))
elif opt == '-w':
Expand All @@ -127,7 +132,7 @@ def main(argv):
for arg in args:
got_input = True
with open(arg) as f:
srcs = list(yaml.load_all(f.read()))
srcs = list(yaml.load_all(f.read(), Loader=yaml.FullLoader))
for src in srcs:
if isinstance(src, str):
assert len(srcs) == 1
Expand Down

0 comments on commit 6046624

Please sign in to comment.