Skip to content

Commit

Permalink
Merge pull request #595 from MridulS/lazy
Browse files Browse the repository at this point in the history
 MAINT: Use lazy_loader for lazy loading of submodules
  • Loading branch information
SimonHeybrock authored Jan 28, 2025
2 parents c6508fd + 8d2d0c1 commit 79be73f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 57 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dynamic = ["version"]
# Run 'tox -e deps' after making changes here. This will update requirement files.
# Make sure to list one dependency per line.
dependencies = [
"lazy_loader",
"h5py",
"mpltoolbox",
"numpy>=1.20",
Expand Down
70 changes: 25 additions & 45 deletions src/scippneutron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,30 @@
except importlib.metadata.PackageNotFoundError:
__version__ = "0.0.0"

from .beamline_components import (
position,
source_position,
sample_position,
incident_beam,
scattered_beam,
Ltotal,
L1,
L2,
two_theta,
)
from .core import convert
from .mantid import (
from_mantid,
to_mantid,
load_with_mantid,
fit,
)
from .instrument_view import instrument_view
from .masking import MaskingTool
from . import atoms
from . import chopper
from . import io

del importlib

__all__ = [
"position",
"source_position",
"sample_position",
"incident_beam",
"scattered_beam",
"Ltotal",
"L1",
"L2",
"two_theta",
"convert",
"from_mantid",
"to_mantid",
"io",
"load_with_mantid",
"fit",
"instrument_view",
"atoms",
"chopper",
"MaskingTool",
]
import lazy_loader as lazy

submodules = ['atoms' 'chopper', 'io']

__getattr__, __dir__, __all__ = lazy.attach(
__name__,
submodules=submodules,
submod_attrs={
'beamline_components': [
'position',
'source_position',
'sample_position',
'incident_beam',
'scattered_beam',
'Ltotal',
'L1',
'L2',
'two_theta',
],
'core': ['convert'],
'mantid': ['from_mantid', 'to_mantid', 'load_with_mantid', 'fit'],
'instrument_view': ['instrument_view'],
'masking': ['MaskingTool'],
},
)
20 changes: 9 additions & 11 deletions src/scippneutron/chopper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@

"""Chopper utilities."""

from .disk_chopper import DiskChopper, DiskChopperType
from .filtering import collapse_plateaus, filter_in_phase, find_plateaus
from .nexus_chopper import extract_chopper_from_nexus
import lazy_loader as lazy

__all__ = [
'DiskChopper',
'DiskChopperType',
'collapse_plateaus',
'filter_in_phase',
'find_plateaus',
'extract_chopper_from_nexus',
]
__getattr__, __dir__, __all__ = lazy.attach(
__name__,
submod_attrs={
'disk_chopper': ['DiskChopper', 'DiskChopperType'],
'filtering': ['collapse_plateaus', 'filter_in_phase', 'find_plateaus'],
'nexus_chopper': ['extract_chopper_from_nexus'],
},
)
9 changes: 8 additions & 1 deletion src/scippneutron/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
"""File input and output."""

from .xye import load_xye, save_xye # noqa: F401
import lazy_loader as lazy

__getattr__, __dir__, __all__ = lazy.attach(
__name__,
submod_attrs={
'xye': ['load_xye', 'save_xye'],
},
)

0 comments on commit 79be73f

Please sign in to comment.