Skip to content

Commit

Permalink
feat: Lazily make mission-specific namespaces available under pyspedas
Browse files Browse the repository at this point in the history
  • Loading branch information
Beforerr committed Nov 1, 2024
1 parent c585725 commit 3883c97
Showing 1 changed file with 5 additions and 45 deletions.
50 changes: 5 additions & 45 deletions pyspedas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
# 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
Expand All @@ -95,58 +94,19 @@
'rbsp', 'secs', 'soho', 'solo', 'st5', 'stereo', 'swarm', 'themis', 'themis.state', '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

def __getattr__(name):
if name in submodules:
return import_module(".projects." + name, __name__)
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

# 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
from .projects import barrel
from .projects import cluster
from .projects import cnofs
from .projects import csswe
from .projects import de2
from .projects import dscovr
from .projects import elfin
from .projects import equator_s
from .projects import erg
from .projects import fast
from .projects import geotail
from .projects import goes
from .projects import image
from .projects import kompsat
# for backward compatibility
from .projects.kompsat.load import load as kompsat_load
from .projects import kyoto
from .projects import lanl
from .projects import maven
# for backward compatibility
from .projects.maven import maven_load
from .projects import mica
from .projects import mms
from .projects import noaa
from .projects import poes
from .projects import polar
from .projects import psp
from .projects import rbsp
from .projects import secs
from .projects import soho
from .projects import solo
from .projects import st5
from .projects import stereo
from .projects import swarm
from .projects import themis
from .projects import twins
from .projects import ulysses
from . import vires
from .projects import wind

Expand Down

0 comments on commit 3883c97

Please sign in to comment.