Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable pyink on tests, fix VSCode pyink config to avoid bad Python version. #47

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

# Check formatting
- name: Check pyink formatting
run: uv run pyink treescope --check
run: uv run pyink treescope tests --check

- name: Run pylint
run: uv run pylint treescope
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"editor.detectIndentation": false,
"editor.defaultFormatter": "ms-python.black-formatter",
},
"black-formatter.path": ["uvx", "pyink"],
"black-formatter.path": ["uvx", "--python=>=3.9,!=3.12.5", "pyink"],
"pylint.enabled": true,
}
1 change: 1 addition & 0 deletions tests/fixtures/treescope_examples_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class ObjectWithCustomHandlerThatThrowsDeferred:

def __treescope_repr__(self, path, subtree_renderer):
del path, subtree_renderer

def _internal_main_thunk(layout_decision):
del layout_decision
raise RuntimeError("Simulated deferred treescope_repr failure!")
Expand Down
4 changes: 3 additions & 1 deletion tests/representation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ class RepresentationPartsTest(parameterized.TestCase):
expected_text_roundtrip_collapsed='some text with characters < > &',
expected_text_roundtrip_expanded='some text with characters < > &',
expected_html='some text with characters &lt; &gt; &amp;',
expected_html_at_beginning='some text with characters &lt; &gt; &amp;',
expected_html_at_beginning=(
'some text with characters &lt; &gt; &amp;'
),
),
dict(
testcase_name='siblings',
Expand Down
6 changes: 3 additions & 3 deletions treescope/_internal/api/arrayviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ def render_array(
something like ``palettable.matplotlib.Inferno_20.colors``.
truncate: Whether or not to truncate the array to a smaller size before
rendering.
maximum_size: Maximum number of elements of an array to show. Arrays larger
than this will be truncated along one or more axes. Ignored unless
``truncate`` is True.
maximum_size: Maximum number of elements of an array to show. Arrays
larger than this will be truncated along one or more axes. Ignored
unless ``truncate`` is True.
cutoff_size_per_axis: Maximum number of elements of each individual axis
to show without truncation. Any axis longer than this will be truncated,
with their visual size increasing logarithmically with the true axis
Expand Down
8 changes: 6 additions & 2 deletions treescope/_internal/handlers/shared_value_postprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,13 @@ def html_setup_parts(
{{
padding-right: 1ch;
margin-right: -0.5ch;
background: linear-gradient(135deg, orange 0 0.6ch, transparent 0.6ch );
background: linear-gradient(
135deg, orange 0 0.6ch, transparent 0.6ch
);
}}
.shared_warning_pip.is_first_on_line:not({setup_context.collapsed_selector} *)
.shared_warning_pip.is_first_on_line:not(
{setup_context.collapsed_selector} *
)
{{
margin-left: -0.5ch;
}}
Expand Down
6 changes: 3 additions & 3 deletions treescope/_internal/html_encapsulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ def encapsulate_streaming_html(
stream = io.StringIO()

if stealable:
stealer_content = _prep_html_js_and_strip_comments(STEALER_TEMPLATE).replace(
"{__REPLACE_ME_WITH_CONTAINER_ID_CLASS__}", unique_id_class
)
stealer_content = _prep_html_js_and_strip_comments(
STEALER_TEMPLATE
).replace("{__REPLACE_ME_WITH_CONTAINER_ID_CLASS__}", unique_id_class)
yield HTMLOutputSegment(
html_src=stealer_content,
segment_type=SegmentType.FINAL_OUTPUT_STEALER,
Expand Down
3 changes: 2 additions & 1 deletion treescope/_internal/parts/basic_parts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
from __future__ import annotations

import abc
from collections.abc import Hashable
import dataclasses
import functools
import html
import io
import itertools
import operator
import typing
from typing import Any, Hashable, Sequence
from typing import Any, Sequence

from treescope._internal import html_escaping
from treescope._internal.parts import part_interface
Expand Down
2 changes: 2 additions & 0 deletions treescope/external/jax_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,14 @@ def _summarize_array_data_unconditionally(array: jax.Array) -> list[str]:
stat = compute_summary(array, is_floating, is_integer, is_bool)
# Get values in parallel.
stat = jax.device_get(stat)
# pylint: disable=inconsistent-quotes
if is_floating and stat["any_finite"]:
output_parts.append(f" ≈{stat['mean']:.2} ±{stat['std']:.2}")
output_parts.append(f" [≥{stat['nanmin']:.2}, ≤{stat['nanmax']:.2}]")

if is_integer:
output_parts.append(f" [≥{stat['min']:_d}, ≤{stat['max']:_d}]")
# pylint: enable=inconsistent-quotes

def append_if_present(output_parts, *names):
for name in names:
Expand Down
Loading