From 966db8c4dd3b597023d2ace37df56d5a777343f5 Mon Sep 17 00:00:00 2001 From: "Pey Lian Lim (Github)" <2090236+pllim@users.noreply.github.com> Date: Wed, 23 Feb 2022 13:33:06 -0500 Subject: [PATCH 1/2] MNT: Modernize packaging. Turn unhandled warnings into exceptions. Update test matrix. Fix test package data. Handle test warnings. --- .gitignore | 35 ++++++++++++--- .readthedocs.yml | 11 ++++- MANIFEST.in | 8 ++++ azure-pipelines.yml | 10 ++--- docs/conf.py | 8 +++- glue_astronomy/__init__.py | 7 +-- .../spectral_cube/tests/test_spectral_cube.py | 43 ++++++++----------- .../data => translators/tests}/__init__.py | 0 .../translators/tests/test_spectrum1d.py | 5 ++- pyproject.toml | 5 +++ setup.cfg | 19 +++++++- setup.py | 15 ++----- tox.ini | 4 +- 13 files changed, 106 insertions(+), 64 deletions(-) create mode 100644 MANIFEST.in rename glue_astronomy/{io/spectral_cube/tests/data => translators/tests}/__init__.py (100%) create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore index 0de6cd8..2d58898 100644 --- a/.gitignore +++ b/.gitignore @@ -2,25 +2,38 @@ build docs/_build docs/api -glue/tests/htmlcov *.coverage *htmlcov* # Packages/installer info -docs/.eggs +*.egg *.egg-info dist +build +eggs +.eggs +parts +bin +var +sdist +develop-eggs +.installed.cfg +distribute-*.tar.gz +MANIFEST +glue_astronomy/version.py +pip-wheel-metadata/ # Compiled files -*.pyc - -# Other generated files -glue/_githash.py +*.py[cod] +*.a +*.o +*.so +*.pyd +__pycache__ # Other .pylintrc *.ropeproject -glue/qt/glue_qt_resources.py *.__junk* *.orig *~ @@ -32,6 +45,9 @@ glue/qt/glue_qt_resources.py # PyCharm .idea +# VS code +.vscode + # Eclipse editor project files .project .pydevproject @@ -43,3 +59,8 @@ glue/qt/glue_qt_resources.py .tox .html + +# Env +.venv +venv +.env diff --git a/.readthedocs.yml b/.readthedocs.yml index 961e968..8993130 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,10 +1,17 @@ version: 2 build: - image: latest + os: ubuntu-20.04 + tools: + python: "3.9" + +sphinx: + builder: html + configuration: docs/conf.py + fail_on_warning: true python: - version: 3.6 + system_packages: false install: - method: pip path: . diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..357e3a1 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,8 @@ +include LICENSE +include README.rst +include CHANGES.rst + +include setup.cfg +include pyproject.toml + +global-exclude *.pyc *.o diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 23ef365..cc5d3a4 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -27,15 +27,13 @@ jobs: coverage: 'false' - linux: py36-test-casa - - linux: py37-test - linux: py38-test - - linux: py38-test-dev + - linux: py39-test + - linux: py310-test-dev - macos: py36-test-casa - windows: py37-test - macos: py38-test - - windows: py38-test-dev + - windows: py39-test-dev - - linux: py36-docs - - macos: py37-docs - - windows: py38-test + - linux: py39-docs diff --git a/docs/conf.py b/docs/conf.py index b420098..94eca2b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -3,7 +3,8 @@ # Glue documentation build configuration file import os -from pkg_resources import get_distribution + +from glue_astronomy import __version__ # -- General configuration ---------------------------------------------------- @@ -57,7 +58,10 @@ # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. -version = release = get_distribution('glue-core').version +# The full version, including alpha/beta/rc tags. +release = __version__ +# The short X.Y version. +version = '.'.join(release.split('.')[:2]) # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. diff --git a/glue_astronomy/__init__.py b/glue_astronomy/__init__.py index b8eb8b1..e64201e 100644 --- a/glue_astronomy/__init__.py +++ b/glue_astronomy/__init__.py @@ -1,9 +1,4 @@ -from pkg_resources import get_distribution, DistributionNotFound - -try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: - pass +from .version import version as __version__ # noqa def setup(): diff --git a/glue_astronomy/io/spectral_cube/tests/test_spectral_cube.py b/glue_astronomy/io/spectral_cube/tests/test_spectral_cube.py index 3353a51..1658a4f 100644 --- a/glue_astronomy/io/spectral_cube/tests/test_spectral_cube.py +++ b/glue_astronomy/io/spectral_cube/tests/test_spectral_cube.py @@ -1,57 +1,52 @@ -import os +import numpy as np import pytest +from astropy.utils.data import get_pkg_data_filename from glue.qglue import parse_data +from spectral_cube import SpectralCube -DATA = os.path.join(os.path.dirname(__file__), 'data') +from glue_astronomy.io.spectral_cube.spectral_cube import is_spectral_cube, read_spectral_cube def test_identifier_fits(): - from ..spectral_cube import is_spectral_cube - assert is_spectral_cube(os.path.join(DATA, 'cube_3d.fits')) + assert is_spectral_cube(get_pkg_data_filename('data/cube_3d.fits')) def test_identifier_casa(): pytest.importorskip('casatools') - from ..spectral_cube import is_spectral_cube - assert is_spectral_cube(os.path.join(DATA, 'cube_3d.image')) + assert is_spectral_cube(get_pkg_data_filename('data/cube_3d.image')) def test_reader_fits(): - from ..spectral_cube import read_spectral_cube - data = read_spectral_cube(os.path.join(DATA, 'cube_3d.fits')) - data['STOKES I'] + data = read_spectral_cube(get_pkg_data_filename('data/cube_3d.fits')) + assert isinstance(data['STOKES I'], np.ndarray) assert data.shape == (2, 3, 4) def test_reader_fits_4d(): - from ..spectral_cube import read_spectral_cube - data = read_spectral_cube(os.path.join(DATA, 'cube_4d.fits')) - data['STOKES I'] + data = read_spectral_cube(get_pkg_data_filename('data/cube_4d.fits')) + assert isinstance(data['STOKES I'], np.ndarray) assert data.shape == (2, 3, 4) def test_reader_fits_4d_fullstokes(): - from ..spectral_cube import read_spectral_cube - data = read_spectral_cube(os.path.join(DATA, 'cube_4d_fullstokes.fits')) - data['STOKES I'] - data['STOKES Q'] - data['STOKES U'] - data['STOKES V'] + data = read_spectral_cube(get_pkg_data_filename('data/cube_4d_fullstokes.fits')) + assert isinstance(data['STOKES I'], np.ndarray) + assert isinstance(data['STOKES Q'], np.ndarray) + assert isinstance(data['STOKES U'], np.ndarray) + assert isinstance(data['STOKES V'], np.ndarray) assert data.shape == (2, 3, 4) def test_reader_casa(): pytest.importorskip('casatools') - from ..spectral_cube import read_spectral_cube - data = read_spectral_cube(os.path.join(DATA, 'cube_3d.image')) - data['STOKES I'] + data = read_spectral_cube(get_pkg_data_filename('data/cube_3d.image')) + assert isinstance(data['STOKES I'], np.ndarray) assert data.shape == (2, 3, 4) def test_qglue(): - from spectral_cube import SpectralCube - cube = SpectralCube.read(os.path.join(DATA, 'cube_3d.fits')) + cube = SpectralCube.read(get_pkg_data_filename('data/cube_3d.fits')) data = parse_data(cube, 'x')[0] assert data.label == 'x' - data['flux'] + assert isinstance(data['flux'], np.ndarray) assert data.shape == (2, 3, 4) diff --git a/glue_astronomy/io/spectral_cube/tests/data/__init__.py b/glue_astronomy/translators/tests/__init__.py similarity index 100% rename from glue_astronomy/io/spectral_cube/tests/data/__init__.py rename to glue_astronomy/translators/tests/__init__.py diff --git a/glue_astronomy/translators/tests/test_spectrum1d.py b/glue_astronomy/translators/tests/test_spectrum1d.py index 88685b4..d71f81a 100644 --- a/glue_astronomy/translators/tests/test_spectrum1d.py +++ b/glue_astronomy/translators/tests/test_spectrum1d.py @@ -9,6 +9,7 @@ from astropy.tests.helper import assert_quantity_allclose from astropy.nddata import VarianceUncertainty from astropy.coordinates import SpectralCoord +from astropy.utils.exceptions import AstropyUserWarning from glue.core import Data, DataCollection from glue.core.component import Component @@ -124,6 +125,7 @@ def test_to_spectrum1d_default_attribute(): 'keyword argument.') +@pytest.mark.filterwarnings('ignore:Input WCS indicates that the spectral axis is not last') @pytest.mark.parametrize('mode', ('wcs1d', 'wcs3d', 'lookup')) def test_from_spectrum1d(mode): @@ -250,7 +252,8 @@ def test_spectrum1d_2d_data(): assert isinstance(s, SpectralCoord) # Check round-tripping of coordinates - px, py = data.coords.world_to_pixel(s, o) + with pytest.warns(AstropyUserWarning, match='No observer defined on WCS'): + px, py = data.coords.world_to_pixel(s, o) assert_allclose(px, 1) assert_allclose(py, 2) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..590e0b1 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,5 @@ +[build-system] +requires = ["setuptools>=30.3.0", + "setuptools_scm", + "wheel"] +build-backend = 'setuptools.build_meta' diff --git a/setup.cfg b/setup.cfg index 7e0823d..deb01ce 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,11 +8,14 @@ license_file = LICENSE url = https://github.com/glue-viz/glue-astronomy description = Astronomy-specific plugins for glue long_description = file: README.rst +long_description_content_type = text/x-rst [options] zip_safe = False packages = find: python_requires = >=3.6 +setup_requires = + setuptools_scm install_requires = astropy>=4.0 glue-core>=1.0 @@ -29,6 +32,7 @@ docs = sphinx-rtd-theme test = pytest + pytest-doctestplus pytest-cov mock qt = @@ -39,6 +43,17 @@ glue.plugins = glue_astronomy = glue_astronomy:setup spectral_cube = glue_astronomy.io.spectral_cube:setup +[options.package_data] +glue_astronomy.io.spectral_cube.tests = data/*, data/*/*, data/*/*/* + [tool:pytest] -addopts=-p no:logging -doctest_plug = enabled +minversion = 6 +testpaths = docs glue_astronomy +doctest_plus = enabled +xfail_strict = true +filterwarnings = + error + ignore:numpy\.ndarray size changed:RuntimeWarning + +[flake8] +max-line-length = 100 diff --git a/setup.py b/setup.py index d9c9284..beea8d9 100755 --- a/setup.py +++ b/setup.py @@ -1,15 +1,6 @@ #!/usr/bin/env python -from __future__ import print_function +import os +from setuptools import setup -import sys -from distutils.version import LooseVersion - -try: - from setuptools import setup, __version__ - assert LooseVersion(__version__) >= LooseVersion('30.3') -except (ImportError, AssertionError): - sys.stderr.write("ERROR: setuptools 30.3 or later is required by glue-plotly\n") - sys.exit(1) - -setup(use_scm_version=True, setup_requires=['setuptools_scm']) +setup(use_scm_version={'write_to': os.path.join('glue_astronomy', 'version.py')}) diff --git a/tox.ini b/tox.ini index c9113e8..9d2ed75 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{36,37,38}-{test,docs} +envlist = py{36,37,38,39,310}-{test,docs}-{casa,dev} requires = pip >= 18.0 setuptools >= 30.3.0 indexserver = @@ -27,4 +27,4 @@ commands = deps = flake8 skip_install = true commands = - flake8 --max-line-length=100 glue_astronomy + flake8 glue_astronomy From 2c93f4532483e2fac783debcbe69db6e9a66d292 Mon Sep 17 00:00:00 2001 From: "Pey Lian Lim (Github)" <2090236+pllim@users.noreply.github.com> Date: Wed, 23 Feb 2022 13:48:42 -0500 Subject: [PATCH 2/2] Just pull pytest-astropy test plugins and add README badges --- README.rst | 21 +++++++++++++++++---- setup.cfg | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index ab782c8..8063bc8 100644 --- a/README.rst +++ b/README.rst @@ -1,10 +1,23 @@ -Experimental astronomy plugins for glue ---------------------------------------- +Astronomy plugins for glue +-------------------------- + +.. image:: https://readthedocs.org/projects/glue-astronomy/badge/?version=latest + :target: https://glue-astronomy.readthedocs.io/en/latest/?badge=latest + :alt: Documentation Status .. image:: https://dev.azure.com/glue-viz/glue-astronomy/_apis/build/status/glue-viz.glue-astronomy?branchName=main :target: https://dev.azure.com/glue-viz/glue-astronomy/_build/latest?definitionId=9&branchName=main + :alt: CI Status + +.. image:: https://codecov.io/gh/glue-viz/glue-astronomy/branch/main/graph/badge.svg + :target: https://codecov.io/gh/glue-viz/glue-astronomy + :alt: Coverage Status + +.. image:: https://img.shields.io/pypi/v/glue-astronomy.svg + :target: https://pypi.org/project/glue-astronomy + :alt: PyPI Status The glue-astronomy plugin for glue provides a collection of astronomy-specific -functionality. It is currently under heavy development and is not ready for -general use at this point. The documentation for this plugin can be found at +functionality. It is currently under heavy development. +The documentation for this plugin can be found at https://glue-astronomy.readthedocs.io. diff --git a/setup.cfg b/setup.cfg index deb01ce..e87fa04 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,7 +32,7 @@ docs = sphinx-rtd-theme test = pytest - pytest-doctestplus + pytest-astropy pytest-cov mock qt =