diff --git a/configuration/buildHelper.py b/configuration/buildHelper.py index ee1d104..d6971b8 100755 --- a/configuration/buildHelper.py +++ b/configuration/buildHelper.py @@ -98,10 +98,10 @@ def main(factoryFile,package,buildDir): # import isce import filecmp try: - import imp + import importlib factoryFile = os.path.abspath(factoryFile) - mod = imp.find_module(factoryFile.replace('.py','')) - factModule = imp.load_module(factoryFile.replace('.py',''),mod[0],mod[1],mod[2]) + mod = importlib.util.spec_from_file_location('.', factoryFile) + factModule = mod.loader.load_module() factoriesInfo = factModule.getFactoriesInfo() nameList = [] for k,v in factoriesInfo.items(): diff --git a/contrib/stack/stripmapStack/stripmapWrapper.py b/contrib/stack/stripmapStack/stripmapWrapper.py index 7f52d3b..7d27b91 100755 --- a/contrib/stack/stripmapStack/stripmapWrapper.py +++ b/contrib/stack/stripmapStack/stripmapWrapper.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 -import os, imp, sys +import os, sys +import importlib import argparse import configparser @@ -21,7 +22,7 @@ class ConfigParser: # Setting up and reading config Config = configparser.ConfigParser() Config.optionxform = str - Config.readfp(content) + Config.read_file(content) # Reading the function sequence followed by input parameters # followed by the function parameters @@ -94,14 +95,12 @@ class ConfigParser: # If any of the following calls raises an exception, # there's a problem we can't handle -- let the caller handle it. - fp, pathname, description = imp.find_module(name) + spec = importlib.util.find_spec(name) try: - return imp.load_module(name, fp, pathname, description) - finally: - # Since we may exit via an exception, close fp explicitly. - if fp: - fp.close() + return spec.loader.load_module() + except ImportError: + print('module {} not found'.format(name)) # Check existence of the input file def check_if_files_exist(Files, ftype='input'): diff --git a/contrib/stack/topsStack/SentinelWrapper.py b/contrib/stack/topsStack/SentinelWrapper.py index 8402e43..30b4a19 100755 --- a/contrib/stack/topsStack/SentinelWrapper.py +++ b/contrib/stack/topsStack/SentinelWrapper.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 -import os, imp, sys +import os, sys +import importlib import argparse import configparser @@ -22,7 +23,7 @@ class ConfigParser: # Setting up and reading config Config = configparser.ConfigParser() Config.optionxform = str - Config.readfp(content) + Config.read_file(content) # Reading the function sequence followed by input parameters # followed by the function parameters @@ -157,14 +158,12 @@ class ConfigParser: # If any of the following calls raises an exception, # there's a problem we can't handle -- let the caller handle it. - fp, pathname, description = imp.find_module(name) + spec = importlib.util.find_spec(name) try: - return imp.load_module(name, fp, pathname, description) - finally: - # Since we may exit via an exception, close fp explicitly. - if fp: - fp.close() + return spec.loader.load_module() + except ImportError: + print('module {} not found'.format(name)) # Check existence of the input file def check_if_files_exist(Files, ftype='input'):