Skip to content

Commit

Permalink
remove uses of deprecated pkg_resources (#478)
Browse files Browse the repository at this point in the history
Co-authored-by: Nadia Dencheva <[email protected]>
  • Loading branch information
braingram and nden authored Oct 10, 2023
1 parent e82d3fb commit 8117b3c
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 35 deletions.
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
0.20.0 (unreleased)
-------------------

other
^^^^^

- Replace ``pkg_resources`` with ``importlib.metadata``. [#478]

0.19.0 (2023-09-15)
-------------------

Expand Down
8 changes: 0 additions & 8 deletions conftest.py

This file was deleted.

6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])

Expand Down
9 changes: 3 additions & 6 deletions gwcs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Empty file added gwcs/tests/data/__init__.py
Empty file.
9 changes: 7 additions & 2 deletions gwcs/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# 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

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):
Expand All @@ -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)
Expand Down
31 changes: 19 additions & 12 deletions gwcs/tests/test_wcs.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
# 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)
from .. import coordinate_frames as cf
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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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']

Expand All @@ -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']

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8117b3c

Please sign in to comment.