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

Define separate entrypoints for translator plugins and make requirements optional #76

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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: 5 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
- Updated ``AstropyRegions`` translator to export ``roi.theta`` angle
(supported as of ``glue`` 1.5.0). [#73]

- Added support to import and export specreduce Trace objects. [#72]
- Added support to import and export ``specreduce`` ``Trace`` objects. [#72]

- Translators for ``CCDData``, ``regions``, ``Spectrum1D``, ``SpectralCube``
and ``specreduce.tracing.Trace`` objects are now loaded upon availability,
making the corresponding packages optional requirements. [#76]

0.4.0 (2022-04-07)
------------------
Expand Down
4 changes: 0 additions & 4 deletions glue_astronomy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
from .version import version as __version__ # noqa


def setup():
from glue_astronomy import translators # noqa
13 changes: 11 additions & 2 deletions glue_astronomy/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
def pytest_configure(config):
from glue_astronomy import setup
setup()
from glue_astronomy.translators import (setup_ccddata,
setup_regions,
setup_spectral_cube,
setup_spectrum1d,
setup_trace)

setup_ccddata()
setup_regions()
setup_spectral_cube()
setup_spectrum1d()
setup_trace()
23 changes: 18 additions & 5 deletions glue_astronomy/translators/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
from . import ccddata # noqa
from . import regions # noqa
from . import spectral_cube # noqa
from . import spectrum1d # noqa
from . import trace # noqa
def setup_ccddata():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this. If they are only used in tests now, why pollute __init__.py and not just make them test fixtures?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not just used by tests, these functions are executed by the glue plugin loader

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay... I see that these invoke some entry point dark magic. Nvm.

from . import ccddata # noqa


def setup_regions():
from . import regions # noqa


def setup_spectral_cube():
from . import spectral_cube # noqa


def setup_spectrum1d():
from . import spectrum1d # noqa


def setup_trace():
from . import trace # noqa
17 changes: 13 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ setup_requires =
install_requires =
astropy>=4.0
glue-core>=1.0

[options.extras_require]
all =
regions>=0.4
specutils>=0.7
specreduce>=1.0.0
spectral-cube>=0.6.0

[options.extras_require]
docs =
sphinx
sphinx-automodapi
Expand All @@ -36,13 +37,21 @@ test =
pytest-astropy
pytest-cov
mock
regions>=0.4
specutils>=0.7
specreduce>=1.0.0
spectral-cube>=0.6.0
qt =
PyQt5

[options.entry_points]
glue.plugins =
glue_astronomy = glue_astronomy:setup
spectral_cube = glue_astronomy.io.spectral_cube:setup
ccddata = glue_astronomy.translators:setup_ccddata
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should give slightly more explicit names to the plugins so that things are clear when we are able to load them individually in future. Translators should probably be called e.g. ccddata_translator

regions = glue_astronomy.translators:setup_regions
spectrum1d = glue_astronomy.translators:setup_spectrum1d
spectral_cube = glue_astronomy.translators:setup_spectral_cube
spectral_cube_io = glue_astronomy.io.spectral_cube:setup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think spectral_cube_io is fine as it covers the data factory and the command-line parser

trace = glue_astronomy.translators:setup_trace
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trace is not very clear (not your fault but we should have named it better in glue-astronomy in the first place). I think we should probably rename all instances of trace (or related classes) to something like specreduce_trace - then the translator should be specreduce_trace_translator.


[options.package_data]
glue_astronomy.io.spectral_cube.tests = data/*, data/*/*, data/*/*/*
Expand Down