Skip to content

Commit

Permalink
chore: Update pre-commit configuration, tools and codebase (#743)
Browse files Browse the repository at this point in the history
* pre-commit: Add pyupgrade

pyupgrade ensures the latest Python syntax supported is used.

* Run pre-commit

check yaml...............................................................Passed
fix end of files.........................................................Failed
- hook id: end-of-file-fixer
- exit code: 1
- files were modified by this hook

Fixing packages/solara-widget-manager8/tsconfig.json
Fixing packages/solara-widget-manager8/src
Fixing packages/solara-widget-manager8/style

trim trailing whitespace.................................................Passed
pyupgrade................................................................Failed
- hook id: pyupgrade
- exit code: 1
- files were modified by this hook

Rewriting solara/website/pages/doc_use_download.py

codespell................................................................Passed
ruff.....................................................................Passed
ruff-format..............................................................Passed
mypy.....................................................................Passed

* pre-commit: Update ruff version, use current repo

Use the latest ruff version (v0.6.1) from the current official ruff repo

* Use `is` for type comparisons

Fix ruff E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks

* Remove redefinition of unused `stack`

Fix ruff F811 in solara\toestand.py:148:40: F811 Redefinition of unused `stack` from line 147

* Run ruff on Jupyter Notebooks

Ruff now also works on Jupyter notebooks by default

* Revert "Run pre-commit"

This reverts commit f530ef8.

* CI: Update code-quality to use Python 3.9 and 3.12

Python 3.9 is the lowest version pre-commit supports. See pre-commit/pre-commit#3042

* Run pre-commit pyupgrade

* Fix pre-commit config warning in mypy hook

Fix: [WARNING] The 'exclude' field in hook 'mypy' is a regex, not a glob -- matching '/*' probably isn't what you want here

In regex, `.` matches any character except a newline, and `*` matches zero or more of the preceding element (in this case, any character). `.*` effectively replaces the `/*` glob pattern.

* Pre-commit: add check-toml, update mypy syntax
  • Loading branch information
EwoutH committed Aug 23, 2024
1 parent 9b7ae75 commit 361b02e
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.8, "3.9"]
python-version: ["3.9", "3.12"] # 3.9 is the lowest version pre-commit supports
env:
LOCK_FILE_LOCATION: .ci-package-locks/code-quality/python${{ matrix.python-version }}.txt

Expand Down
14 changes: 10 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ repos:
rev: v4.5.0
hooks:
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
exclude: .bumpversion.cfg
- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
- id: pyupgrade
args: [--py36-plus]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
Expand All @@ -14,18 +20,18 @@ repos:
args: ["--skip=**/solara_portal/**"]
additional_dependencies:
- tomli
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.3.4"
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.1
hooks:
- id: ruff
stages: [commit]
- id: ruff-format
stages: [commit]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.9.0" # Use the sha / tag you want to point at
rev: v1.9.0
hooks:
- id: mypy
pass_filenames: false
args: [--explicit-package-bases, .]
additional_dependencies: [types-requests, types-markdown, types-PyYAML, types-filelock, types-cachetools, types-redis, types-python-dateutil, types-pycurl, reacton, types-six, types-decorator, ipython, ipykernel]
exclude: tests/unit/solara_test_apps/multipage/04-a_directory/*|nogit
exclude: tests/unit/solara_test_apps/multipage/04-a_directory/.*|nogit
4 changes: 2 additions & 2 deletions solara/components/cross_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,14 @@ def update_filter():
with solara.HBox(align_items="center"):
label = f"Select {column} {mode} " if not invert else f"Drop {column} {mode} "

if py_types[column] == int:
if py_types[column] is int:
if isinstance(filter_value, int):
solara.SliderInt(label=label, value=filter_value, min=vmin, max=vmax, on_value=set_filter_value, disabled=not enable, thumb_label=False)
else:
solara.Error(f"Filter value is not an integer type, but {type(filter_value)} (value = {filter_value})")
if filter_value is not None:
solara.Text(f"{filter_value:,}")
elif py_types[column] == float:
elif py_types[column] is float:
if isinstance(filter_value, float):
solara.SliderFloat(label=label, value=filter_value, min=vmin, max=vmax, on_value=set_filter_value, disabled=not enable, thumb_label=False)
else:
Expand Down
10 changes: 5 additions & 5 deletions solara/minisettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def _get_type(annotation):
if annotation == Optional[check_type]:
return check_type
if hasattr(annotation, "__origin__"):
if annotation.__origin__ == dict:
if annotation.__origin__ is dict:
return dict
return annotation

Expand Down Expand Up @@ -72,13 +72,13 @@ def convert(annotation, value: str) -> Any:
annotation = sub_type
values = value.split(",")
return [convert(sub_type, k) for k in values]
if annotation == str:
if annotation is str:
return value
elif annotation == int:
elif annotation is int:
return int(value)
elif annotation == float:
elif annotation is float:
return float(value)
elif annotation == bool:
elif annotation is bool:
if value in ("True", "true", "1"):
return True
elif value in ("False", "false", "0"):
Expand Down
1 change: 0 additions & 1 deletion solara/toestand.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ def fire(self, new: T, old: T):
for listener2, scope in self.listeners2[scope_id].copy():
if scope is not None:
scopes.add(scope)
stack = contextlib.ExitStack()
with contextlib.ExitStack() as stack:
for scope in scopes:
stack.enter_context(scope)
Expand Down
2 changes: 1 addition & 1 deletion solara/website/pages/doc_use_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def DownloadFile(file_path=file_path, url=url, expected_size=expected_size, on_d
status = "Done 🎉"
else:
MEGABYTES = 2.0**20.0
status = "Downloading {}... ({:6.2f}/{:6.2f} MB)".format(file_path, downloaded_size / MEGABYTES, expected_size / MEGABYTES)
status = f"Downloading {file_path}... ({downloaded_size / MEGABYTES:6.2f}/{expected_size / MEGABYTES:6.2f} MB)"
# status = "hi"
# return MarkdownIt(f'{status}')
assert download.progress is not None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"\n",
"\n",
"df = px.data.iris()\n",
"df\n"
"df"
]
},
{
Expand Down Expand Up @@ -163,17 +163,18 @@
"columns = list(df.columns)\n",
"x_axis = solara.reactive(\"sepal_length\")\n",
"\n",
"\n",
"@solara.component\n",
"def Page():\n",
" # Create a scatter plot by passing \"x_axis.value\" to px.scatter\n",
" # This will automatically make the component listen to changes in x_axis\n",
" # and re-execute this function when x_axis value changes\n",
" fig = px.scatter(df, x_axis.value, \"sepal_width\")\n",
" solara.FigurePlotly(fig)\n",
" \n",
"\n",
" # Pass x_axis to Select component\n",
" # The select will control the x_axis reactive variable\n",
" solara.Select(label=\"X-axis\", value=x_axis, values=columns)\n"
" solara.Select(label=\"X-axis\", value=x_axis, values=columns)"
]
},
{
Expand Down Expand Up @@ -219,12 +220,13 @@
"source": [
"y_axis = solara.reactive(\"sepal_width\")\n",
"\n",
"\n",
"@solara.component\n",
"def Page():\n",
" fig = px.scatter(df, x_axis.value, y_axis.value)\n",
" solara.FigurePlotly(fig)\n",
" solara.Select(label=\"X-axis\", value=x_axis, values=columns)\n",
" solara.Select(label=\"Y-axis\", value=y_axis, values=columns) "
" solara.Select(label=\"Y-axis\", value=y_axis, values=columns)"
]
},
{
Expand Down Expand Up @@ -267,8 +269,7 @@
" solara.Select(label=\"X-axis\", value=x_axis, values=columns)\n",
" solara.Select(label=\"Y-axis\", value=y_axis, values=columns)\n",
" # display it pre-formatted using the backticks `` using Markdown\n",
" solara.Markdown(f\"`{click_data}`\")\n",
" "
" solara.Markdown(f\"`{click_data}`\")"
]
},
{
Expand Down Expand Up @@ -319,7 +320,7 @@
" row_index = click_data.value[\"points\"][\"point_indexes\"][0]\n",
" x = click_data.value[\"points\"][\"xs\"][0]\n",
" y = click_data.value[\"points\"][\"ys\"][0]\n",
" solara.Markdown(f\"`Click on index={row_index} x={x} y={y}`\")\n"
" solara.Markdown(f\"`Click on index={row_index} x={x} y={y}`\")"
]
},
{
Expand Down Expand Up @@ -373,8 +374,8 @@
"\n",
"def find_nearest_neighbours(df, xcol, ycol, x, y, n=10):\n",
" df = df.copy()\n",
" df[\"distance\"] = ((df[xcol] - x)**2 + (df[ycol] - y)**2)**0.5\n",
" return df.sort_values('distance')[1:n+1]\n",
" df[\"distance\"] = ((df[xcol] - x) ** 2 + (df[ycol] - y) ** 2) ** 0.5\n",
" return df.sort_values(\"distance\")[1 : n + 1]\n",
"\n",
"\n",
"@solara.component\n",
Expand All @@ -385,13 +386,12 @@
" x = click_data.value[\"points\"][\"xs\"][0]\n",
" y = click_data.value[\"points\"][\"ys\"][0]\n",
"\n",
" # add an indicator \n",
" # add an indicator\n",
" fig.add_trace(px.scatter(x=[x], y=[y], text=[\"⭐️\"]).data[0])\n",
" df_nearest = find_nearest_neighbours(df, x_axis.value, y_axis.value, x, y, n=3)\n",
" else:\n",
" df_nearest = None\n",
"\n",
"\n",
" solara.FigurePlotly(fig, on_click=click_data.set)\n",
" solara.Select(label=\"X-axis\", value=x_axis, values=columns)\n",
" solara.Select(label=\"Y-axis\", value=y_axis, values=columns)\n",
Expand Down
Loading

0 comments on commit 361b02e

Please sign in to comment.