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

[pre-commit.ci] pre-commit autoupdate #7595

Merged
merged 6 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
exclude: \.min\.js$
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.0
rev: v0.8.6
hooks:
- id: ruff
files: panel/
Expand All @@ -36,7 +36,7 @@ repos:
additional_dependencies:
- tomli
- repo: https://github.com/hoxbro/prettier-pre-commit
rev: v3.3.3
rev: v3.4.2
hooks:
- id: prettier
entry: prettier --write --ignore-unknown --no-error-on-unmatched-pattern
Expand All @@ -47,7 +47,7 @@ repos:
- id: oxipng
stages: [manual]
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v9.13.0
rev: v9.17.0
hooks:
- id: eslint
args: ['-c', 'panel/.eslintrc.js', 'panel/*.ts', 'panel/models/**/*.ts', '--fix']
Expand Down
12 changes: 6 additions & 6 deletions panel/io/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,12 @@ def is_embeddable(object):
if len(cross_product) > max_states:
if config._doc_build:
return
param.main.param.warning('The cross product of different application '
'states is very large to explore (N=%d), consider '
'reducing the number of options on the widgets or '
'increase the max_states specified in the function '
'to remove this warning' %
len(cross_product))
param.main.param.warning(
'The cross product of different application states is very large '
f'to explore (N={len(cross_product)}), consider reducing the number '
'of options on the widgets or increase the max_states specified '
'in the function to remove this warning.'
)

nested_dict = lambda: defaultdict(nested_dict)
state_dict = nested_dict()
Expand Down
4 changes: 2 additions & 2 deletions panel/io/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ def _origin_url(url: str) -> str:

def _server_url(url: str, port: int) -> str:
if url.startswith("http"):
return '%s:%d%s' % (url.rsplit(':', 1)[0], port, "/")
return f"{url.rsplit(':', 1)[0]}:{port}/"
else:
return 'http://%s:%d%s' % (url.split(':')[0], port, "/")
return f"http://{url.split(':')[0]}:{port}/"

_tasks = set()

Expand Down
84 changes: 51 additions & 33 deletions panel/layout/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,20 @@ def __repr__(self, depth: int = 0, max_depth: int = 10) -> str:
spacer = '\n' + (' ' * (depth+1))
cls = type(self).__name__
params = param_reprs(self, ['objects'])
objs = ['[%d] %s' % (i, obj.__repr__(depth+1)) for i, obj in enumerate(self)]
objs = [f'[{i}] {obj.__repr__(depth+1)}' for i, obj in enumerate(self)]
if not params and not objs:
return super().__repr__(depth+1)
elif not params:

if not params:
template = '{cls}{spacer}{objs}'
elif not objs:
template = '{cls}({params})'
else:
template = '{cls}({params}){spacer}{objs}'
return template.format(
cls=cls, params=', '.join(params),
objs=str(spacer).join(objs), spacer=spacer)
objs=str(spacer).join(objs), spacer=spacer
)

#----------------------------------------------------------------
# Callback API
Expand Down Expand Up @@ -393,34 +395,40 @@ def __contains__(self, obj: Viewable) -> bool:

def __setitem__(self, index: int | slice, panes: Iterable[Any]) -> None:
new_objects = list(self)
name = type(self).__name__
if not isinstance(index, slice):
start, end = index, index+1
if start > len(self.objects):
raise IndexError('Index %d out of bounds on %s '
'containing %d objects.' %
(end, type(self).__name__, len(self.objects)))
raise IndexError(
f'Index {end} out of bounds on {name} containing '
f'{len(self.objects)} objects.'
)
panes = [panes]
else:
start = index.start or 0
end = len(self) if index.stop is None else index.stop
if index.start is None and index.stop is None:
if not isinstance(panes, list):
raise IndexError('Expected a list of objects to '
f'replace the objects in the {type(self).__name__}, '
f'got a {type(panes).__name__} type.')
raise IndexError(
'Expected a list of objects to replace the '
f'objects in the {name}, got a '
f'{type(panes).__name__} type.'
)
expected = len(panes)
new_objects = [None]*expected # type: ignore
end = expected
elif end > len(self.objects):
raise IndexError('Index %d out of bounds on %s '
'containing %d objects.' %
(end, type(self).__name__, len(self.objects)))
raise IndexError(
f'Index {end} out of bounds on {name} containing '
f'{len(self.objects)} objects.'
)
else:
expected = end-start
if not isinstance(panes, list) or len(panes) != expected:
raise IndexError('Expected a list of %d objects to set '
'on the %s to match the supplied slice.' %
(expected, type(self).__name__))
raise IndexError(
f'Expected a list of {expected} objects to set '
f'on the {name} to match the supplied slice.'
)
for i, pane in zip(range(start, end), panes):
new_objects[i] = pane

Expand All @@ -445,8 +453,10 @@ def clone(self, *objects: Any, **params: Any) -> ListLike:
else:
objects = self.objects
elif 'objects' in params:
raise ValueError(f"A {type(self).__name__}'s objects should be supplied either "
"as arguments or as a keyword, not both.")
raise ValueError(
f"A {type(self).__name__}'s objects should be supplied either "
"as arguments or as a keyword, not both."
)
p = dict(self.param.values(), **params)
del p['objects']
return type(self)(*objects, **p)
Expand Down Expand Up @@ -645,35 +655,42 @@ def __radd__(self, other: Iterable[Any]) -> NamedListLike:

def __setitem__(self, index: int | slice, panes: Iterable[Any]) -> None:
new_objects = list(self)
name = type(self).__name__
if not isinstance(index, slice):
if index > len(self.objects):
raise IndexError('Index %d out of bounds on %s '
'containing %d objects.' %
(index, type(self).__name__, len(self.objects)))
raise IndexError(
f'Index {index} out of bounds on {name} '
f'containing {len(self.objects)} objects.'
)
start, end = index, index+1
panes = [panes]
else:
start = index.start or 0
end = len(self.objects) if index.stop is None else index.stop
if index.start is None and index.stop is None:
if not isinstance(panes, list):
raise IndexError('Expected a list of objects to '
f'replace the objects in the {type(self).__name__}, '
f'got a {type(panes).__name__} type.')
raise IndexError(
'Expected a list of objects to replace '
f'the objects in the {name}, got a '
f'{type(panes).__name__} type.'
)
expected = len(panes)
new_objects = [None]*expected # type: ignore
self._names = [None]*len(panes)
end = expected
else:
expected = end-start
if end > len(self.objects):
raise IndexError('Index %d out of bounds on %s '
'containing %d objects.' %
(end, type(self).__name__, len(self.objects)))
nobjs = len(self.objects)
if end > nobjs:
raise IndexError(
f'Index {end} out of bounds on {name} '
'containing {nobjs} objects.'
)
if not isinstance(panes, list) or len(panes) != expected:
raise IndexError('Expected a list of %d objects to set '
'on the %s to match the supplied slice.' %
(expected, type(self).__name__))
raise IndexError(
f'Expected a list of {expected} objects to set '
f'on the {name} to match the supplied slice.'
)
for i, pane in zip(range(start, end), panes):
new_objects[i], self._names[i] = self._to_object_and_name(pane)
self.objects = new_objects
Expand All @@ -694,9 +711,10 @@ def clone(self, *objects: Any, **params: Any) -> NamedListLike:
if objects:
overrides = objects
elif 'objects' in params:
raise ValueError('Tabs objects should be supplied either '
'as positional arguments or as a keyword, '
'not both.')
raise ValueError(
'Tabs objects should be supplied either as positional '
'arguments or as a keyword, not both.'
)
elif 'objects' in params:
overrides = params.pop('objects')
else:
Expand Down
14 changes: 8 additions & 6 deletions panel/layout/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,14 @@ def __setitem__(self, index, obj):
continue
if old_obj not in objects:
objects.append(old_obj)
overlapping += ' (%d, %d): %s\n\n' % (yidx, xidx, old_obj)
overlap_text = ('Specified region overlaps with the following '
'existing object(s) in the grid:\n\n'+overlapping+
'The following shows a view of the grid '
'(empty: 0, occupied: 1, overlapping: 2):\n\n'+
str(grid.astype('uint8')))
overlapping += f' ({yidx}, {xidx}: {old_obj}\n\n'
overlap_text = (
'Specified region overlaps with the following '
'existing object(s) in the grid:\n\n'+overlapping+
'The following shows a view of the grid '
'(empty: 0, occupied: 1, overlapping: 2):\n\n'+
str(grid.astype('uint8'))
)
if self.mode == 'error':
raise IndexError(overlap_text)
elif self.mode == 'warn':
Expand Down
9 changes: 5 additions & 4 deletions panel/layout/tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,11 @@ def _get_objects(self, model, old_objects, doc, root, comm=None):
from ..pane.base import RerenderError, panel
new_models, old_models = [], []
if len(self._names) != len(self):
raise ValueError('Tab names do not match objects, ensure '
'that the Tabs.objects are not modified '
'directly. Found %d names, expected %d.' %
(len(self._names), len(self)))
raise ValueError(
'Tab names do not match objects, ensure that the '
'Tabs.objects are not modified directly. '
f'Found {len(self._names)} names, expected {len(self)}.'
)
for i, (name, pane) in enumerate(zip(self._names, self)):
pane = panel(pane, name=name)
self.objects[i] = pane
Expand Down
2 changes: 1 addition & 1 deletion panel/pane/vtk/synchronizable_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ def genericMapperSerializer(parent, mapper, mapperId, context, depth):
for port in range(mapper.GetNumberOfInputPorts()): # Glyph3DMapper can define input data objects on 2 ports (input, source)
dataObject = mapper.GetInputDataObject(port, 0)
if dataObject:
dataObjectId = '%s-dataset-%d' % (mapperId, port)
dataObjectId = f'{mapperId}-dataset-{port}'
if parent.IsA('vtkActor') and not mapper.IsA('vtkTexture'):
# vtk-js actors can render only surfacic datasets
# => we ensure to convert the dataset in polydata
Expand Down
2 changes: 1 addition & 1 deletion panel/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def __repr__(self):
else:
cls_name = stage.__name__
params = ', '.join(param_reprs(stage))
repr_str += '\n [%d] %s: %s(%s)' % (i, name, cls_name, params)
repr_str += f'\n [{i}] {name}: {cls_name}({params})'
return repr_str

def __str__(self):
Expand Down
2 changes: 1 addition & 1 deletion panel/reactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -2048,7 +2048,7 @@ def _get_template(self) -> tuple[str, list[str], Mapping[str, list[tuple[str, li
for parent, child_name in self._parser.children.items():
if (parent, child_name) in self._parser.looped:
for i, _ in enumerate(getattr(self, child_name)):
html = html.replace('${%s[%d]}' % (child_name, i), '')
html = html.replace(f'${{{child_name}[{i}]}}', '')
else:
html = html.replace(f'${{{child_name}}}', '')
return html, parser.nodes, p_attrs
Expand Down
2 changes: 1 addition & 1 deletion panel/tests/io/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def link(target, event):
assert event1['kind'] == 'ModelChanged'
assert event1['attr'] == 'text'
assert event1['model'] == model.children[0].children[0].ref
assert event1['new'] == '<b>%d</b>' % values[k]
assert event1['new'] == f'<b>{values[k]:.0f}</b>'

assert event2['kind'] == 'ModelChanged'
assert event2['attr'] == 'text'
Expand Down
10 changes: 5 additions & 5 deletions panel/tests/test_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,11 +1145,11 @@ class View(param.Parameterized):

@param.depends('a')
def view(self):
return Div(text='%d' % self.a)
return Div(text=str(int(self.a)))

@param.depends('b.param')
def subobject_view(self):
return Div(text='%d' % self.b.a)
return Div(text=str(int(self.b.a)))

@param.depends('a')
def mpl_view(self):
Expand All @@ -1164,7 +1164,7 @@ def test_get_param_function_pane_type():
test = View()

def view(a):
return Div(text='%d' % a)
return Div(text=str(int(a)))

assert PaneBase.get_pane_type(view) is not ParamFunction
assert PaneBase.get_pane_type(param.depends(test.param.a)(view)) is ParamFunction
Expand All @@ -1175,7 +1175,7 @@ def test_param_function_pane(document, comm):

@param.depends(test.param.a)
def view(a):
return Div(text='%d' % a)
return Div(text=str(int(a)))

pane = panel(view)
inner_pane = pane._pane
Expand Down Expand Up @@ -1216,7 +1216,7 @@ def test_param_function_pane_defer_load(document, comm):

@param.depends(test.param.a)
def view(a):
return Div(text='%d' % a)
return Div(text=str(int(a)))

pane = panel(view, defer_load=True)
inner_pane = pane._pane
Expand Down
2 changes: 1 addition & 1 deletion panel/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def http_serve_directory(directory=".", port=0):
httpd.timeout = 0.5
httpd.server_bind()

address = "http://%s:%d" % (httpd.server_name, httpd.server_port)
address = f"http://{httpd.server_name}:{httpd.server_port}"

httpd.server_activate()

Expand Down
2 changes: 1 addition & 1 deletion panel/tests/widgets/test_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def test_discrete_slider_disabled(document, comm):


def test_discrete_date_slider(document, comm):
dates = {'2016-01-0%d' % i: datetime(2016, 1, i) for i in range(1, 4)}
dates = {f'2016-01-0{i:d}' % i: datetime(2016, 1, i) for i in range(1, 4)}
philippjfr marked this conversation as resolved.
Show resolved Hide resolved
discrete_slider = DiscreteSlider(name='DiscreteSlider', value=dates['2016-01-02'],
options=dates)

Expand Down
10 changes: 6 additions & 4 deletions panel/theme/css/fast.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
:host {
--track-width: 4;
--thumb-size: calc(
(var(--base-height-multiplier) + var(--density)) * var(--design-unit) * 0.5 -
var(--design-unit)
(var(--base-height-multiplier) + var(--density)) * var(--design-unit) *
0.5 - var(--design-unit)
);
--handle-width: calc(var(--thumb-size) * 1px);
--handle-height: calc(var(--thumb-size) * 1px);
Expand Down Expand Up @@ -743,7 +743,8 @@ select:not([size]).bk-input {
(
(var(--base-height-multiplier) + var(--density)) * var(--design-unit) /
2 + var(--design-unit)
) * 1px
) *
1px
);
}

Expand All @@ -764,7 +765,8 @@ select:not([size]).bk-input {
(
(var(--base-height-multiplier) + var(--density)) * var(--design-unit) /
2 + var(--design-unit)
) * 1px
) *
1px
);
top: 0;
width: calc(
Expand Down
Loading