From 1d23c181ce6720532af1a4df76b90565f3a100f4 Mon Sep 17 00:00:00 2001 From: jameswilburlewis Date: Sun, 25 Aug 2024 21:49:40 -0700 Subject: [PATCH] Add code to maintain backward compatibility with imports like "import pyspedas.mms", "from pyspedas.themis import fgm", etc. --- pyspedas/__init__.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pyspedas/__init__.py b/pyspedas/__init__.py index 739a6216..c5ddbb92 100644 --- a/pyspedas/__init__.py +++ b/pyspedas/__init__.py @@ -81,6 +81,32 @@ from .projects.mms.particles.mms_part_getspec import mms_part_getspec from .projects.mms.particles.mms_part_slice2d import mms_part_slice2d + +# The code below is needed for backward compatibility, so users can continue to do things +# like "from pyspedas.mms import mec" even after mms has been moved to the projects directory. + +import sys +from importlib import import_module + +# List of submodules we want to make available under the pyspedas namespace +submodules = ['ace', 'akebono', 'barrel', 'cluster', 'cnofs', 'csswe', 'de2', 'dscovr', + 'elfin', 'equator_s', 'erg', 'fast', 'geotail', 'goes', 'image', 'kompsat', + 'kyoto', 'lanl', 'maven', 'mica', 'mms', 'noaa', 'omni', 'poes', 'polar', 'psp', + 'rbsp', 'secs', 'soho', 'solo', 'st5', 'stereo', 'swarm', 'themis', 'twins', + 'ulysses' + ] + +for submodule in submodules: + # Import the module from the new path + full_module_path = f"pyspedas.projects.{submodule}" + imported_module = import_module(full_module_path) + + # Add it to sys.modules under the old path + sys.modules[f"pyspedas.{submodule}"] = imported_module + +# This set of imports is still needed for backward compatibility, when using fully-qualified +# routine names in function calls, like "pyspedas.mms.mec()" rather than "pyspedas.projects.mms.mec()" + # Make mission-specific namespaces available under pyspedas from .projects import ace from .projects import akebono