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

ci: start using ruff #654

Merged
merged 1 commit into from
Dec 27, 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 .codespellrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[codespell]
skip = **/package-lock.json,*.vti,PKG-INFO,**/dist/**,CHANGELOG.md
skip = **/package-lock.json,*.vti,PKG-INFO,**/dist/**,CHANGELOG.md,**/*.js
ignore-words-list = hist
ignore-regex = name="ba"
13 changes: 4 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
repos:
- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black
entry: black --check

- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell

- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.4
hooks:
- id: flake8
- id: ruff
- id: ruff-format
3 changes: 1 addition & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Tips
####

#. When first creating a new project, it is helpful to run ``pre-commit run --all-files`` to ensure all files pass the pre-commit checks.
#. A quick way to fix ``black`` issues is by installing black (``pip install black``) and running the ``black`` command at the root of your repository.
#. Sometimes, ``black`` and ``flake8`` do not agree. Add options to your ``.flake8`` file to fix these things. See the `flake8 configuration docs <https://flake8.pycqa.org/en/latest/user/configuration.html>`_ for more details.
#. A quick way to fix ``ruff`` issues is by installing ruff (``pip install ruff``) and running the ``ruff check --fix .`` or ``ruff format`` command at the root of your repository.
#. A quick way to fix ``codespell`` issues is by installing codespell (``pip install codespell``) and running the ``codespell -w`` command at the root of your directory.
#. The `.codespellrc file <https://github.com/codespell-project/codespell#using-a-config-file>`_ can be used fix any other codespell issues, such as ignoring certain files, directories, words, or regular expressions.
4 changes: 2 additions & 2 deletions docker/scripts/generate_launcher_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def run(input_path, apps_path, out_path):
for app_name, config in apps_dict.items():
if "app" not in config and "cmd" not in config:
msg = (
f'In {apps_path}, every app must contain an "app" key if a "cmd" is not provided, but '
f'"{app_name}" does not'
f'In {apps_path}, every app must contain an "app" key '
f'if a "cmd" is not provided, but "{app_name}" does not'
)
raise Exception(msg)

Expand Down
1 change: 0 additions & 1 deletion docs/api/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@


def run_apidoc(_):

# Override the apidoc options with what we want
apidoc.OPTIONS.clear()
apidoc.OPTIONS.extend(
Expand Down
2 changes: 1 addition & 1 deletion docs/vitepress/guide/jupyter/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
print(os.environ.get("TRAME_JUPYTER_WWW"))

app = Cone()
await app.ui.ready
await app.ui.ready # noqa: F704

print(app.ui._jupyter_content())

Expand Down
2 changes: 1 addition & 1 deletion examples/00_howdoi/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
async def start_countdown():
try:
state.countdown = int(state.countdown)
except:
except ValueError:
state.countdown = coundown_init

while state.countdown > 0:
Expand Down
2 changes: 1 addition & 1 deletion examples/00_howdoi/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def validate_my_number(my_number, **kwargs):

try:
state.my_number = int(my_number)
except:
except ValueError:
state.my_number = DEFAULT_VALUE


Expand Down
13 changes: 12 additions & 1 deletion examples/00_howdoi/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@
# --------------------------------------------------------------------------------
data = json.loads(
"""
[{"name":"Frozen Yogurt","calories":200,"fat":6,"carbs":24,"protein":4,"iron":"1%"},{"name":"Ice cream sandwich","calories":200,"fat":9,"carbs":37,"protein":4.3,"iron":"1%"},{"name":"Eclair","calories":300,"fat":16,"carbs":23,"protein":6,"iron":"7%"},{"name":"Cupcake","calories":300,"fat":3.7,"carbs":67,"protein":4.3,"iron":"8%"},{"name":"Gingerbread","calories":400,"fat":16,"carbs":49,"protein":3.9,"iron":"16%"},{"name":"Jelly bean","calories":400,"fat":0,"carbs":94,"protein":0,"iron":"0%"},{"name":"Lollipop","calories":400,"fat":0.2,"carbs":98,"protein":0,"iron":"2%"},{"name":"Honeycomb","calories":400,"fat":3.2,"carbs":87,"protein":6.5,"iron":"45%"},{"name":"Donut","calories":500,"fat":25,"carbs":51,"protein":4.9,"iron":"22%"},{"name":"KitKat","calories":500,"fat":26,"carbs":65,"protein":7,"iron":"6%"}]
[
{"name":"Frozen Yogurt","calories":200,"fat":6,"carbs":24,"protein":4,"iron":"1%"},
{"name":"Ice cream sandwich","calories":200,"fat":9,"carbs":37,"protein":4.3,"iron":"1%"},
{"name":"Eclair","calories":300,"fat":16,"carbs":23,"protein":6,"iron":"7%"},
{"name":"Cupcake","calories":300,"fat":3.7,"carbs":67,"protein":4.3,"iron":"8%"},
{"name":"Gingerbread","calories":400,"fat":16,"carbs":49,"protein":3.9,"iron":"16%"},
{"name":"Jelly bean","calories":400,"fat":0,"carbs":94,"protein":0,"iron":"0%"},
{"name":"Lollipop","calories":400,"fat":0.2,"carbs":98,"protein":0,"iron":"2%"},
{"name":"Honeycomb","calories":400,"fat":3.2,"carbs":87,"protein":6.5,"iron":"45%"},
{"name":"Donut","calories":500,"fat":25,"carbs":51,"protein":4.9,"iron":"22%"},
{"name":"KitKat","calories":500,"fat":26,"carbs":65,"protein":7,"iron":"6%"}
]
"""
)

Expand Down
13 changes: 12 additions & 1 deletion examples/00_howdoi/table_dyna.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@
# --------------------------------------------------------------------------------
data = json.loads(
"""
[{"name":"Frozen Yogurt","calories":200,"fat":6,"carbs":24,"protein":4,"iron":"1%"},{"name":"Ice cream sandwich","calories":200,"fat":9,"carbs":37,"protein":4.3,"iron":"1%"},{"name":"Eclair","calories":300,"fat":16,"carbs":23,"protein":6,"iron":"7%"},{"name":"Cupcake","calories":300,"fat":3.7,"carbs":67,"protein":4.3,"iron":"8%"},{"name":"Gingerbread","calories":400,"fat":16,"carbs":49,"protein":3.9,"iron":"16%"},{"name":"Jelly bean","calories":400,"fat":0,"carbs":94,"protein":0,"iron":"0%"},{"name":"Lollipop","calories":400,"fat":0.2,"carbs":98,"protein":0,"iron":"2%"},{"name":"Honeycomb","calories":400,"fat":3.2,"carbs":87,"protein":6.5,"iron":"45%"},{"name":"Donut","calories":500,"fat":25,"carbs":51,"protein":4.9,"iron":"22%"},{"name":"KitKat","calories":500,"fat":26,"carbs":65,"protein":7,"iron":"6%"}]
[
{"name":"Frozen Yogurt","calories":200,"fat":6,"carbs":24,"protein":4,"iron":"1%"},
{"name":"Ice cream sandwich","calories":200,"fat":9,"carbs":37,"protein":4.3,"iron":"1%"},
{"name":"Eclair","calories":300,"fat":16,"carbs":23,"protein":6,"iron":"7%"},
{"name":"Cupcake","calories":300,"fat":3.7,"carbs":67,"protein":4.3,"iron":"8%"},
{"name":"Gingerbread","calories":400,"fat":16,"carbs":49,"protein":3.9,"iron":"16%"},
{"name":"Jelly bean","calories":400,"fat":0,"carbs":94,"protein":0,"iron":"0%"},
{"name":"Lollipop","calories":400,"fat":0.2,"carbs":98,"protein":0,"iron":"2%"},
{"name":"Honeycomb","calories":400,"fat":3.2,"carbs":87,"protein":6.5,"iron":"45%"},
{"name":"Donut","calories":500,"fat":25,"carbs":51,"protein":4.9,"iron":"22%"},
{"name":"KitKat","calories":500,"fat":26,"carbs":65,"protein":7,"iron":"6%"}
]
"""
)

Expand Down
2 changes: 2 additions & 0 deletions examples/00_howdoi/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def file_uploaded(file_exchange, **kwargs):
file_binary_content = file_exchange.get(
"content"
) # can be either list(bytes, ...), or bytes
print(f"{file_name=}, {file_size=} {file_time=} {file_mime_type=}")
print(f"file_binary_content=size({len(file_binary_content)})")
print(file.info)
print(type(file.content)) # will always be bytes
# print(file_binary_content)
Expand Down
1 change: 0 additions & 1 deletion examples/02_vuetify/00_dataframe-table-vue3.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ def update_values(rows, **kwargs):
)

with layout.content:

state.rows = rows
with vuetify.VDataTable(**table):
with vuetify.Template(
Expand Down
3 changes: 1 addition & 2 deletions examples/05_charts/Plotly/01_plotly-charts-resizable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import plotly.graph_objects as go
import plotly.figure_factory as ff
from plotly.subplots import make_subplots

from trame.app import get_server
from trame.ui.vuetify import SinglePageLayout
Expand Down Expand Up @@ -236,7 +235,7 @@ def update_polar_size(polar_size, **kwargs):


@state.change("ternary_size")
def update_stream_size(ternary_size, **kwargs):
def update_ternary_size(ternary_size, **kwargs):
if ternary_size is None:
return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ def update_grid(nodes_file, elems_file, field_file, **kwargs):
points = df_nodes[["x", "y", "z"]].to_numpy()
cell_types = df_elems["cell_types"].to_numpy()
n_nodes = df_elems.loc[:, "n_nodes"].to_numpy()
# subtract starting node id from all grid references in cells to avoid filling from 0 to first used node (in case mesh doesn't start at 1)
# subtract starting node id from all grid references in cells to avoid
# filling from 0 to first used node (in case mesh doesn't start at 1)
p = df_elems.iloc[:, 3:-1].to_numpy() - df_nodes.index.min()
# if you need to, re-order nodes here-ish
a = np.hstack((n_nodes.reshape((len(n_nodes), 1)), p))
Expand Down Expand Up @@ -344,7 +345,7 @@ def update_tooltip(pick_data, pixel_ratio, **kwargs):
elevation=2,
outlined=True,
):
vuetify.VCardText("<pre>{{ tooltip }}</pre>"),
vuetify.VCardText("<pre>{{ tooltip }}</pre>")


# Variables not defined within HTML but used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ def update_grid(nodes_file, elems_file, field_file, **kwargs):
points = df_nodes[["x", "y", "z"]].to_numpy()
cell_types = df_elems["cell_types"].to_numpy()
n_nodes = df_elems.loc[:, "n_nodes"].to_numpy()
# subtract starting node id from all grid references in cells to avoid filling from 0 to first used node (in case mesh doesn't start at 1)
# subtract starting node id from all grid references in cells to avoid
# filling from 0 to first used node (in case mesh doesn't start at 1)
p = df_elems.iloc[:, 3:-1].to_numpy() - df_nodes.index.min()
# if you need to, re-order nodes here-ish
a = np.hstack((n_nodes.reshape((len(n_nodes), 1)), p))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ def update_grid(nodes_file, elems_file, field_file, **kwargs):
points = df_nodes[["x", "y", "z"]].to_numpy()
cell_types = df_elems["cell_types"].to_numpy()
n_nodes = df_elems.loc[:, "n_nodes"].to_numpy()
# subtract starting node id from all grid references in cells to avoid filling from 0 to first used node (in case mesh doesn't start at 1)
# subtract starting node id from all grid references in cells to avoid
# filling from 0 to first used node (in case mesh doesn't start at 1)
p = df_elems.iloc[:, 3:-1].to_numpy() - df_nodes.index.min()
# if you need to, re-order nodes here-ish
a = np.hstack((n_nodes.reshape((len(n_nodes), 1)), p))
Expand Down
3 changes: 0 additions & 3 deletions examples/06_vtk/Applications/RemoteSelection/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pandas as pd

# Plotly/chart imports
import plotly.graph_objects as go
import plotly.express as px

# Trame imports
Expand Down Expand Up @@ -34,11 +33,9 @@

from vtkmodules.vtkInteractionStyle import (
vtkInteractorStyleRubberBandPick,
vtkInteractorStyleSwitch,
) # noqa
import vtkmodules.vtkRenderingOpenGL2 # noqa

from vtkmodules.vtkInteractionStyle import vtkInteractorStyleRubberBandPick

# -----------------------------------------------------------------------------
# Data file information
Expand Down
7 changes: 6 additions & 1 deletion examples/06_vtk/Applications/SurfacePicking/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,12 @@ def update_tooltip(pickData, pixel_ratio, **kwargs):
color_data_range=("fieldParameters[field].range",),
actor=("{ visibility: f1Visible }",),
mapper=(
"{ colorByArrayName: field, scalarMode: 3, interpolateScalarsBeforeMapping: true, scalarVisibility: field !== 'solid' }",
"""{
colorByArrayName: field,
scalarMode: 3,
interpolateScalarsBeforeMapping: true,
scalarVisibility: field !== 'solid',
}""",
),
):
vtk_widgets.VtkMesh("f1", dataset=f1_mesh, point_arrays=["p", "U"])
Expand Down
7 changes: 6 additions & 1 deletion examples/06_vtk/Applications/VTPViewer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ def load_client_files(files, **kwargs):
"fields[field] && fields[field].range || [0, 1]",
),
mapper=(
"{ colorByArrayName: field, scalarMode: fields[field] && fields[field].scalarMode || 3, interpolateScalarsBeforeMapping: true, scalarVisibility: field !== 'solid' }",
"""{
colorByArrayName: field,
scalarMode: fields[field] && fields[field].scalarMode || 3,
interpolateScalarsBeforeMapping: true,
scalarVisibility: field !== 'solid',
}""",
),
):
vtk_widgets.VtkMesh("myMesh", state=("mesh",))
Expand Down
6 changes: 4 additions & 2 deletions examples/06_vtk/Applications/ZarrContourViewer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ def decrease_level():
classes="mx-2",
)
html.Div(
"Level({{ level }}) - Points({{parseInt( points ).toLocaleString()}}) - Cells({{parseInt( cells ).toLocaleString()}})",
"Level({{ level }}) "
"- Points({{parseInt( points ).toLocaleString()}}) "
"- Cells({{parseInt( cells ).toLocaleString()}})",
style="min-width: 350px; text-align: right;",
)
vuetify.VDivider(vertical=True, classes="mx-2"),
vuetify.VDivider(vertical=True, classes="mx-2")
vuetify.VBtn(
icon=True,
click=update_reset_level,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os, sys
import os
import sys
import zarr

import vtk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from trame.widgets import vuetify, paraview
from trame.ui.vuetify import SinglePageLayout

from paraview import simple

# -----------------------------------------------------------------------------
# Trame setup
# -----------------------------------------------------------------------------
Expand All @@ -28,12 +30,10 @@
# -----------------------------------------------------------------------------
# ParaView pipeline
# -----------------------------------------------------------------------------
from paraview import simple

simple.LoadDistributedPlugin("AcceleratedAlgorithms", remote=False, ns=globals())
reader = simple.XMLImageDataReader(FileName=[str(head_vti)])
# contour = simple.Contour(Input=reader) # Default filter => no plugin but slow
contour = FlyingEdges3D(Input=reader) # Faster processing => make it interactive
contour = simple.FlyingEdges3D(Input=reader) # Faster processing => make it interactive

# Extract data range => Update store/state
array = reader.GetPointDataInformation().GetArray(0)
Expand Down
2 changes: 1 addition & 1 deletion examples/07_paraview/ContourGeometry/RemoteRendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

reader = simple.XMLImageDataReader(FileName=[str(head_vti)])
# contour = simple.Contour(Input=reader) # Default filter => no plugin but slow
contour = FlyingEdges3D(Input=reader) # Faster processing => make it interactive
contour = simple.FlyingEdges3D(Input=reader) # Faster processing => make it interactive

# Extract data range => Update store/state
array = reader.GetPointDataInformation().GetArray(0)
Expand Down
4 changes: 2 additions & 2 deletions examples/07_paraview/Wavelet/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,13 @@ def ui_state_target_fps_change(self, target_fps, **kwargs):
vuetify.VSpacer()
vuetify.VIcon("mdi-dots-triangle", x_small=True, classes="mr-1")
html.Div(
"{{ active_data_info?.points.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') | 0 }}",
r"{{ active_data_info?.points.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') | 0 }}",
classes="text-caption",
)
vuetify.VSpacer()
vuetify.VIcon("mdi-triangle-outline", x_small=True, classes="mr-1")
html.Div(
"{{ active_data_info?.cells.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') || 0 }}",
r"{{ active_data_info?.cells.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') || 0 }}",
classes="text-caption",
)
vuetify.VDivider()
Expand Down
4 changes: 2 additions & 2 deletions examples/07_paraview/WaveletROI/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import paraview.web.venv
from trame.app import get_server
from trame.ui.vuetify3 import SinglePageWithDrawerLayout
from trame.widgets import vuetify3 as v3, paraview as pv_widgets
Expand Down Expand Up @@ -75,7 +74,8 @@ def _build_ui(self):
with SinglePageWithDrawerLayout(self.server, full_height=True) as layout:
with layout.toolbar:
v3.VLabel(
"Extent [{{i_range.join(', ')}}, {{j_range.join(', ')}}, {{k_range.join(', ')}}] - Volume: {{ volume }}",
"Extent [{{i_range.join(', ')}}, {{j_range.join(', ')}}, {{k_range.join(', ')}}]"
" - Volume: {{ volume }}",
classes="mx-2",
)
v3.VBtn(icon="mdi-crop-free", click=self.ctrl.view_reset_camera)
Expand Down
5 changes: 4 additions & 1 deletion examples/08_pydeck/01_uber-nyc-pickups.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@
)


def lowercase(x):
return str(x).lower()


def load_data(nrows):
data = pd.read_csv(DATA_URL, nrows=nrows)
lowercase = lambda x: str(x).lower()
data.rename(lowercase, axis="columns", inplace=True)
data[DATE_TIME] = pd.to_datetime(data[DATE_TIME])
return data
Expand Down
1 change: 0 additions & 1 deletion examples/09_advanced/custom_endpoint/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from trame.decorators import TrameApp, controller

import time
from pathlib import Path
from aiohttp import web


Expand Down
18 changes: 15 additions & 3 deletions examples/09_advanced/popup_window/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from trame.app import get_server
from trame.widgets import vuetify3, client
from trame.widgets import vuetify3
from trame.ui.vuetify3 import SinglePageLayout, VAppLayout


Expand Down Expand Up @@ -33,15 +33,27 @@ def ui_main(self):
vuetify3.VBtn(
"Open Hello",
disabled=("window_hello",),
click="window_hello = window.open('/?ui=hello', target='_blank', 'popup,width=200,height=200,left=10,top=10')",
click="""
window_hello = window.open(
'/?ui=hello',
target='_blank',
'popup,width=200,height=200,left=10,top=10'
)
""",
)
vuetify3.VBtn(
"Close Hello", click="window_hello.close(); window_hello = null;"
)
vuetify3.VBtn(
"Open World",
disabled=("window_world",),
click="window_world = window.open('/?ui=world', target='_blank', 'popup,width=200,height=200,left=100,top=100')",
click="""
window_world = window.open(
'/?ui=world',
target='_blank',
'popup,width=200,height=200,left=100,top=100'
)
""",
)
vuetify3.VBtn(
"Close World", click="window_world.close(); window_world = null;"
Expand Down
Loading
Loading