Skip to content

Commit

Permalink
About plugin (#2886)
Browse files Browse the repository at this point in the history
* About plugin

* TST: Mark uncovered logic routes

* Remove repeated text

Co-authored-by: Kyle Conroy <[email protected]>

* Use f-string

Co-authored-by: Ricky O'Steen <[email protected]>

* Add link to RTD doc
as Gilbert suggested

---------

Co-authored-by: Kyle Conroy <[email protected]>
Co-authored-by: Ricky O'Steen <[email protected]>
  • Loading branch information
3 people authored May 24, 2024
1 parent 7d46709 commit 0b11723
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
New Features
------------

- Adding flux/surface brightness translation and surface brightness
- Added flux/surface brightness translation and surface brightness
unit conversion in Cubeviz and Specviz. [#2781]

- Plugin tray is now open by default. [#2892]

- New "About" plugin to show Jdaviz version info. [#2886]

Cubeviz
^^^^^^^

Expand Down
3 changes: 3 additions & 0 deletions docs/reference/api_plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
Plugins API
===========

.. automodapi:: jdaviz.configs.default.plugins.about.about
:no-inheritance-diagram:

.. automodapi:: jdaviz.configs.default.plugins.collapse.collapse
:no-inheritance-diagram:

Expand Down
1 change: 1 addition & 0 deletions jdaviz/configs/cubeviz/cubeviz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ tray:
- cubeviz-moment-maps
- imviz-aper-phot-simple
- export
- about
viewer_area:
- container: col
children:
Expand Down
3 changes: 2 additions & 1 deletion jdaviz/configs/default/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ toolbar:
tray:
- g-subset-plugin
- g-gaussian-smooth
- export
- export
- about
1 change: 1 addition & 0 deletions jdaviz/configs/default/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
from .plot_options.plot_options import * # noqa
from .markers.markers import * # noqa
from .data_quality.data_quality import * # noqa
from .about.about import * # noqa
1 change: 1 addition & 0 deletions jdaviz/configs/default/plugins/about/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .about import * # noqa
56 changes: 56 additions & 0 deletions jdaviz/configs/default/plugins/about/about.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import json

import requests
from packaging.version import Version
from traitlets import Bool, Unicode

from jdaviz.core.registries import tray_registry
from jdaviz.core.template_mixin import PluginTemplateMixin

try:
from jdaviz import __version__
except ImportError: # pragma: no cover
__version__ = "unknown"

__all__ = ['About']


@tray_registry('about', label="About")
class About(PluginTemplateMixin):
"""Show information about Jdaviz."""
template_file = __file__, "about.vue"

jdaviz_version = Unicode("unknown").tag(sync=True)
jdaviz_pypi = Unicode("unknown").tag(sync=True)
not_is_latest = Bool(False).tag(sync=True)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.jdaviz_version = __version__

if __version__ != "unknown":
_ver_pypi = latest_version_from_pypi("jdaviz")
if _ver_pypi:
self.jdaviz_pypi = _ver_pypi
self.not_is_latest = Version(__version__) < Version(_ver_pypi)
else: # pragma: no cover
self.jdaviz_pypi = "unknown"
self.not_is_latest = False


def latest_version_from_pypi(package_name):
"""Version info for given package or `None`."""
url = f"https://pypi.org/pypi/{package_name}/json"
try:
r = requests.get(url, timeout=60)
except Exception: # nosec # pragma: no cover
pass
else:
if r.ok:
try:
d = json.loads(r.text)
v = d["info"]["version"]
except Exception: # nosec # pragma: no cover
pass
else:
return v
42 changes: 42 additions & 0 deletions jdaviz/configs/default/plugins/about/about.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<template>
<j-tray-plugin
:description="docs_description || 'About Jdaviz.'"
:link="docs_link || 'https://jdaviz.readthedocs.io/en/'+vdocs+'/'"
:popout_button="popout_button"
:scroll_to.sync="scroll_to">

<v-row>
<v-text-field class="v-messages v-messages__message text--secondary"
v-model="jdaviz_version"
label="Version"
hint="Version of installed Jdaviz."
readonly>
</v-text-field>
</v-row>

<v-row v-if="not_is_latest">
<span class="v-messages v-messages__message text--secondary" style="color: red !important">
A newer version ({{ jdaviz_pypi }}) is available from PyPI.
</span>
<j-docs-link link="https://pypi.org/project/jdaviz/" linktext="Go to PyPI">
Please update Jdaviz and restart your session.
</j-docs-link>

</v-row>

<v-row>
<j-docs-link link="https://github.com/spacetelescope/jdaviz/blob/main/CHANGES.rst" linktext="Change Log">
To see list of changes, go to your version section in the

</j-docs-link>
</v-row>

<v-row>
<j-docs-link link="https://jwsthelp.stsci.edu" linktext="JWST Help Desk">
For further assistance, please contact the

</j-docs-link>
</v-row>

</j-tray-plugin>
</template>
Empty file.
30 changes: 30 additions & 0 deletions jdaviz/configs/default/plugins/about/tests/test_about_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pytest

from jdaviz import __version__
from jdaviz.configs.default.plugins.about.about import latest_version_from_pypi


@pytest.mark.remote_data
def test_get_latest_version_from_pypi():
# Since the latest version will change over time,
# we can only check that something is returned but not what exactly.

v = latest_version_from_pypi("jdaviz")
assert isinstance(v, str)

v = latest_version_from_pypi("fakespacetelescopepackage")
assert v is None


# NOTE: Theoretically now all the tests in jdaviz are remote data tests
# because all the viz loads About plugin and About plugin always polls
# PyPI for the latest release version. If that bothers you or PyPI
# starts blocking us as spammer, we can consider caching it at package level
# but that introduces new non-standard package attributes.
def test_about_basic(specviz_helper):
plg = specviz_helper.plugins["About"]._obj

assert plg.jdaviz_version == __version__
assert isinstance(plg.jdaviz_pypi, str)
# not_is_latest can be non-deterministic because user can be running
# this test from an older version going forward, so we skip checking it.
1 change: 1 addition & 0 deletions jdaviz/configs/imviz/imviz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ tray:
- imviz-catalogs
- imviz-footprints
- export
- about
viewer_area:
- container: col
children:
Expand Down
1 change: 1 addition & 0 deletions jdaviz/configs/mosviz/mosviz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ tray:
- g-line-list
- specviz-line-analysis
- export
- about
viewer_area:
- container: col
children:
Expand Down
1 change: 1 addition & 0 deletions jdaviz/configs/specviz/specviz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ tray:
- g-line-list
- specviz-line-analysis
- export
- about
viewer_area:
- container: col
children:
Expand Down
1 change: 1 addition & 0 deletions jdaviz/configs/specviz2d/specviz2d.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ tray:
- g-line-list
- specviz-line-analysis
- export
- about
viewer_area:
- container: col
children:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies = [
"sidecar>=0.5.2",
"ipypopout>=0.0.11",
"astroquery",
"requests",
]
dynamic = [
"version",
Expand Down

0 comments on commit 0b11723

Please sign in to comment.