-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## main #76 +/- ##
==========================================
+ Coverage 97.46% 97.47% +0.01%
==========================================
Files 17 17
Lines 1223 1230 +7
==========================================
+ Hits 1192 1199 +7
Misses 31 31
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
a610506
to
de60544
Compare
de60544
to
b9e1785
Compare
@pllim if you want to check this for your dependency tree... |
from . import spectral_cube # noqa | ||
from . import spectrum1d # noqa | ||
from . import trace # noqa | ||
def setup_ccddata(): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
I checked out this branch and then do a clean install using
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good but doesn't do anything because glue-core else stills pulls in spectral-cube , as Derek suspected. See glue-viz/glue#2316
Yes, apparently when running without |
Also, I think this breaks translator lookup on Jdaviz. I forgot to uninstall this branch and was working on something else and glue complained that it cannot find translator for Spectrum1D . |
Is specutils installed in that branch? |
Yes, specutils 1.7.1.dev (though might not be the latest dev). Once I uninstalled this branch and installed the released glue-astronomy , things worked again. |
Can you pin that down to a failure within glue, or does it only happen in the jdaviz environment? FWIW glue tests are passing locally for me with no glue-astronomy installed at all, with this branch I am getting e.g. in =================================================================== short test summary info ====================================================================
FAILED glue/core/tests/test_data_translation.py::TestTranslationData::test_get_object_explicit_class - AssertionError: assert 'Specify the ...akeDataObject' ...
FAILED glue/core/tests/test_data_translation.py::TestTranslationData::test_get_subset_object_explicit_class - AssertionError: assert 'Specify the ...akeDataO..
================================================== 2 failed, 10 passed, 2007 deselected, 7 warnings in 0.84s =================================================== but with released glue-astronomy versions (0.4 or 0.1), it's even one more failure! FAILED glue/core/tests/test_data_translation.py::TestTranslationData::test_get_object_explicit_class - AssertionError: assert 'Specify the ...akeDataObject' ...
FAILED glue/core/tests/test_data_translation.py::TestTranslationData::test_get_subset_object_explicit_class - AssertionError: assert 'Specify the ...akeDataO...
FAILED glue/core/tests/test_data_translation.py::TestTranslationData::test_get_selection_invalid - assert "Subset state...t_translator'" == "Subset state...t...
=================================================== 3 failed, 9 passed, 2007 deselected, 7 warnings in 0.93s =================================================== Apparently glue-core has no test setup with glue-astronomy installed defined. |
Since you can get error in glue-core, do you still need me to dig at Jdaviz? If so, please lemme know and I'll try tomorrow. Thanks! glue was complaining it can't find translator for Spectrum1D but I don't have the traceback right now. |
Yes, would be good to know what did work in 0.4.0 and broke now – I only find 3 identical failures in all of glue.core, and this one with 0.4.0 that no longer fails with 0.4.1dev. Thanks! ________________________________________________________ TestTranslationData.test_get_selection_invalid ________________________________________________________
...
with pytest.raises(ValueError) as exc:
data.get_selection_definition(subset_id=0)
> assert exc.value.args[0] == ("Subset state handler format not set - should be one "
"of:\n\n* 'my_subset_translator'")
E assert ('Subset state handler format not set - should be one of:\n'\n '\n'\n "* 'astropy-regions'\n"\n "* 'my_subset_translator'") == ('Subset state handler format not set - should be one of:\n'\n '\n'\n "* 'my_subset_translator'")
E Subset state handler format not set - should be one of:
E
E + * 'astropy-regions'
E * 'my_subset_translator' |
Okay, here is the traceback with this branch: from astropy.utils.data import download_file
from jdaviz import Cubeviz
fn = download_file('https://stsci.box.com/shared/static/28a88k1qfipo4yxc4p4d40v4axtlal8y.fits', cache=True)
cubeviz = Cubeviz()
cubeviz.load_data(fn)
|
OK. I note that try:
setup_spectrum1d()
except ImportError:
pass and so on for every single translator (would there even be a point in having separate entry points then?)! @astrofrog is the above import as done by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dhomeier - jdaviz should not be importing glue_astronomy.translators
but instead jdaviz should really just be calling load_plugins
from glue-core. If there is a desire to specify a limited list of plugins to load, we should modify load_plugins
to take an optional list of plugins to load.
Where is the documentation telling us how to do this? I cannot find it. |
I think the idea is to first |
Entry points are not executed on glue_astronomy import but instead when As mentioned above, it would probably be nice to have a way of specifying a list or a single plugin to load in load_plugins, and perhaps also a way to easily list plugins with a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should get this moving again - I've left a few comments below. To keep things simpler discussion wise, I would suggest removing the change related to making the dependencies optional and focusing for now on making the plugins individually defined.
In glue-viz/glue#2447 I've mentioned that we need to improve load_plugins
for use downstream in e.g. jdaviz.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
spectrum1d = glue_astronomy.translators:setup_spectrum1d | ||
spectral_cube = glue_astronomy.translators:setup_spectral_cube | ||
spectral_cube_io = glue_astronomy.io.spectral_cube:setup | ||
trace = glue_astronomy.translators:setup_trace |
There was a problem hiding this comment.
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
.
Description
Giving each plugin its own entry point so it can be loaded on demand/availability.
This allows making
regions
,specutils
,specreduce
andspectral-cube
optional dependencies; they will also be installed with theglue-astronomy[all]
andglue-astronomy[test]
options.To be discussed if there is a preferable
options.extras_require
setup or if the tests should also just try the imports and pass, if not installed.