From 3483ab0fb6630f9aa9cd8d6d1fe7a6fee2a0896b Mon Sep 17 00:00:00 2001 From: Kyle Gentle Date: Thu, 18 Aug 2022 21:10:07 -0400 Subject: [PATCH] Remove dynamic imports in mako-render It's cheap to `import json`, and with recent versions of python the `simplejson` lib isn't required. --- etc/bin/mako-render | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/etc/bin/mako-render b/etc/bin/mako-render index 20ed422307..f10190eba3 100644 --- a/etc/bin/mako-render +++ b/etc/bin/mako-render @@ -4,10 +4,13 @@ # This module is part of Mako and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php from argparse import ArgumentParser +from copy import deepcopy from importlib import import_module from os.path import isfile, dirname +import json import os import sys +import yaml from mako.template import Template from mako.lookup import TemplateLookup from mako import exceptions @@ -213,27 +216,17 @@ def load_data(datafiles): :Returns: data (dict) :Raises: ImportError, ValueError """ - imported_json = False imported_yaml = False mydata = {} for filename, namespace in datafiles: data = None if filename[-5:].lower() == ".json": - if not imported_json: - try: - import simplejson as json - except ImportError: - import json - imported_json = True try: data = json.load(open(filename, 'r')) except ValueError as err: raise ValueError("Invalid JSON in file '%s'. (%s)" % (filename, str(err))) elif filename[-5:].lower() in (".yaml", ".yml"): - if not imported_yaml: - import yaml - imported_yaml = True data = yaml.load_all(open(filename, 'r'), Loader=yaml.loader.FullLoader) data = list(data)[0] else: