Skip to content

Commit

Permalink
Merge branch 'main' into enh/mandatory_config
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies authored Aug 19, 2024
2 parents 2ca8ba9 + e0a30e6 commit 7730215
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 13 deletions.
12 changes: 12 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion nireports/assembler/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Report:
... dirs_exist_ok=True,
... )
>>> REPORT_BASELINE_LENGTH = 41770
>>> RATING_WIDGET_LENGTH = 83308
>>> RATING_WIDGET_LENGTH = 83343
Examples
Expand Down
47 changes: 36 additions & 11 deletions nireports/assembler/reportlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,21 @@
from nireports.assembler.misc import dict2html, read_crashfile
from nireports.exceptions import RequiredReportletException

SVG_SNIPPET = [
"""\
IMG_SNIPPET = """\
<div class="reportlet">
<object class="svg-reportlet" type="image/svg+xml" data="./{name}" style="{style}">
Problem loading figure {name}. If the link below works, please try \
reloading the report in your browser.</object>
<img class="{ext}-reportlet" src="./{name}" style="{style}" />
</div>
<small>Get figure file: <a href="./{name}" target="_blank">{name}</a></small>
""",
"""\
"""

SVG_SNIPPET = """\
<div class="reportlet">
<img class="svg-reportlet" src="./{name}" style="{style}" />
<object class="{ext}-reportlet" type="image/{ext}+xml" data="./{name}" style="{style}">
Problem loading figure {name}. If the link below works, please try \
reloading the report in your browser.</object>
</div>
<small>Get figure file: <a href="./{name}" target="_blank">{name}</a></small>
""",
]
"""

METADATA_ACCORDION_BLOCK = """\
<div class="accordion accordion-flush" id="{metadata_id}">
Expand Down Expand Up @@ -266,10 +265,36 @@ 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 = IMG_SNIPPET if is_static else SVG_SNIPPET
contents = snippet.format(
ext=ext[1:],
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%"}
style.update(config.get("style", {}))

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}")

if contents:
self.components.append((contents, desc_text))
Expand Down
8 changes: 8 additions & 0 deletions nireports/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies = [
"nibabel >= 3.0.1",
"nilearn >= 0.5.2",
"nipype",
"numpy < 2.0",
"numpy",
"pandas",
"pybids",
"pyyaml",
Expand Down Expand Up @@ -57,6 +57,7 @@ dev = [
test = [
"coverage",
"matplotlib",
"packaging",
"pytest",
"pytest-cov",
"pytest-env",
Expand Down

0 comments on commit 7730215

Please sign in to comment.