Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean lazy_loader from module namespace #15

Merged
merged 5 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions neuro_py/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/behavior/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/ensemble/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/lfp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/plotting/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/process/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/session/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/spikes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/stats/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
6 changes: 3 additions & 3 deletions neuro_py/tuning/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lazy_loader as lazy
import lazy_loader as _lazy

(__getattr__, __dir__, __all__) = lazy.attach_stub(__name__, __file__)
del lazy
(__getattr__, __dir__, __all__) = _lazy.attach_stub(__name__, __file__)
del _lazy
41 changes: 41 additions & 0 deletions tests/test_lazy_loading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import sys


def test_lazy_loading():
# clear all neuro_py submodules
for module in list(sys.modules.keys()):
if module.startswith("neuro_py"):
sys.modules.pop(module)

import neuro_py

npy_submodules = set(
x.split(".")[1]
for x in sys.modules.keys()
if (
x.startswith("neuro_py.")
and "__" not in x
and not x.split(".")[1].startswith("_")
and sys.modules[x] is not None
)
)

# ensure that no submodules have been imported yet
assert npy_submodules == set(), \
f"Submodules already loaded: {npy_submodules}"

# ensure that only the accessed submodule has been imported
neuro_py.behavior
npy_submodules = set(
x.split(".")[1]
for x in sys.modules.keys()
if (
x.startswith("neuro_py.")
and "__" not in x
and not x.split(".")[1].startswith("_")
and sys.modules[x] is not None
)
)
assert npy_submodules == {
"behavior"
}, f"Submodules already loaded: {npy_submodules}"
Loading