-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
7d46709
commit 0b11723
Showing
15 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ toolbar: | |
tray: | ||
- g-subset-plugin | ||
- g-gaussian-smooth | ||
- export | ||
- export | ||
- about |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .about import * # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
30
jdaviz/configs/default/plugins/about/tests/test_about_plugin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ tray: | |
- imviz-catalogs | ||
- imviz-footprints | ||
- export | ||
- about | ||
viewer_area: | ||
- container: col | ||
children: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters