From 491b506738cfb1bd48e254a8a4e1425a723e886b Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Mon, 14 Oct 2024 11:33:11 +0100 Subject: [PATCH 1/8] Try to fix failing build --- conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conftest.py b/conftest.py index 261eef90..f987caa5 100644 --- a/conftest.py +++ b/conftest.py @@ -28,8 +28,8 @@ def pytest_report_header(config, start_path): def pytest_runtest_makereport(item, call): report = yield if report.when == "call": - ds = item.config.getoption("--ds") - tds = item.config.getoption("--tiled-ds") + ds = item.config.getoption("--ds") or None + tds = item.config.getoption("--tiled-ds") or None if ds and item.get_closest_marker("accept_cli_dataset"): report.nodeid += f"[{ds}]" if tds and item.get_closest_marker("accept_cli_tiled_dataset"): From de0c9384940593ecc1a698d23d07d3a4d1fed523 Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Mon, 14 Oct 2024 12:01:42 +0100 Subject: [PATCH 2/8] Gotta change that log --- changelog/447.trivial.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/447.trivial.rst diff --git a/changelog/447.trivial.rst b/changelog/447.trivial.rst new file mode 100644 index 00000000..9f819e26 --- /dev/null +++ b/changelog/447.trivial.rst @@ -0,0 +1 @@ +Fix failure to fetch CLI options in publish build. From 2ec86d45da48c08c0f1c95bf730d75c96da531ad Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Mon, 14 Oct 2024 12:16:33 +0100 Subject: [PATCH 3/8] Well that doesn't work I guess --- conftest.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/conftest.py b/conftest.py index f987caa5..9b2c6ab3 100644 --- a/conftest.py +++ b/conftest.py @@ -28,8 +28,14 @@ def pytest_report_header(config, start_path): def pytest_runtest_makereport(item, call): report = yield if report.when == "call": - ds = item.config.getoption("--ds") or None - tds = item.config.getoption("--tiled-ds") or None + try: + ds = item.config.getoption("--ds") + except ValueError: + ds = None + try: + tds = item.config.getoption("--tiled-ds") + except ValueError: + tds = None if ds and item.get_closest_marker("accept_cli_dataset"): report.nodeid += f"[{ds}]" if tds and item.get_closest_marker("accept_cli_tiled_dataset"): From fb0072605d605ab2c7a097b657ac908a9f862669 Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Thu, 17 Oct 2024 14:07:15 +0100 Subject: [PATCH 4/8] Move pytest ds and tiled_ds options into conftest one dir down --- conftest.py | 34 ----------------------- dkist/conftest.py | 69 ++++++++++++++++++++++++++++++++++------------- 2 files changed, 51 insertions(+), 52 deletions(-) diff --git a/conftest.py b/conftest.py index 9b2c6ab3..a17bd8ed 100644 --- a/conftest.py +++ b/conftest.py @@ -1,5 +1,4 @@ import matplotlib as mpl -import pytest mpl.use("Agg") @@ -9,36 +8,3 @@ def pytest_configure(config): # which will cause errors with remote_data off from astropy.utils.iers import IERS_Auto IERS_Auto.open() - - -def pytest_addoption(parser): - parser.addoption("--ds", action="store", help="Dataset provided as a string which can be parsed by load_dataset. This will override fixtures used in tests decorated with @accept_ds_from_cli.") - parser.addoption("--tiled-ds", action="store", help="Tiled datasets provided as a string which can be parsed by load_dataset. These datasets will override fixtures used in tests decorated with @accept_tiled_ds_from_cli.") - - -def pytest_report_header(config, start_path): - ds_str = config.getoption("--ds") or "None" - tds_str = config.getoption("--tiled-ds") or "None" - - return [f"CLI dataset provided: {ds_str}", - f"CLI tiled dataset provided: {tds_str}"] - - -@pytest.hookimpl(wrapper=True, tryfirst=True) -def pytest_runtest_makereport(item, call): - report = yield - if report.when == "call": - try: - ds = item.config.getoption("--ds") - except ValueError: - ds = None - try: - tds = item.config.getoption("--tiled-ds") - except ValueError: - tds = None - if ds and item.get_closest_marker("accept_cli_dataset"): - report.nodeid += f"[{ds}]" - if tds and item.get_closest_marker("accept_cli_tiled_dataset"): - report.nodeid += f"[{tds}]" - - return report diff --git a/dkist/conftest.py b/dkist/conftest.py index 0f8b7c9b..9be0c31c 100644 --- a/dkist/conftest.py +++ b/dkist/conftest.py @@ -25,6 +25,57 @@ from dkist.io.loaders import AstropyFITSLoader +def pytest_addoption(parser): + parser.addoption("--ds", action="store", help="Dataset provided as a string which can be parsed by load_dataset. This will override fixtures used in tests decorated with @accept_ds_from_cli.") + parser.addoption("--tiled-ds", action="store", help="Tiled datasets provided as a string which can be parsed by load_dataset. These datasets will override fixtures used in tests decorated with @accept_tiled_ds_from_cli.") + + +def pytest_report_header(config, start_path): + ds_str = config.getoption("--ds") or "None" + tds_str = config.getoption("--tiled-ds") or "None" + + return [f"CLI dataset provided: {ds_str}", + f"CLI tiled dataset provided: {tds_str}"] + + +@pytest.hookimpl(wrapper=True, tryfirst=True) +def pytest_runtest_makereport(item, call): + report = yield + if report.when == "call": + try: + ds = item.config.getoption("--ds") + except ValueError: + ds = None + try: + tds = item.config.getoption("--tiled-ds") + except ValueError: + tds = None + if ds and item.get_closest_marker("accept_cli_dataset"): + report.nodeid += f"[{ds}]" + if tds and item.get_closest_marker("accept_cli_tiled_dataset"): + report.nodeid += f"[{tds}]" + + return report + + +@pytest.hookimpl(hookwrapper=True) +def pytest_runtest_call(item): + ds = item.config.getoption("--ds") + tds = item.config.getoption("--tiled-ds") + + # Only one of accept_cli_dataset and accept_cli_tiled_dataset should be available + mark = item.get_closest_marker("accept_cli_dataset") or item.get_closest_marker("accept_cli_tiled_dataset") + if mark: + # Replace either the fixture specified as the first arg of the marker, or the first fixture in the test definition + replace_arg = mark.args[0] if mark.args else item.fixturenames[0] + if ds: + item.funcargs[replace_arg] = load_dataset(ds) + if tds: + item.funcargs[replace_arg] = load_dataset(tds) + + yield item + + @pytest.fixture def caplog_dkist(caplog): """ @@ -347,21 +398,3 @@ def visp_dataset_no_headers(tmp_path_factory): with open(vispdir / "test_visp_no_headers.asdf", mode="wb") as afo: afo.write(gfo.read()) return load_dataset(vispdir / "test_visp_no_headers.asdf") - - -@pytest.hookimpl(hookwrapper=True) -def pytest_runtest_call(item): - ds = item.config.getoption("--ds") - tds = item.config.getoption("--tiled-ds") - - # Only one of accept_cli_dataset and accept_cli_tiled_dataset should be available - mark = item.get_closest_marker("accept_cli_dataset") or item.get_closest_marker("accept_cli_tiled_dataset") - if mark: - # Replace either the fixture specified as the first arg of the marker, or the first fixture in the test definition - replace_arg = mark.args[0] if mark.args else item.fixturenames[0] - if ds: - item.funcargs[replace_arg] = load_dataset(ds) - if tds: - item.funcargs[replace_arg] = load_dataset(tds) - - yield item From 4c024fcb59ce012f4cbfd1138a4f7f85aefab9c1 Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Mon, 21 Oct 2024 11:13:51 +0100 Subject: [PATCH 5/8] Well that clearly doesn't work either --- conftest.py | 34 +++++++++++++++++++++++ dkist/conftest.py | 69 +++++++++++++---------------------------------- 2 files changed, 52 insertions(+), 51 deletions(-) diff --git a/conftest.py b/conftest.py index a17bd8ed..9b2c6ab3 100644 --- a/conftest.py +++ b/conftest.py @@ -1,4 +1,5 @@ import matplotlib as mpl +import pytest mpl.use("Agg") @@ -8,3 +9,36 @@ def pytest_configure(config): # which will cause errors with remote_data off from astropy.utils.iers import IERS_Auto IERS_Auto.open() + + +def pytest_addoption(parser): + parser.addoption("--ds", action="store", help="Dataset provided as a string which can be parsed by load_dataset. This will override fixtures used in tests decorated with @accept_ds_from_cli.") + parser.addoption("--tiled-ds", action="store", help="Tiled datasets provided as a string which can be parsed by load_dataset. These datasets will override fixtures used in tests decorated with @accept_tiled_ds_from_cli.") + + +def pytest_report_header(config, start_path): + ds_str = config.getoption("--ds") or "None" + tds_str = config.getoption("--tiled-ds") or "None" + + return [f"CLI dataset provided: {ds_str}", + f"CLI tiled dataset provided: {tds_str}"] + + +@pytest.hookimpl(wrapper=True, tryfirst=True) +def pytest_runtest_makereport(item, call): + report = yield + if report.when == "call": + try: + ds = item.config.getoption("--ds") + except ValueError: + ds = None + try: + tds = item.config.getoption("--tiled-ds") + except ValueError: + tds = None + if ds and item.get_closest_marker("accept_cli_dataset"): + report.nodeid += f"[{ds}]" + if tds and item.get_closest_marker("accept_cli_tiled_dataset"): + report.nodeid += f"[{tds}]" + + return report diff --git a/dkist/conftest.py b/dkist/conftest.py index 9be0c31c..0f8b7c9b 100644 --- a/dkist/conftest.py +++ b/dkist/conftest.py @@ -25,57 +25,6 @@ from dkist.io.loaders import AstropyFITSLoader -def pytest_addoption(parser): - parser.addoption("--ds", action="store", help="Dataset provided as a string which can be parsed by load_dataset. This will override fixtures used in tests decorated with @accept_ds_from_cli.") - parser.addoption("--tiled-ds", action="store", help="Tiled datasets provided as a string which can be parsed by load_dataset. These datasets will override fixtures used in tests decorated with @accept_tiled_ds_from_cli.") - - -def pytest_report_header(config, start_path): - ds_str = config.getoption("--ds") or "None" - tds_str = config.getoption("--tiled-ds") or "None" - - return [f"CLI dataset provided: {ds_str}", - f"CLI tiled dataset provided: {tds_str}"] - - -@pytest.hookimpl(wrapper=True, tryfirst=True) -def pytest_runtest_makereport(item, call): - report = yield - if report.when == "call": - try: - ds = item.config.getoption("--ds") - except ValueError: - ds = None - try: - tds = item.config.getoption("--tiled-ds") - except ValueError: - tds = None - if ds and item.get_closest_marker("accept_cli_dataset"): - report.nodeid += f"[{ds}]" - if tds and item.get_closest_marker("accept_cli_tiled_dataset"): - report.nodeid += f"[{tds}]" - - return report - - -@pytest.hookimpl(hookwrapper=True) -def pytest_runtest_call(item): - ds = item.config.getoption("--ds") - tds = item.config.getoption("--tiled-ds") - - # Only one of accept_cli_dataset and accept_cli_tiled_dataset should be available - mark = item.get_closest_marker("accept_cli_dataset") or item.get_closest_marker("accept_cli_tiled_dataset") - if mark: - # Replace either the fixture specified as the first arg of the marker, or the first fixture in the test definition - replace_arg = mark.args[0] if mark.args else item.fixturenames[0] - if ds: - item.funcargs[replace_arg] = load_dataset(ds) - if tds: - item.funcargs[replace_arg] = load_dataset(tds) - - yield item - - @pytest.fixture def caplog_dkist(caplog): """ @@ -398,3 +347,21 @@ def visp_dataset_no_headers(tmp_path_factory): with open(vispdir / "test_visp_no_headers.asdf", mode="wb") as afo: afo.write(gfo.read()) return load_dataset(vispdir / "test_visp_no_headers.asdf") + + +@pytest.hookimpl(hookwrapper=True) +def pytest_runtest_call(item): + ds = item.config.getoption("--ds") + tds = item.config.getoption("--tiled-ds") + + # Only one of accept_cli_dataset and accept_cli_tiled_dataset should be available + mark = item.get_closest_marker("accept_cli_dataset") or item.get_closest_marker("accept_cli_tiled_dataset") + if mark: + # Replace either the fixture specified as the first arg of the marker, or the first fixture in the test definition + replace_arg = mark.args[0] if mark.args else item.fixturenames[0] + if ds: + item.funcargs[replace_arg] = load_dataset(ds) + if tds: + item.funcargs[replace_arg] = load_dataset(tds) + + yield item From 62fe2d94b6409d6921d5a2991bda7c45b1fa1023 Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Mon, 21 Oct 2024 11:22:28 +0100 Subject: [PATCH 6/8] Try just working around the problem --- conftest.py | 7 +++---- dkist/conftest.py | 9 +++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/conftest.py b/conftest.py index 9b2c6ab3..0dc76f6a 100644 --- a/conftest.py +++ b/conftest.py @@ -30,12 +30,11 @@ def pytest_runtest_makereport(item, call): if report.when == "call": try: ds = item.config.getoption("--ds") - except ValueError: - ds = None - try: tds = item.config.getoption("--tiled-ds") except ValueError: - tds = None + # If CLI arguments can't be found, need to return gracefully + # TODO raise a warning here + return report if ds and item.get_closest_marker("accept_cli_dataset"): report.nodeid += f"[{ds}]" if tds and item.get_closest_marker("accept_cli_tiled_dataset"): diff --git a/dkist/conftest.py b/dkist/conftest.py index 0f8b7c9b..955d73ec 100644 --- a/dkist/conftest.py +++ b/dkist/conftest.py @@ -351,8 +351,13 @@ def visp_dataset_no_headers(tmp_path_factory): @pytest.hookimpl(hookwrapper=True) def pytest_runtest_call(item): - ds = item.config.getoption("--ds") - tds = item.config.getoption("--tiled-ds") + try: + ds = item.config.getoption("--ds") + tds = item.config.getoption("--tiled-ds") + except ValueError: + # If CLI arguments can't be found, need to return gracefully + # TODO raise a warning here + yield item # Only one of accept_cli_dataset and accept_cli_tiled_dataset should be available mark = item.get_closest_marker("accept_cli_dataset") or item.get_closest_marker("accept_cli_tiled_dataset") From e0869faf4b51974d16247fb853d17398454b3163 Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Mon, 21 Oct 2024 11:56:52 +0100 Subject: [PATCH 7/8] That's not how yield works --- dkist/conftest.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/dkist/conftest.py b/dkist/conftest.py index 955d73ec..0a1b942c 100644 --- a/dkist/conftest.py +++ b/dkist/conftest.py @@ -354,19 +354,19 @@ def pytest_runtest_call(item): try: ds = item.config.getoption("--ds") tds = item.config.getoption("--tiled-ds") + + # Only one of accept_cli_dataset and accept_cli_tiled_dataset should be available + mark = item.get_closest_marker("accept_cli_dataset") or item.get_closest_marker("accept_cli_tiled_dataset") + if mark: + # Replace either the fixture specified as the first arg of the marker, or the first fixture in the test definition + replace_arg = mark.args[0] if mark.args else item.fixturenames[0] + if ds: + item.funcargs[replace_arg] = load_dataset(ds) + if tds: + item.funcargs[replace_arg] = load_dataset(tds) + + yield item except ValueError: # If CLI arguments can't be found, need to return gracefully # TODO raise a warning here yield item - - # Only one of accept_cli_dataset and accept_cli_tiled_dataset should be available - mark = item.get_closest_marker("accept_cli_dataset") or item.get_closest_marker("accept_cli_tiled_dataset") - if mark: - # Replace either the fixture specified as the first arg of the marker, or the first fixture in the test definition - replace_arg = mark.args[0] if mark.args else item.fixturenames[0] - if ds: - item.funcargs[replace_arg] = load_dataset(ds) - if tds: - item.funcargs[replace_arg] = load_dataset(tds) - - yield item From b28b6da7e16ec456436a64014f3b1d3dcbc6ccb2 Mon Sep 17 00:00:00 2001 From: Drew Leonard Date: Mon, 21 Oct 2024 12:20:39 +0100 Subject: [PATCH 8/8] Try adding some warnings and see if the build still passes --- conftest.py | 4 +++- dkist/conftest.py | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/conftest.py b/conftest.py index 0dc76f6a..72f242cd 100644 --- a/conftest.py +++ b/conftest.py @@ -1,3 +1,5 @@ +import warnings + import matplotlib as mpl import pytest @@ -33,7 +35,7 @@ def pytest_runtest_makereport(item, call): tds = item.config.getoption("--tiled-ds") except ValueError: # If CLI arguments can't be found, need to return gracefully - # TODO raise a warning here + warnings.warn("--ds and --tiled-ds were not found. Any supplied datasets were not used.") return report if ds and item.get_closest_marker("accept_cli_dataset"): report.nodeid += f"[{ds}]" diff --git a/dkist/conftest.py b/dkist/conftest.py index 0a1b942c..9d6f648b 100644 --- a/dkist/conftest.py +++ b/dkist/conftest.py @@ -1,5 +1,6 @@ import copy import gzip +import warnings from pathlib import Path import dask.array as da @@ -369,4 +370,5 @@ def pytest_runtest_call(item): except ValueError: # If CLI arguments can't be found, need to return gracefully # TODO raise a warning here + warnings.warn("--ds and --tiled-ds were not found. Any supplied datasets will not be used.") yield item