diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b0986fbc3..83573fb50 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,7 +16,7 @@ repos: - id: pyupgrade args: [--py36-plus] - repo: https://github.com/codespell-project/codespell - rev: v2.3.0 + rev: v2.4.0 hooks: - id: codespell files: ^.*\.(py|md|yaml|js|ts|ipynb)$ @@ -24,7 +24,7 @@ repos: additional_dependencies: - tomli - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.6 + rev: v0.9.3 hooks: - id: ruff stages: [pre-commit] diff --git a/solara/__main__.py b/solara/__main__.py index 028baadfd..b3b156013 100644 --- a/solara/__main__.py +++ b/solara/__main__.py @@ -156,7 +156,7 @@ def cli(): "--restart-dir", "restart_dirs", multiple=True, - help="Set restart directories explicitly, instead of using the current working" " directory.", + help="Set restart directories explicitly, instead of using the current working directory.", type=click.Path(exists=True), ) @click.option( @@ -172,7 +172,7 @@ def cli(): "--workers", default=None, type=int, - help="Number of worker processes. Defaults to the $WEB_CONCURRENCY environment" " variable if available, or 1. Not valid with --auto-restart/-a.", + help="Number of worker processes. Defaults to the $WEB_CONCURRENCY environment variable if available, or 1. Not valid with --auto-restart/-a.", ) @click.option( "--env-file", diff --git a/solara/_stores.py b/solara/_stores.py index df7d54385..54794be79 100644 --- a/solara/_stores.py +++ b/solara/_stores.py @@ -87,7 +87,7 @@ def check_mutations(self): code = tb.code_context[0] else: code = "" - msg += f"The last value was read in the following code:\n" f"{tb.filename}:{tb.lineno}\n" f"{code}" + msg += f"The last value was read in the following code:\n{tb.filename}:{tb.lineno}\n{code}" raise ValueError(msg) elif not isinstance(store_value.set_value, _SetValueNotSet) and not self.equals(store_value.set_value, store_value.private): tb = store_value.set_traceback @@ -120,7 +120,7 @@ def check_mutations(self): code = tb.code_context[0] else: code = "" - msg += "The last time the value was set was at:\n" f"{tb.filename}:{tb.lineno}\n" f"{code}" + msg += f"The last time the value was set was at:\n{tb.filename}:{tb.lineno}\n{code}" raise ValueError(msg) def _ensure_public_exists(self): @@ -164,7 +164,7 @@ def _check_equals(self, a: S, b: S): code = tb.code_context[0] else: code = "" - warn += "This warning was triggered from:\n" f"{tb.filename}:{tb.lineno}\n" f"{code}" + warn += f"This warning was triggered from:\n{tb.filename}:{tb.lineno}\n{code}" warnings.warn(warn) self._enabled = False @@ -239,7 +239,7 @@ def __init__(self, value: S, equals: Callable[[Any, Any], bool] = solara.util.eq code = tb.code_context[0] else: code = "" - msg += "This warning was triggered from:\n" f"{tb.filename}:{tb.lineno}\n" f"{code}" + msg += f"This warning was triggered from:\n{tb.filename}:{tb.lineno}\n{code}" warnings.warn(msg) self._mutation_detection = False super().__init__(equals=equals) @@ -256,7 +256,7 @@ def _check_mutation(self): code = tb.code_context[0].strip() else: code = "No code context available" - msg = f"Reactive variable was initialized at {tb.filename}:{tb.lineno} with {initial!r}, but was mutated to {current!r}.\n" f"{code}" + msg = f"Reactive variable was initialized at {tb.filename}:{tb.lineno} with {initial!r}, but was mutated to {current!r}.\n{code}" else: msg = f"Reactive variable was initialized with a value of {initial!r}, but was mutated to {current!r} (unable to report the location in the source code)." raise ValueError(msg) diff --git a/solara/checks.py b/solara/checks.py index 49567a1a5..969a37eec 100644 --- a/solara/checks.py +++ b/solara/checks.py @@ -164,7 +164,7 @@ def get_server_python_executable(silent: bool = False): else: python = pythons[0] if not silent: - warnings.warn("Found multiple find servers:\n%s\n" "We are assuming the server is running under Python executable: %s" % (info, python)) + warnings.warn(f"Found multiple find servers:\n{info}\nWe are assuming the server is running under Python executable: {python}") else: python = pythons[0] return python diff --git a/solara/components/style.py b/solara/components/style.py index 60b43ad78..8b1ae75f9 100644 --- a/solara/components/style.py +++ b/solara/components/style.py @@ -101,5 +101,5 @@ async def watch(): {css_content} """ - # using .key avoids re-using the template, which causes a flicker (due to ipyvue) + # using .key avoids reusing the template, which causes a flicker (due to ipyvue) return v.VuetifyTemplate.element(template=template).key(key) diff --git a/solara/lab/components/chat.py b/solara/lab/components/chat.py index 1f64813c5..3821386a2 100644 --- a/solara/lab/components/chat.py +++ b/solara/lab/components/chat.py @@ -203,12 +203,12 @@ def ChatMessage( .chat-message-{msg_uuid}.left{{ border-top-left-radius: 0; background-color:var(--color); - { "margin-left: 10px !important;" if notch else ""} + {"margin-left: 10px !important;" if notch else ""} }} .chat-message-{msg_uuid}.right{{ border-top-right-radius: 0; background-color:var(--color); - { "margin-right: 10px !important;" if notch else ""} + {"margin-right: 10px !important;" if notch else ""} }} {extra_styles} """ diff --git a/solara/server/server.py b/solara/server/server.py index ecb4fa98a..7251319d3 100644 --- a/solara/server/server.py +++ b/solara/server/server.py @@ -187,7 +187,7 @@ async def app_loop( created_widgets_count = len(widgets_ids_after - widgets_ids) close_widgets_count = len(widgets_ids - widgets_ids_after) print( # noqa: T201 - f"timing: total={t2-t0:.3f}s, deserialize={t1-t0:.3f}s, kernel={t2-t1:.3f}s" + f"timing: total={t2 - t0:.3f}s, deserialize={t1 - t0:.3f}s, kernel={t2 - t1:.3f}s" f" widget: created: {created_widgets_count} closed: {close_widgets_count}" ) finally: diff --git a/solara/server/starlette.py b/solara/server/starlette.py index 91f375fa0..78d2e4cb2 100644 --- a/solara/server/starlette.py +++ b/solara/server/starlette.py @@ -380,7 +380,7 @@ async def root(request: Request, fullpath: str = ""): forwarded_proto = request.headers.get("x-forwarded-proto") host = request.headers.get("host") if forwarded_proto and forwarded_proto != request.scope["scheme"]: - warnings.warn(f"""Header x-forwarded-proto={forwarded_proto!r} does not match scheme={request.scope['scheme']!r} as given by the asgi framework (probably uvicorn) + warnings.warn(f"""Header x-forwarded-proto={forwarded_proto!r} does not match scheme={request.scope["scheme"]!r} as given by the asgi framework (probably uvicorn) This might be a configuration mismatch behind a reverse proxy and can cause issues with redirect urls, and auth. @@ -439,10 +439,10 @@ async def root(request: Request, fullpath: str = ""): See also https://solara.dev/documentation/getting_started/deploying/self-hosted """ if "script-name" in request.headers: - msg += f"""It looks like the reverse proxy sets the script-name header to {request.headers['script-name']!r} + msg += f"""It looks like the reverse proxy sets the script-name header to {request.headers["script-name"]!r} """ if "x-script-name" in request.headers: - msg += f"""It looks like the reverse proxy sets the x-script-name header to {request.headers['x-script-name']!r} + msg += f"""It looks like the reverse proxy sets the x-script-name header to {request.headers["x-script-name"]!r} """ if configured_root_path: msg += f"""It looks like the root path was configured to {configured_root_path!r} in the settings @@ -502,8 +502,8 @@ async def root(request: Request, fullpath: str = ""): samesite = "none" secure = True elif request.base_url.hostname != "localhost": - warnings.warn(f"""Cookies with samesite=none require https, but according to the asgi framework, the scheme is {request.scope['scheme']!r} -and the x-forwarded-proto header is {request.headers.get('x-forwarded-proto', 'http')!r}. We will fallback to samesite=lax. + warnings.warn(f"""Cookies with samesite=none require https, but according to the asgi framework, the scheme is {request.scope["scheme"]!r} +and the x-forwarded-proto header is {request.headers.get("x-forwarded-proto", "http")!r}. We will fallback to samesite=lax. If you embed solara in an iframe, make sure you forward the x-forwarded-proto header correctly so that the session cookie can be set. diff --git a/solara/test/pytest_plugin.py b/solara/test/pytest_plugin.py index 686c0e8d1..8dbd222f5 100644 --- a/solara/test/pytest_plugin.py +++ b/solara/test/pytest_plugin.py @@ -101,7 +101,7 @@ def context_session( if capture_screenshot: for index, page in enumerate(pages): human_readable_status = "failed" if failed else "finished" - screenshot_path = _build_artifact_test_folder(pytestconfig, request, f"test-{human_readable_status}-{index+1}.png") + screenshot_path = _build_artifact_test_folder(pytestconfig, request, f"test-{human_readable_status}-{index + 1}.png") try: page.screenshot(timeout=5000, path=screenshot_path) except Error: diff --git a/solara/toestand.py b/solara/toestand.py index ac285d56c..9d906f702 100644 --- a/solara/toestand.py +++ b/solara/toestand.py @@ -398,7 +398,7 @@ def __init__(self, default_value: S, key=None, equals: Callable[[Any, Any], bool code = tb.code_context[0] else: code = "" - msg += "This warning was triggered from:\n" f"{tb.filename}:{tb.lineno}\n" f"{code}" + msg += f"This warning was triggered from:\n{tb.filename}:{tb.lineno}\n{code}" warnings.warn(msg) self._mutation_detection = False cls = type(default_value) @@ -425,7 +425,7 @@ def _check_mutation(self): code = tb.code_context[0].strip() else: code = "No code context available" - msg = f"Reactive variable was initialized at {tb.filename}:{tb.lineno} with {initial!r}, but was mutated to {current!r}.\n" f"{code}" + msg = f"Reactive variable was initialized at {tb.filename}:{tb.lineno} with {initial!r}, but was mutated to {current!r}.\n{code}" else: msg = f"Reactive variable was initialized with a value of {initial!r}, but was mutated to {current!r} (unable to report the location in the source code)." raise ValueError(msg) diff --git a/solara/website/pages/documentation/advanced/content/10-howto/20-layout.md b/solara/website/pages/documentation/advanced/content/10-howto/20-layout.md index 1d425b23c..f6c079737 100644 --- a/solara/website/pages/documentation/advanced/content/10-howto/20-layout.md +++ b/solara/website/pages/documentation/advanced/content/10-howto/20-layout.md @@ -122,4 +122,4 @@ The following [Container components](/documentation/advanced/understanding/conta * [GridDraggable](/documentation/components/layout/griddraggable) * [VBox](/documentation/components/layout/vbox) (kept for ipywidgets compatibility, please use Column) * [HBox](/documentation/components/layout/hbox) (kept for ipywidgets compatibility, please use Row) - * [AppLayout](/documentation/components/layout/app_layout) Not often used directly, since Solara will already wrap your page in it. Sometimes re-used in a new `Layout` component. + * [AppLayout](/documentation/components/layout/app_layout) Not often used directly, since Solara will already wrap your page in it. Sometimes reused in a new `Layout` component. diff --git a/solara/website/pages/documentation/examples/general/pokemon_search.py b/solara/website/pages/documentation/examples/general/pokemon_search.py index 39cba6a09..e8e048e0a 100644 --- a/solara/website/pages/documentation/examples/general/pokemon_search.py +++ b/solara/website/pages/documentation/examples/general/pokemon_search.py @@ -40,7 +40,7 @@ def Page(): for pokemon in pokemons[:20]: with solara.Div(): name = pokemon["name"] - url = f'{pokemon_base_url}/{pokemon["image"]}' + url = f"{pokemon_base_url}/{pokemon['image']}" # TODO: how to do this with solara rv.Img(src=url, contain=True, max_height="200px") solara.Text(name) diff --git a/tests/unit/pivottable_test.py b/tests/unit/pivottable_test.py index 632f266be..961953fb4 100644 --- a/tests/unit/pivottable_test.py +++ b/tests/unit/pivottable_test.py @@ -86,7 +86,7 @@ def Test(): assert data["values_x"] == ["106", "171"] assert data["values_y"] == ["158", "119"] assert data["values"] == [["12", "94"], ["146", "25"]] - assert data["total"] == f"{len(df[df.pclass==2]):,}" + assert data["total"] == f"{len(df[df.pclass == 2]):,}" set_filter(None) # wait for the filter to be applied (data should change) rc.find(PivotTableWidget).assert_wait(lambda w: w.d["values"] != [["12", "94"], ["146", "25"]], timeout=10)