Skip to content

Commit

Permalink
Merge pull request #345 from adrn/astropy60-compat
Browse files Browse the repository at this point in the history
Fix compatibility with Astropy v6.0
  • Loading branch information
adrn authored Dec 13, 2023
2 parents bcfda7d + 4d0a8c5 commit 0f2ba4a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 39 deletions.
34 changes: 4 additions & 30 deletions gala/_astropy_init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst

__all__ = ['__version__']
__all__ = ["__version__"]

# this indicates whether or not we are in the package's setup.py
try:
Expand All @@ -12,41 +12,15 @@
try:
from .version import version as __version__
except ImportError:
__version__ = ''
__version__ = ""


if not _ASTROPY_SETUP_: # noqa
import os
from warnings import warn
from astropy.config.configuration import (
update_default_config,
ConfigurationDefaultMissingError,
ConfigurationDefaultMissingWarning)

# Create the test function for self test
from astropy.tests.runner import TestRunner

test = TestRunner.make_test_runner_in(os.path.dirname(__file__))
test.__test__ = False
__all__ += ['test']

# add these here so we only need to cleanup the namespace at the end
config_dir = None

if not os.environ.get('ASTROPY_SKIP_CONFIG_UPDATE', False):
config_dir = os.path.dirname(__file__)
config_template = os.path.join(config_dir, __package__ + ".cfg")
if os.path.isfile(config_template):
try:
update_default_config(
__package__, config_dir, version=__version__)
except TypeError as orig_error:
try:
update_default_config(__package__, config_dir)
except ConfigurationDefaultMissingError as e:
wmsg = (e.args[0] +
" Cannot install default profile. If you are "
"importing from source, this is expected.")
warn(ConfigurationDefaultMissingWarning(wmsg))
del e
except Exception:
raise orig_error
__all__ += ["test"]
13 changes: 10 additions & 3 deletions gala/dynamics/representation_nd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

__all__ = ['NDCartesianRepresentation', 'NDCartesianDifferential']

# TODO: Remove when astropy min version >=v6.0
try:
_make_getter = coord.representation._make_getter
except AttributeError:
_make_getter = coord.representation.base._make_getter


class NDMixin(object):

Expand Down Expand Up @@ -95,8 +101,9 @@ def __init__(self, x, differentials=None, unit=None, copy=True):
if not hasattr(cls, name):
setattr(cls, name,
property(
coord.representation._make_getter(name),
doc=(f"The '{name}' component of the points(s).")))
_make_getter(name),
doc=(f"The '{name}' component of the points(s)."))
)

def get_xyz(self, xyz_axis=0):
"""Return a vector array of the x, y, and z coordinates.
Expand Down Expand Up @@ -181,7 +188,7 @@ def __init__(self, d_x, unit=None, copy=True):
cls = self.__class__
if not hasattr(cls, name):
setattr(cls, name,
property(coord.representation._make_getter(name),
property(_make_getter(name),
doc=("The '{0}' component of the points(s)."
.format(name))))

Expand Down
9 changes: 4 additions & 5 deletions gala/potential/potential/tests/test_interop_galpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import numpy as np
import pytest
from astropy.coordinates import CylindricalRepresentation
from astropy.tests.helper import catch_warnings

# This project
import gala.potential as gp
Expand Down Expand Up @@ -73,11 +72,11 @@ def pytest_generate_tests(metafunc):
for Potential in _galpy_to_gala.keys():
galpy_pot = Potential(ro=ro, vo=vo) # use defaults

with catch_warnings(RuntimeWarning) as warns:
pot = galpy_to_gala_potential(galpy_pot, ro=ro, vo=vo)

if isinstance(galpy_pot, galpy_gp.MN3ExponentialDiskPotential):
assert len(warns) > 0
with pytest.warns():
pot = galpy_to_gala_potential(galpy_pot, ro=ro, vo=vo)
else:
pot = galpy_to_gala_potential(galpy_pot, ro=ro, vo=vo)

gala_pots.append(pot)
galpy_pots.append(galpy_pot)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ tutorials = [
"jupyter_client",
"ipykernel",
"jupytext",
"pyia",
"pyia @ git+https://github.com/adrn/pyia",
"astroquery"
]

Expand Down

0 comments on commit 0f2ba4a

Please sign in to comment.