diff --git a/CHANGES.rst b/CHANGES.rst index 78aa61cc..0582181c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,11 @@ +0.20.0 (unreleased) +------------------- + +other +^^^^^ + +- Replace ``pkg_resources`` with ``importlib.metadata``. [#478] + 0.19.0 (2023-09-15) ------------------- diff --git a/conftest.py b/conftest.py deleted file mode 100644 index 5a6c2288..00000000 --- a/conftest.py +++ /dev/null @@ -1,8 +0,0 @@ -import pkg_resources - -entry_points = [] -for entry_point in pkg_resources.iter_entry_points('pytest11'): - entry_points.append(entry_point.name) - -if "asdf_schema_tester" not in entry_points: - pytest_plugins = ['asdf.tests.schema_tester'] diff --git a/docs/conf.py b/docs/conf.py index 73f5592b..8e15eb80 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -33,8 +33,8 @@ import tomllib except ImportError: import tomli as tomllib - -from pkg_resources import get_distribution + +import importlib.metadata try: from sphinx_astropy.conf.v1 import * # noqa @@ -83,7 +83,7 @@ # |version| and |release|, also used in various other places throughout the # built documents. -release = get_distribution(project).version +release = importlib.metadata.version(project) # for example take major/minor version = '.'.join(release.split('.')[:2]) diff --git a/gwcs/__init__.py b/gwcs/__init__.py index 1f87f8b1..18d5c3c8 100644 --- a/gwcs/__init__.py +++ b/gwcs/__init__.py @@ -57,14 +57,11 @@ """ -import sys -from pkg_resources import get_distribution, DistributionNotFound -if sys.version_info < (3, 6): - raise ImportError("GWCS supports Python versions 3.6 and above.") # pragma: no cover +import importlib.metadata try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: # pragma: no cover + __version__ = importlib.metadata.version(__name__) +except importlib.metadata.PackageNotFoundError: # pragma: no cover # package is not installed pass # pragma: no cover diff --git a/gwcs/tests/data/__init__.py b/gwcs/tests/data/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/gwcs/tests/test_utils.py b/gwcs/tests/test_utils.py index 1d4bbcbd..e69ec536 100644 --- a/gwcs/tests/test_utils.py +++ b/gwcs/tests/test_utils.py @@ -1,11 +1,11 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst +import os.path import numpy as np from astropy.io import fits from astropy import wcs as fitswcs from astropy import units as u from astropy import coordinates as coord from astropy.modeling import models -from astropy.utils.data import get_pkg_data_filename from astropy.tests.helper import assert_quantity_allclose import pytest from numpy.testing import assert_allclose @@ -13,6 +13,11 @@ from .. import utils as gwutils from ..utils import UnsupportedProjectionError +from . import data + + +data_path = os.path.split(os.path.abspath(data.__file__))[0] + def test_wrong_projcode(): with pytest.raises(UnsupportedProjectionError): @@ -26,7 +31,7 @@ def test_wrong_projcode2(): def test_fits_transform(): - hdr = fits.Header.fromfile(get_pkg_data_filename('data/simple_wcs2.hdr')) + hdr = fits.Header.fromfile(os.path.join(data_path, "simple_wcs2.hdr")) gw1 = gwutils.make_fitswcs_transform(hdr) w1 = fitswcs.WCS(hdr) assert_allclose(gw1(1, 2), w1.wcs_pix2world(1, 2, 0), atol=10 ** -8) diff --git a/gwcs/tests/test_wcs.py b/gwcs/tests/test_wcs.py index 2cde95d9..7268f392 100644 --- a/gwcs/tests/test_wcs.py +++ b/gwcs/tests/test_wcs.py @@ -1,16 +1,20 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst import warnings +import os.path + +import pytest + import numpy as np from numpy.testing import assert_allclose, assert_equal + from astropy.modeling import models from astropy import coordinates as coord from astropy.io import fits from astropy import units as u -import pytest -from astropy.utils.data import get_pkg_data_filename from astropy import wcs as astwcs from astropy.wcs import wcsapi from astropy.time import Time +import asdf from .. import wcs from ..wcstools import (wcs_from_fiducial, grid_from_bounding_box, wcs_from_points) @@ -18,7 +22,10 @@ from .. import utils from ..utils import CoordinateFrameError from .utils import _gwcs_from_hst_fits_wcs -import asdf +from . import data + + +data_path = os.path.split(os.path.abspath(data.__file__))[0] m1 = models.Shift(12.4) & models.Shift(-2) @@ -378,7 +385,7 @@ def test_grid_from_bounding_box_step(): def test_wcs_from_points(): np.random.seed(0) - hdr = fits.Header.fromtextfile(get_pkg_data_filename("data/acs.hdr"), endcard=False) + hdr = fits.Header.fromtextfile(os.path.join(data_path, "acs.hdr"), endcard=False) with pytest.warns(astwcs.FITSFixedWarning) as caught_warnings: # this raises a warning unimportant for this testing the pix2world # FITSFixedWarning(u'The WCS transformation has more axes (2) than @@ -532,7 +539,7 @@ def test_high_level_api(): class TestImaging(object): def setup_class(self): - hdr = fits.Header.fromtextfile(get_pkg_data_filename("data/acs.hdr"), endcard=False) + hdr = fits.Header.fromtextfile(os.path.join(data_path, "acs.hdr"), endcard=False) with pytest.warns(astwcs.FITSFixedWarning) as caught_warnings: # this raises a warning unimportant for this testing the pix2world # FITSFixedWarning(u'The WCS transformation has more axes (2) than @@ -640,7 +647,7 @@ def test_to_fits_sip(): y, x = np.mgrid[:1024:10, :1024:10] xflat = np.ravel(x[1:-1, 1:-1]) yflat = np.ravel(y[1:-1, 1:-1]) - fn = get_pkg_data_filename('data/miriwcs.asdf') + fn = os.path.join(data_path, 'miriwcs.asdf') with asdf.open(fn, lazy_load=False, copy_arrays=True, ignore_missing_extensions=True) as af: miriwcs = af.tree['wcs'] bounding_box = ((0, 1024), (0, 1024)) @@ -1001,7 +1008,7 @@ def test_to_fits_tab_time_cube(gwcs_cube_with_separable_time): def test_to_fits_tab_miri_image(): # gWCS: - fn = get_pkg_data_filename('data/miriwcs.asdf') + fn = os.path.join(data_path, 'miriwcs.asdf') with asdf.open(fn, copy_arrays=True, lazy_load=False, ignore_missing_extensions=True) as af: w = af.tree['wcs'] @@ -1025,7 +1032,7 @@ def test_to_fits_tab_miri_image(): def test_to_fits_tab_miri_lrs(): - fn = get_pkg_data_filename('data/miri_lrs_wcs.asdf') + fn = os.path.join(data_path, 'miri_lrs_wcs.asdf') with asdf.open(fn, copy_arrays=True, lazy_load=False, ignore_missing_extensions=True) as af: w = af.tree['wcs'] @@ -1094,7 +1101,7 @@ def test_in_image(): def test_iter_inv(): - fn = get_pkg_data_filename('data/nircamwcs.asdf') + fn = os.path.join(data_path, 'nircamwcs.asdf') with asdf.open(fn, lazy_load=False, copy_arrays=False, ignore_missing_extensions=True) as af: w = af.tree['wcs'] # remove analytic/user-supplied inverse: @@ -1237,8 +1244,8 @@ def test_initialize_wcs_with_list(): def test_sip_roundtrip(): - hdr = fits.Header.fromtextfile(get_pkg_data_filename("data/acs.hdr"), - endcard=False) + hdr = fits.Header.fromtextfile(os.path.join(data_path, "acs.hdr"), endcard=False) + nx = ny = 1024 hdr['naxis'] = 2 hdr['naxis1'] = nx @@ -1275,7 +1282,7 @@ def test_sip_roundtrip(): def test_spatial_spectral_stokes(): """ Converts a FITS WCS to GWCS and compares results.""" - hdr = fits.Header.fromfile(get_pkg_data_filename("data/stokes.txt")) + hdr = fits.Header.fromfile(os.path.join(data_path, "stokes.txt")) with warnings.catch_warnings(): warnings.simplefilter("ignore", category=astwcs.FITSFixedWarning) aw = astwcs.WCS(hdr) diff --git a/pyproject.toml b/pyproject.toml index a3675460..b225a667 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,9 +58,8 @@ requires = [ ] build-backend = "setuptools.build_meta" -[tool.setuptools] -zip-safe = false -include-package-data = false +[tool.setuptools.package-data] +'gwcs.tests.data' = ["*"] [tool.setuptools.packages.find] namespaces = false diff --git a/tox.ini b/tox.ini index 93ac88e5..0418f6e8 100644 --- a/tox.ini +++ b/tox.ini @@ -60,7 +60,7 @@ passenv = set_env = dev: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/scientific-python-nightly-wheels/simple args_are_paths = false -change_dir = pyargs: {homedir} +change_dir = pyargs: {env:HOME} extras = test alldeps: all