Skip to content

Commit

Permalink
Merge pull request #64 from pllim/fix-tests
Browse files Browse the repository at this point in the history
MNT: Modernize packaging, etc
  • Loading branch information
astrofrog authored Feb 24, 2022
2 parents 7f3229d + 2c93f45 commit b0c598c
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 68 deletions.
35 changes: 28 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
*~
Expand All @@ -32,6 +45,9 @@ glue/qt/glue_qt_resources.py
# PyCharm
.idea

# VS code
.vscode

# Eclipse editor project files
.project
.pydevproject
Expand All @@ -43,3 +59,8 @@ glue/qt/glue_qt_resources.py

.tox
.html

# Env
.venv
venv
.env
11 changes: 9 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -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: .
Expand Down
8 changes: 8 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include LICENSE
include README.rst
include CHANGES.rst

include setup.cfg
include pyproject.toml

global-exclude *.pyc *.o
21 changes: 17 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 4 additions & 6 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# Glue documentation build configuration file

import os
from pkg_resources import get_distribution

from glue_astronomy import __version__

# -- General configuration ----------------------------------------------------

Expand Down Expand Up @@ -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.
Expand Down
7 changes: 1 addition & 6 deletions glue_astronomy/__init__.py
Original file line number Diff line number Diff line change
@@ -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():
Expand Down
43 changes: 19 additions & 24 deletions glue_astronomy/io/spectral_cube/tests/test_spectral_cube.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 4 additions & 1 deletion glue_astronomy/translators/tests/test_spectrum1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):

Expand Down Expand Up @@ -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)

Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build-system]
requires = ["setuptools>=30.3.0",
"setuptools_scm",
"wheel"]
build-backend = 'setuptools.build_meta'
19 changes: 17 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,6 +32,7 @@ docs =
sphinx-rtd-theme
test =
pytest
pytest-astropy
pytest-cov
mock
qt =
Expand All @@ -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
15 changes: 3 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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')})
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down Expand Up @@ -27,4 +27,4 @@ commands =
deps = flake8
skip_install = true
commands =
flake8 --max-line-length=100 glue_astronomy
flake8 glue_astronomy

0 comments on commit b0c598c

Please sign in to comment.