Skip to content

Commit

Permalink
Merge pull request #229 from SciCatProject/better-html-errors
Browse files Browse the repository at this point in the history
Show tooltip in rows with error in HTML repr
  • Loading branch information
jl-wynen authored Aug 30, 2024
2 parents 423b4ec + 45239dd commit 6dd672f
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
args: ["--drop-empty-cells",
"--extra-keys 'metadata.language_info.version cell.metadata.jp-MarkdownHeadingCollapsed cell.metadata.pycharm'"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.1
rev: v0.6.3
hooks:
- id: ruff-format
types_or: [ python, pyi ]
Expand Down
8 changes: 4 additions & 4 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ anyio==4.4.0
# via httpx
bcrypt==4.2.0
# via paramiko
certifi==2024.7.4
certifi==2024.8.30
# via
# httpcore
# httpx
Expand All @@ -29,14 +29,14 @@ h11==0.14.0
# via httpcore
httpcore==1.0.5
# via httpx
httpx==0.27.0
httpx==0.27.2
# via -r base.in
idna==3.7
idna==3.8
# via
# anyio
# email-validator
# httpx
paramiko==3.4.0
paramiko==3.4.1
# via -r base.in
pycparser==2.22
# via cffi
Expand Down
4 changes: 2 additions & 2 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# pip-compile-multi
#
cachetools==5.4.0
cachetools==5.5.0
# via tox
chardet==5.2.0
# via tox
Expand All @@ -29,7 +29,7 @@ pluggy==1.5.0
# via tox
pyproject-api==1.7.1
# via tox
tox==4.17.1
tox==4.18.0
# via -r ci.in
virtualenv==20.26.3
# via tox
6 changes: 3 additions & 3 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jupyter-server==2.14.2
# notebook-shim
jupyter-server-terminals==0.5.3
# via jupyter-server
jupyterlab==4.2.4
jupyterlab==4.2.5
# via -r dev.in
jupyterlab-server==2.27.3
# via jupyterlab
Expand All @@ -73,7 +73,7 @@ rfc3986-validator==0.1.1
# via
# jsonschema
# jupyter-events
ruff==0.5.7
ruff==0.6.3
# via -r dev.in
send2trash==1.8.3
# via jupyter-server
Expand All @@ -85,7 +85,7 @@ toposort==1.10
# via pip-compile-multi
uri-template==1.3.0
# via jsonschema
webcolors==24.6.0
webcolors==24.8.0
# via jsonschema
websocket-client==1.8.0
# via jupyter-server
Expand Down
10 changes: 5 additions & 5 deletions requirements/docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ imagesize==1.4.1
# via sphinx
ipykernel==6.29.5
# via -r docs.in
ipython==8.26.0
ipython==8.27.0
# via
# -r docs.in
# ipykernel
Expand Down Expand Up @@ -107,7 +107,7 @@ nbformat==5.10.4
# nbclient
# nbconvert
# nbsphinx
nbsphinx==0.9.4
nbsphinx==0.9.5
# via -r docs.in
nest-asyncio==1.6.0
# via ipykernel
Expand Down Expand Up @@ -140,7 +140,7 @@ pygments==2.18.0
# sphinx
python-dotenv==1.0.1
# via pydantic-settings
pyzmq==26.1.0
pyzmq==26.2.0
# via
# ipykernel
# jupyter-client
Expand All @@ -156,7 +156,7 @@ rpds-py==0.20.0
# referencing
snowballstemmer==2.2.0
# via sphinx
soupsieve==2.5
soupsieve==2.6
# via beautifulsoup4
sphinx==8.0.2
# via
Expand All @@ -168,7 +168,7 @@ sphinx==8.0.2
# sphinx-autodoc-typehints
# sphinx-copybutton
# sphinx-design
sphinx-autodoc-typehints==2.2.3
sphinx-autodoc-typehints==2.3.0
# via -r docs.in
sphinx-copybutton==0.5.2
# via -r docs.in
Expand Down
4 changes: 2 additions & 2 deletions requirements/mypy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
# pip-compile-multi
#
-r test.txt
mypy==1.11.1
mypy==1.11.2
# via -r mypy.in
mypy-extensions==1.0.0
# via mypy
types-docutils==0.21.0.20240724
# via -r mypy.in
types-paramiko==3.4.0.20240423
# via -r mypy.in
types-python-dateutil==2.9.0.20240316
types-python-dateutil==2.9.0.20240821
# via -r mypy.in
types-pyyaml==6.0.12.20240808
# via -r mypy.in
Expand Down
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ execnet==2.1.1
# via pytest-xdist
filelock[typing]==3.15.4
# via -r test.in
hypothesis==6.110.1
hypothesis==6.111.2
# via -r test.in
iniconfig==2.0.0
# via pytest
Expand Down
13 changes: 7 additions & 6 deletions src/scitacean/_html_repr/_dataset_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _format_field(field: Field) -> str:
)
typ = format_type(field.type)
description = html.escape(field.description)
row_highlight = _row_highlight_classes(field)
row_highlight, title = _row_highlight_classes_and_title(field)

template = _resources.dataset_field_repr_template()
return template.substitute(
Expand All @@ -109,6 +109,7 @@ def _format_field(field: Field) -> str:
value=value,
description=description,
extra_classes=row_highlight,
field_title=f'title="{title}"' if title else "",
)


Expand Down Expand Up @@ -157,7 +158,7 @@ def _get_fields(dset: Dataset) -> list[Field]:


def _check_error(field: Dataset.Field, validation: dict[str, str]) -> str | None:
field_spec = next(filter(lambda f: f.name == field.name, Dataset.fields()))
field_spec = next(f for f in Dataset.fields() if f.name == field.name)
return validation.get(field_spec.scicat_name, None)


Expand Down Expand Up @@ -205,12 +206,12 @@ def _human_readable_size(size_in_bytes: int) -> str:
return f"{size_in_bytes} B"


def _row_highlight_classes(field: Field) -> str:
def _row_highlight_classes_and_title(field: Field) -> tuple[str, str | None]:
if field.required and field.value is None:
return "cean-missing-value"
return "cean-missing-value", "Missing required field"
# Do not flag read-only fields with a value as errors.
# Validation is geared towards uploading where such fields must be None.
# But here, we don't want to flag downloaded datasets as bad because of this.
if field.error and not (field.read_only and field.error.startswith("Extra inputs")):
return "cean-error"
return ""
return "cean-error", field.error
return "", None
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tr class="field ${extra_classes}">
<tr class="cean-field ${extra_classes}" ${field_title}>
<td class="cean-field-flag">${flag}</td>
<td class="cean-field-name">${name}</td>
<td class="cean-field-type">${type}</td>
Expand Down

0 comments on commit 6dd672f

Please sign in to comment.