Skip to content

Commit 3f2a08a

Browse files
authored
ruff rules plus other small changes (#2)
1 parent edc1a38 commit 3f2a08a

File tree

10 files changed

+91
-14
lines changed

10 files changed

+91
-14
lines changed

demo/demo/demo.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22

33
import reflex as rx
44

5-
import reflex_ui as rxui
5+
import reflex_ui as ui
66

77

88
def index() -> rx.Component:
99
# Welcome Page (Index)
1010
return rx.el.div(
11-
rxui.button(rxui.hi("SmileIcon"), "Click me"),
12-
class_name=rxui.cn(
11+
ui.button(
12+
ui.icon("SmileIcon"),
13+
"Click me",
14+
on_click=rx.toast.success(
15+
"You are cool :)",
16+
position="top-center",
17+
),
18+
),
19+
class_name=ui.cn(
1320
"flex flex-col items-center justify-center h-screen", "bg-secondary-1"
1421
),
1522
)

pyproject.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,43 @@ dev = ["pyright==1.1.402", "pre-commit"]
2424

2525
[tool.codespell]
2626
skip = "*.pyi, uv.lock"
27+
28+
[tool.ruff]
29+
target-version = "py313"
30+
output-format = "concise"
31+
lint.isort.split-on-trailing-comma = false
32+
lint.select = ["ALL"]
33+
lint.ignore = [
34+
"A",
35+
"ANN002",
36+
"ANN003",
37+
"ANN2",
38+
"ANN4",
39+
"ARG",
40+
"BLE",
41+
"C901",
42+
"COM",
43+
"D205",
44+
"DTZ",
45+
"E501",
46+
"F403",
47+
"FBT",
48+
"FIX",
49+
"G004",
50+
"ISC003",
51+
"PLC",
52+
"PLR",
53+
"PLW",
54+
"PT011",
55+
"PT012",
56+
"PYI",
57+
"RUF012",
58+
"S",
59+
"SLF",
60+
"SLOT",
61+
"TC",
62+
"TD",
63+
"TRY0",
64+
"UP038",
65+
]
66+
lint.pydocstyle.convention = "google"

reflex_ui/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
_SUBMOD_ATTRS = {
1212
**_REFLEX_UI_MAPPING,
1313
"components": ["base"],
14-
"components.icons.hugeicon": ["hi"],
15-
"components.icons.icon": ["icon"],
14+
"components.icons.hugeicon": ["hi", "icon"],
15+
"components.icons.others": ["spinner"],
1616
"utils.twmerge": ["cn"],
1717
}
1818

reflex_ui/components/base/avatar.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010

1111
class ClassNames:
12+
"""Class names for avatar components."""
13+
1214
ROOT = "shrink-0 inline-flex size-6 items-center justify-center overflow-hidden rounded-full bg-secondary-1 align-middle text-base font-medium text-secondary-12 select-none"
1315
IMAGE = "size-full object-cover shrink-0"
1416
FALLBACK = "flex size-full items-center justify-center text-sm animate-pulse bg-secondary-6"
@@ -21,6 +23,7 @@ class AvatarBaseComponent(BaseUIComponent):
2123

2224
@property
2325
def import_var(self):
26+
"""Return the import variable for the avatar component."""
2427
return ImportVar(tag="Avatar", package_path="", install=False)
2528

2629

reflex_ui/components/base/button.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from reflex.vars import Var
88

99
from reflex_ui.components.component import CoreComponent
10-
from reflex_ui.components.icons.icon import spinner
10+
from reflex_ui.components.icons.others import spinner
1111

1212
LiteralButtonVariant = Literal[
1313
"primary", "destructive", "outline", "secondary", "ghost", "link", "dark"
@@ -82,17 +82,21 @@ def create(cls, *children, **props) -> BaseButton:
8282

8383
@staticmethod
8484
def validate_variant(variant: LiteralButtonVariant):
85+
"""Validate the button variant."""
8586
if variant not in BUTTON_VARIANTS["variant"]:
86-
raise ValueError(
87-
f"Invalid variant: {variant}. Available variants: {', '.join(BUTTON_VARIANTS['variant'].keys())}"
87+
available_variants = ", ".join(BUTTON_VARIANTS["variant"].keys())
88+
message = (
89+
f"Invalid variant: {variant}. Available variants: {available_variants}"
8890
)
91+
raise ValueError(message)
8992

9093
@staticmethod
9194
def validate_size(size: LiteralButtonSize):
95+
"""Validate the button size."""
9296
if size not in BUTTON_VARIANTS["size"]:
93-
raise ValueError(
94-
f"Invalid size: {size}. Available sizes: {', '.join(BUTTON_VARIANTS['size'].keys())}"
95-
)
97+
available_sizes = ", ".join(BUTTON_VARIANTS["size"].keys())
98+
message = f"Invalid size: {size}. Available sizes: {available_sizes}"
99+
raise ValueError(message)
96100

97101
def _exclude_props(self) -> list[str]:
98102
return [

reflex_ui/components/component.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Core component for all components"""
1+
"""Core component for all components."""
22

33
from typing import Any
44

@@ -21,6 +21,7 @@ def set_class_name(cls, default_class_name: str, props: dict[str, Any]) -> None:
2121
Args:
2222
props: The component props dictionary
2323
default_class_name: The default class name to use
24+
2425
"""
2526
if "render_" in props:
2627
return
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""Icons sub-package."""
2+
3+
from reflex.utils import lazy_loader
4+
5+
_SUBMODULES: set[str] = {
6+
"hugeicon",
7+
"others",
8+
}
9+
10+
_SUBMOD_ATTRS: dict[str, list[str]] = {
11+
"hugeicon": ["hi", "icon"],
12+
"others": ["spinner"],
13+
}
14+
15+
__getattr__, __dir__, __all__ = lazy_loader.attach(
16+
__name__,
17+
submodules=_SUBMODULES,
18+
submod_attrs=_SUBMOD_ATTRS,
19+
)

reflex_ui/components/icons/hugeicon.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def create(cls, *children, **props) -> Component:
3939
4040
Returns:
4141
The created component.
42+
4243
"""
4344
if children and isinstance(children[0], str) and "icon" not in props:
4445
props["icon"] = children[0]
@@ -58,4 +59,4 @@ def create(cls, *children, **props) -> Component:
5859
return super().create(*children, **props)
5960

6061

61-
hi = HugeIcon.create
62+
hi = icon = HugeIcon.create
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
def spinner_component(
1212
class_name: str | Var[str] = "",
1313
) -> Component:
14-
"""A spinner SVG icon.
14+
"""Create a spinner SVG icon.
1515
1616
Args:
1717
class_name: The class name of the spinner.
1818
1919
Returns:
2020
The spinner SVG icon.
21+
2122
"""
2223
return svg(
2324
svg.path(

reflex_ui/utils/twmerge.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def cn(
1515
1616
Returns:
1717
Var: A Var representing the merged classes string.
18+
1819
"""
1920
return (
2021
Var(

0 commit comments

Comments
 (0)