From 5da871ce193c37d48eb5c1cac5307eeeab0d53ac Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Tue, 14 May 2024 10:55:03 +0200 Subject: [PATCH 1/5] Use more recent _astropy_init --- srttools/_astropy_init.py | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/srttools/_astropy_init.py b/srttools/_astropy_init.py index 0a9f2537..8c1ddc76 100644 --- a/srttools/_astropy_init.py +++ b/srttools/_astropy_init.py @@ -18,12 +18,6 @@ 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 @@ -31,25 +25,3 @@ 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 From 5fbdd96250dd5a363201b061f061e3ece5a1d992 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Tue, 14 May 2024 11:23:32 +0200 Subject: [PATCH 2/5] Fix pytest call --- setup.py | 13 ++++++++----- tox.ini | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 8f98e849..f764dcf9 100755 --- a/setup.py +++ b/setup.py @@ -9,7 +9,6 @@ from setuptools import setup - # First provide helpful messages if contributors try and run legacy commands # for tests or docs. @@ -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) @@ -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) @@ -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, + } +) diff --git a/tox.ini b/tox.ini index 464418df..d37d8138 100644 --- a/tox.ini +++ b/tox.ini @@ -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] From ca73c516f48c8ae64cd0bac9ad50d5a05e6c407f Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Tue, 14 May 2024 12:05:04 +0200 Subject: [PATCH 3/5] Fix doctests --- srttools/imager.py | 4 ++-- srttools/utils.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/srttools/imager.py b/srttools/imager.py index d9ccb070..098320d8 100644 --- a/srttools/imager.py +++ b/srttools/imager.py @@ -127,9 +127,9 @@ def merge_tables(tables): >>> t1.meta["filename"] = "asd" >>> s = merge_tables([t0, t1]) Traceback (most recent call last): - ... + ... astropy.table.np_utils.TableMergeError:... - ... + ... """ try: with warnings.catch_warnings(): diff --git a/srttools/utils.py b/srttools/utils.py index 9df274f9..b5e31e3e 100644 --- a/srttools/utils.py +++ b/srttools/utils.py @@ -906,7 +906,7 @@ def look_for_files_or_bust(files, timeout): >>> look_for_files_or_bust(['blabla1.txt', 'blabla2.txt', 'blabla3.txt'], ... timeout=1) Traceback (most recent call last): - ... + ... FileNotFoundError: ...['blabla3.txt'] """ t0 = time.time() From 45348c2a7f3318b985d631c68ff04e5ea9e7687a Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Tue, 14 May 2024 12:06:14 +0200 Subject: [PATCH 4/5] Add changelog --- docs/changes/238.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changes/238.bugfix.rst diff --git a/docs/changes/238.bugfix.rst b/docs/changes/238.bugfix.rst new file mode 100644 index 00000000..6a827a51 --- /dev/null +++ b/docs/changes/238.bugfix.rst @@ -0,0 +1 @@ +Fix incompatibility with Astropy 6 From 84365cedce5fd42529df155b312648cff1f288d5 Mon Sep 17 00:00:00 2001 From: Matteo Bachetti Date: Tue, 14 May 2024 12:55:39 +0200 Subject: [PATCH 5/5] Move problematic doctests to standard tests --- srttools/imager.py | 15 +-------------- srttools/tests/test_imager.py | 17 ++++++++++++----- srttools/tests/test_utils.py | 11 ++++++++++- srttools/utils.py | 13 +------------ 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/srttools/imager.py b/srttools/imager.py index 098320d8..de82aa37 100644 --- a/srttools/imager.py +++ b/srttools/imager.py @@ -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) diff --git a/srttools/tests/test_imager.py b/srttools/tests/test_imager.py index 15857219..c6bf4426 100644 --- a/srttools/tests/test_imager.py +++ b/srttools/tests/test_imager.py @@ -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 @@ -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]) diff --git a/srttools/tests/test_utils.py b/srttools/tests/test_utils.py index 4f4ae51f..ac8ef628 100644 --- a/srttools/tests/test_utils.py +++ b/srttools/tests/test_utils.py @@ -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") @@ -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) diff --git a/srttools/utils.py b/srttools/utils.py index b5e31e3e..e49aed1c 100644 --- a/srttools/utils.py +++ b/srttools/utils.py @@ -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