Resolve warnings and deprecations in several scripts in tools

pull/24673/head
Lidi Zheng 5 years ago
parent 2ebd3c3c02
commit 76aade3eac
  1. 2
      src/abseil-cpp/gen_build_yaml.py
  2. 2
      test/cpp/naming/gen_build_yaml.py
  3. 23
      tools/buildgen/mako_renderer.py

@ -20,7 +20,7 @@ import yaml
BUILDS_YAML_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), BUILDS_YAML_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)),
'preprocessed_builds.yaml') 'preprocessed_builds.yaml')
with open(BUILDS_YAML_PATH) as f: with open(BUILDS_YAML_PATH) as f:
builds = yaml.load(f) builds = yaml.load(f, Loader=yaml.FullLoader)
for build in builds: for build in builds:
build['build'] = 'private' build['build'] = 'private'

@ -65,7 +65,7 @@ def _resolver_test_cases(resolver_component_data):
def main(): def main():
resolver_component_data = '' resolver_component_data = ''
with open('test/cpp/naming/resolver_test_record_groups.yaml') as f: 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 = { json = {
'resolver_tests_common_zone_name': 'resolver_tests_common_zone_name':

@ -15,28 +15,31 @@
"""Simple Mako renderer. """Simple Mako renderer.
Just a wrapper around the mako rendering library. Just a wrapper around the mako rendering library.
""" """
import getopt import getopt
import imp import importlib
import os import os
import pickle import pickle
import shutil import shutil
import sys import sys
import yaml
from mako.lookup import TemplateLookup from mako.lookup import TemplateLookup
from mako.runtime import Context from mako.runtime import Context
from mako.template import Template from mako.template import Template
import bunch import bunch
import yaml
# Imports a plugin # Imports a plugin
def import_plugin(name): def import_plugin(path):
_, base_ex = os.path.split(name) module_name = os.path.basename(path).replace('.py', '')
base, _ = os.path.splitext(base_ex) spec = importlib.util.spec_from_file_location(module_name, path)
return imp.load_source(base, name) module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
spec.loader.exec_module(module)
return module
def out(msg): def out(msg):
@ -104,7 +107,9 @@ def main(argv):
elif opt == '-d': elif opt == '-d':
assert not got_preprocessed_input assert not got_preprocessed_input
with open(arg, 'r') as dict_file: 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': elif opt == '-p':
plugins.append(import_plugin(arg)) plugins.append(import_plugin(arg))
elif opt == '-w': elif opt == '-w':
@ -127,7 +132,7 @@ def main(argv):
for arg in args: for arg in args:
got_input = True got_input = True
with open(arg) as f: 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: for src in srcs:
if isinstance(src, str): if isinstance(src, str):
assert len(srcs) == 1 assert len(srcs) == 1

Loading…
Cancel
Save