Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with astropy 6 #238

Merged
merged 5 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes/238.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix incompatibility with Astropy 6
13 changes: 8 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from setuptools import setup


# First provide helpful messages if contributors try and run legacy commands
# for tests or docs.

Expand All @@ -34,7 +33,7 @@
http://docs.astropy.org/en/latest/development/testguide.html#running-tests
"""

if 'test' in sys.argv:
if "test" in sys.argv:
print(TEST_HELP)
sys.exit(1)

Expand All @@ -59,7 +58,7 @@
http://docs.astropy.org/en/latest/install.html#builddocs
"""

if 'build_docs' in sys.argv or 'build_sphinx' in sys.argv:
if "build_docs" in sys.argv or "build_sphinx" in sys.argv:
print(DOCS_HELP)
sys.exit(1)

Expand All @@ -74,5 +73,9 @@
version = '{version}'
""".lstrip()

setup(use_scm_version={'write_to': os.path.join('srttools', 'version.py'),
'write_to_template': VERSION_TEMPLATE})
setup(
use_scm_version={
"write_to": os.path.join("srttools", "version.py"),
"write_to_template": VERSION_TEMPLATE,
}
)
28 changes: 0 additions & 28 deletions srttools/_astropy_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,10 @@

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
15 changes: 1 addition & 14 deletions srttools/imager.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,7 @@ def _load_and_merge_subscans(indices_and_subscans):


def merge_tables(tables):
"""

Examples
--------
>>> t0 = Table({"Ch0": [0, 1]})
>>> t1 = Table({"Ch0": [[0, 1]]})
>>> t0.meta["filename"] = "sss"
>>> t1.meta["filename"] = "asd"
>>> s = merge_tables([t0, t1])
Traceback (most recent call last):
...
astropy.table.np_utils.TableMergeError:...
...
"""
"""Merge two tables, or raise."""
try:
with warnings.catch_warnings():
warnings.simplefilter("ignore", MergeConflictWarning)
Expand Down
17 changes: 12 additions & 5 deletions srttools/tests/test_imager.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@
from srttools.calibration import CalibratorTable
from srttools.calibration import HAS_STATSM
from srttools.read_config import read_config
from srttools.imager import (
main_imager,
main_preprocess,
_excluded_regions_from_args,
)
from srttools.imager import main_imager, main_preprocess, _excluded_regions_from_args, merge_tables
from srttools.inspect_observations import main_inspector
from srttools.simulate import simulate_sun
from srttools.global_fit import display_intermediate
Expand Down Expand Up @@ -1099,3 +1095,14 @@ def teardown_class(klass):
for o in out_fits_files + out_hdf5_files:
os.unlink(o)
shutil.rmtree(os.path.join(klass.config["productdir"], "sim"))


def test_table_merge():
from astropy.table import Table

t0 = Table({"Ch0": [0, 1]})
t1 = Table({"Ch0": [[0, 1]]})
t0.meta["filename"] = "sss"
t1.meta["filename"] = "asd"
with pytest.raises(ValueError, match=".*ERROR while merging tables.*"):
s = merge_tables([t0, t1])
11 changes: 10 additions & 1 deletion srttools/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import numpy as np
from ..utils import HAS_MAHO, calculate_zernike_moments
from ..utils import HAS_MAHO, calculate_zernike_moments, look_for_files_or_bust


@pytest.mark.skipif("not HAS_MAHO")
Expand All @@ -11,3 +11,12 @@ def test_zernike_moments():
)
assert res[1][1] < 1e-10
assert res[3][1] < 1e-10


def test_look_for_files_or_bust():
from pathlib import Path

Path("blabla1.txt").touch()
Path("blabla2.txt").touch()
with pytest.raises(FileNotFoundError, match=".+blabla3.txt.+"):
look_for_files_or_bust(["blabla1.txt", "blabla2.txt", "blabla3.txt"], timeout=1)
13 changes: 1 addition & 12 deletions srttools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,18 +897,7 @@ def get_mH2O(TMP, U):


def look_for_files_or_bust(files, timeout):
"""
Examples
--------
>>> from pathlib import Path
>>> Path('blabla1.txt').touch()
>>> Path('blabla2.txt').touch()
>>> look_for_files_or_bust(['blabla1.txt', 'blabla2.txt', 'blabla3.txt'],
... timeout=1)
Traceback (most recent call last):
...
FileNotFoundError: ...['blabla3.txt']
"""
"""Look for all files in the list, or raise an exception."""
t0 = time.time()
current_time = time.time()
number_of_seconds = 0
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ extras =
commands =
devdeps: pip install -U --pre -i https://pypi.anaconda.org/scipy-wheels-nightly/simple numpy
pip freeze
!cov: pytest --pyargs srttools {toxinidir}/docs {posargs}
cov: pytest --pyargs srttools {toxinidir}/docs --cov srttools --cov-config={toxinidir}/setup.cfg {posargs}
!cov: pytest --pyargs srttools {posargs}
cov: pytest --pyargs srttools --cov srttools --cov-config={toxinidir}/setup.cfg {posargs}
cov: coverage xml -o {toxinidir}/coverage.xml

[testenv:build_docs]
Expand Down
Loading