From 91e1289bc4180cd385c1c9c4a358f26cf5cf2d1b Mon Sep 17 00:00:00 2001
From: Eva Schiffer <evas@ssec.wisc.edu>
Date: Fri, 17 Jul 2020 16:20:02 -0500
Subject: [PATCH] moving from imp to importlib for loading our configuration
 files

---
 pyglance/glance/config_organizer.py | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/pyglance/glance/config_organizer.py b/pyglance/glance/config_organizer.py
index 5a3c319..6d135a7 100644
--- a/pyglance/glance/config_organizer.py
+++ b/pyglance/glance/config_organizer.py
@@ -10,7 +10,7 @@ Created by evas Dec 2012.
 Copyright (c) 2012 University of Wisconsin SSEC. All rights reserved.
 """
 
-import os, sys, imp, logging, re
+import os, sys, importlib, logging, re
 import argparse
 
 import glance.io as io
@@ -311,6 +311,17 @@ def _get_missing_values_if_needed(fileA, fileB,
     
     return missing_value_A, missing_value_B
 
+def _import_module(full_name, full_file_path,) :
+    """
+    load up a python module from a file on the fly, this should be used when loading configuration files for Glance
+    """
+
+    spec = importlib.util.spec_from_file_location(full_name, full_file_path,)
+    mod  = importlib.util.module_from_spec(spec)
+
+    spec.loader.exec_module(mod)
+    return mod
+
 # TODO, right now this is the top level function that the library functions in
 # compare.py call
 def load_config_or_options(aPath, bPath, optionsSet, requestedVars = [ ]) :
@@ -373,9 +384,11 @@ def load_config_or_options(aPath, bPath, optionsSet, requestedVars = [ ]) :
             
             # load the file
             LOG.debug ('loading config file: ' + str(requestedConfigFile))
-            glanceRunConfig = imp.load_module(fileBaseName, file(requestedConfigFile, 'U'),
-                                              requestedConfigFile, ('.py' , 'U', 1))
-            
+            glanceRunConfig = _import_module(fileBaseName, requestedConfigFile,)
+            #import imp
+            #glanceRunConfig = imp.load_module(fileBaseName, open(requestedConfigFile, 'U'),
+            #                                  requestedConfigFile, ('.py' , 'U', 1))
+
             # this is an exception, since it is not advertised to the user we don't expect it to be in the file
             # (at least not at the moment, it could be added later and if they did happen to put it in the
             # config file, it would override this line)
-- 
GitLab