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

Convert an automatic registration into an option #1068

Merged
merged 2 commits into from
Jul 31, 2023
Merged
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
12 changes: 7 additions & 5 deletions specutils/io/registers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _astropy_has_priorities():


def data_loader(label, identifier=None, dtype=Spectrum1D, extensions=None,
priority=0, force=False, verbose=False):
priority=0, force=False, autogenerate_spectrumlist=True, verbose=False):
"""
Wraps a function that can be added to an `~astropy.io.registry` for custom
file reading.
Expand All @@ -51,6 +51,9 @@ def data_loader(label, identifier=None, dtype=Spectrum1D, extensions=None,
force : bool, optional
Whether to override any existing function if already present.
Default is ``False``. Passed down to astropy registry.
autogenerate_spectrumlist : bool, optional
Whether to automatically register a SpectrumList reader for any
data_loader that reads Spectrum1D objects. Default is ``True``.
verbose : bool
Print extra info.

Expand Down Expand Up @@ -105,10 +108,9 @@ def decorator(func):
if verbose:
print(f"Successfully loaded reader \"{label}\".")

# Automatically register a SpectrumList reader for any data_loader that
# reads Spectrum1D objects. TODO: it's possible that this
# functionality should be opt-in rather than automatic.
if dtype is Spectrum1D:
# Optionally register a SpectrumList reader for any data_loader that
# reads Spectrum1D objects.
if dtype is Spectrum1D and autogenerate_spectrumlist:
def load_spectrum_list(*args, **kwargs):
return SpectrumList([ func(*args, **kwargs) ])

Expand Down