From b51d6e52fec31b506561c7af458175a0fa40baf1 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Fri, 16 Aug 2024 13:07:51 -0400 Subject: [PATCH 01/10] Update reportlet.py --- nireports/assembler/reportlet.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/nireports/assembler/reportlet.py b/nireports/assembler/reportlet.py index a69c421a..28862363 100644 --- a/nireports/assembler/reportlet.py +++ b/nireports/assembler/reportlet.py @@ -270,6 +270,26 @@ def __init__(self, layout, config=None, out_dir=None, bids_filters=None, metadat name=html_anchor, style="; ".join(f"{k}: {v}" for k, v in style.items()), ) + elif ext in (".png", ".jpg", ".jpeg"): + entities = dict(bidsfile.entities) + if desc_text: + desc_text = desc_text.format(**entities) + + try: + html_anchor = src.relative_to(out_dir) + except ValueError: + html_anchor = src.relative_to(Path(layout.root)) + dst = out_dir / html_anchor + dst.parent.mkdir(parents=True, exist_ok=True) + copyfile(src, dst, copy=True, use_hardlink=True) + + style = {"width": "100%"} if is_static else {} + style.update(config.get("style", {})) + + stylestr = "; ".join(f"{k}: {v}" for k, v in style.items()) + contents = f'' + else: + raise RuntimeError(f"Unsupported file extension: {ext}") if contents: self.components.append((contents, desc_text)) From 662be80c4eec342bc07ba61a4e5cafd0db0efc04 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Fri, 16 Aug 2024 13:13:58 -0400 Subject: [PATCH 02/10] Show contents. --- nireports/assembler/report.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nireports/assembler/report.py b/nireports/assembler/report.py index eb858601..f2b337a0 100644 --- a/nireports/assembler/report.py +++ b/nireports/assembler/report.py @@ -220,6 +220,9 @@ class Report: ... ).read_text()) - (REPORT_BASELINE_LENGTH + 51892) 0 + >>> (output_dir / 'nireports' / 'sub-03_task-faketaskwithruns_bold.html').read_text() + "test" + >>> len(( ... output_dir / 'nireports' / 'sub-03_task-faketaskwithruns_bold.html' ... ).read_text()) - RATING_WIDGET_LENGTH From bf10a4694e1dd1572b8b04ab7b273af8a2c9b1f3 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Fri, 16 Aug 2024 13:20:08 -0400 Subject: [PATCH 03/10] Update report.py --- nireports/assembler/report.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/nireports/assembler/report.py b/nireports/assembler/report.py index f2b337a0..eb858601 100644 --- a/nireports/assembler/report.py +++ b/nireports/assembler/report.py @@ -220,9 +220,6 @@ class Report: ... ).read_text()) - (REPORT_BASELINE_LENGTH + 51892) 0 - >>> (output_dir / 'nireports' / 'sub-03_task-faketaskwithruns_bold.html').read_text() - "test" - >>> len(( ... output_dir / 'nireports' / 'sub-03_task-faketaskwithruns_bold.html' ... ).read_text()) - RATING_WIDGET_LENGTH From eb2a35afe911b1c9dd32d76c8accf5f6bd7d5885 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Fri, 16 Aug 2024 13:29:28 -0400 Subject: [PATCH 04/10] Pin numpy version. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 1b41c886..2ddd560a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ dependencies = [ "nibabel >= 3.0.1", "nilearn >= 0.5.2", "nipype", - "numpy", + "numpy < 2.0.0", "pandas", "pybids", "pyyaml", From 3752a18ae3f3bc69020a78eb1054b39c75c688ff Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Mon, 19 Aug 2024 09:53:48 -0400 Subject: [PATCH 05/10] Unpin Sphinx. --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2ddd560a..131b2b11 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,10 +41,10 @@ NiPreps = "https://www.nipreps.org/" [project.optional-dependencies] doc = [ - "furo ~= 2021.10.09", + "furo", "pydot >= 1.2.3", "pydotplus", - "sphinx ~= 4.0", + "sphinx", "sphinxcontrib-apidoc", "sphinxcontrib-napoleon", ] From 7efbcfd97e09c197d91b1a2d599edaf4ecd585a3 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Mon, 19 Aug 2024 10:51:01 -0400 Subject: [PATCH 06/10] Use snippet for pngs. --- nireports/assembler/reportlet.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/nireports/assembler/reportlet.py b/nireports/assembler/reportlet.py index 28862363..d942efe9 100644 --- a/nireports/assembler/reportlet.py +++ b/nireports/assembler/reportlet.py @@ -31,22 +31,20 @@ from nireports.assembler.misc import dict2html, read_crashfile -SVG_SNIPPET = [ - """\ +IMG_SNIPPET = """\
- -Problem loading figure {name}. If the link below works, please try \ -reloading the report in your browser. +
Get figure file: {name} -""", - """\ +""" +SVG_SNIPPET = """\
- + +Problem loading figure {name}. If the link below works, please try \ +reloading the report in your browser.
Get figure file: {name} -""", -] +""" METADATA_ACCORDION_BLOCK = """\
@@ -266,7 +264,9 @@ def __init__(self, layout, config=None, out_dir=None, bids_filters=None, metadat style = {"width": "100%"} if is_static else {} style.update(config.get("style", {})) - contents = SVG_SNIPPET[is_static].format( + snippet = SVG_SNIPPET if is_static else IMG_SNIPPET + contents = snippet.format( + ext=ext[1:], name=html_anchor, style="; ".join(f"{k}: {v}" for k, v in style.items()), ) @@ -283,11 +283,15 @@ def __init__(self, layout, config=None, out_dir=None, bids_filters=None, metadat dst.parent.mkdir(parents=True, exist_ok=True) copyfile(src, dst, copy=True, use_hardlink=True) - style = {"width": "100%"} if is_static else {} + style = {"width": "100%"} style.update(config.get("style", {})) - stylestr = "; ".join(f"{k}: {v}" for k, v in style.items()) - contents = f'' + snippet = IMG_SNIPPET + contents = snippet.format( + ext=ext[1:], + name=html_anchor, + style="; ".join(f"{k}: {v}" for k, v in style.items()), + ) else: raise RuntimeError(f"Unsupported file extension: {ext}") From 53587594d8251dfd9ba20e076967f179a24d0f78 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Mon, 19 Aug 2024 10:58:42 -0400 Subject: [PATCH 07/10] Flip them. --- nireports/assembler/reportlet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nireports/assembler/reportlet.py b/nireports/assembler/reportlet.py index d942efe9..b14acc7f 100644 --- a/nireports/assembler/reportlet.py +++ b/nireports/assembler/reportlet.py @@ -264,7 +264,7 @@ def __init__(self, layout, config=None, out_dir=None, bids_filters=None, metadat style = {"width": "100%"} if is_static else {} style.update(config.get("style", {})) - snippet = SVG_SNIPPET if is_static else IMG_SNIPPET + snippet = IMG_SNIPPET if is_static else SVG_SNIPPET contents = snippet.format( ext=ext[1:], name=html_anchor, From dc54385842c370eedaed5b1b5f0cbd9eb5692899 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Mon, 19 Aug 2024 11:15:59 -0400 Subject: [PATCH 08/10] REL: 23.2.2 --- CHANGES.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 1af0fe94..ab27a29f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,15 @@ +23.2.2 (August 19, 2024) +======================== +Bug-fix release in the 23.2.x series. + +CHANGES +------- + +**Full Changelog**: https://github.com/nipreps/nireports/compare/23.2.1...23.2.2 + +* ENH: Support PNGs and JPGs in reportlets (#126) + + 23.2.1 (May 07, 2024) ===================== Bug-fix release in the 23.2.x series. From c980e130d8e5c7b1470b31e9a97870a94bf22227 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Mon, 19 Aug 2024 11:42:40 -0400 Subject: [PATCH 09/10] test: Fix expected length of widget (see 4d43a88) --- nireports/assembler/report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nireports/assembler/report.py b/nireports/assembler/report.py index 0555fc6c..b58fcfca 100644 --- a/nireports/assembler/report.py +++ b/nireports/assembler/report.py @@ -96,7 +96,7 @@ class Report: ... dirs_exist_ok=True, ... ) >>> REPORT_BASELINE_LENGTH = 41770 - >>> RATING_WIDGET_LENGTH = 83308 + >>> RATING_WIDGET_LENGTH = 83343 Examples From 449edfa30938951b9cf1f161d52f2b45353673e2 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Mon, 19 Aug 2024 11:14:22 -0400 Subject: [PATCH 10/10] test: Numpy 2.0 compatibility --- nireports/conftest.py | 8 ++++++++ pyproject.toml | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/nireports/conftest.py b/nireports/conftest.py index c67ff257..4fb25190 100644 --- a/nireports/conftest.py +++ b/nireports/conftest.py @@ -41,6 +41,14 @@ test_workdir = os.getenv("TEST_WORK_DIR") +@pytest.fixture(scope="session", autouse=True) +def legacy_printoptions(): + from packaging.version import Version + + if Version(np.__version__) >= Version("1.22"): + np.set_printoptions(legacy="1.21") + + @pytest.fixture(autouse=True) def expand_namespace(doctest_namespace): doctest_namespace["PY_VERSION"] = version_info diff --git a/pyproject.toml b/pyproject.toml index 297e4bc5..b67d93e9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ dependencies = [ "nibabel >= 3.0.1", "nilearn >= 0.5.2", "nipype", - "numpy < 2.0", + "numpy", "pandas", "pybids", "pyyaml", @@ -57,6 +57,7 @@ dev = [ test = [ "coverage", "matplotlib", + "packaging", "pytest", "pytest-cov", "pytest-env",