Skip to content

Commit cb07a55

Browse files
authored
regenerate pyi files and bring chakra to full 0.8.0 compat (#42)
* regenerate pyi files and bring chakra to full 0.8.0 compat * add ruff ci * run pyright * add working dir * do it through extra args * run pyi again and uv lock * ignore that file * add check for pyi files * use 3.13 for check pyi * basically do DCE * make override a warning * disable check pyi and use better pyi generatio * make the headings work * huh * enable pyi in ci
1 parent d3bf1c1 commit cb07a55

File tree

155 files changed

+9601
-12392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+9601
-12392
lines changed

.github/workflows/ci.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: ci
2+
env:
3+
OPENAI_API_KEY: "dummy"
4+
on:
5+
push:
6+
branches: [main]
7+
pull_request:
8+
branches: [main]
9+
10+
jobs:
11+
type-check:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: Install UV
16+
uses: astral-sh/setup-uv@v6
17+
with:
18+
python-version: "3.10"
19+
enable-cache: true
20+
activate-environment: true
21+
- name: Install dependencies
22+
run: uv sync
23+
- name: Run Type Checking
24+
uses: jakebailey/pyright-action@v2
25+
with:
26+
extra-args: reflex_chakra
27+
version: PATH
28+
lint:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
- name: Install UV
33+
uses: astral-sh/setup-uv@v6
34+
with:
35+
python-version: "3.10"
36+
enable-cache: true
37+
activate-environment: true
38+
- name: Install dependencies
39+
run: uv sync
40+
- name: Run Ruff Linter
41+
run: ruff check --output-format=github reflex_chakra
42+
- name: Run Ruff Formatter
43+
run: ruff format --check --diff reflex_chakra
44+
check-pyi:
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v4
48+
- name: Install UV
49+
uses: astral-sh/setup-uv@v6
50+
with:
51+
python-version: "3.13"
52+
enable-cache: true
53+
activate-environment: true
54+
- name: Install dependencies
55+
run: uv sync
56+
- name: Run PYI generation
57+
run: python regenerate_pyi.py
58+
- name: Check if there are any changes
59+
run: git diff --exit-code -- "*.pyi" || (echo "PYI files have changed. Please commit the changes." && exit 1)
60+
check-export:
61+
runs-on: ubuntu-latest
62+
steps:
63+
- uses: actions/checkout@v4
64+
- name: Install UV
65+
uses: astral-sh/setup-uv@v6
66+
with:
67+
python-version: "3.10"
68+
enable-cache: true
69+
activate-environment: true
70+
- name: Install Reflex
71+
working-directory: ./docs/rcweb
72+
run: uv pip install $(grep -ivE "reflex-chakra" requirements.txt)
73+
74+
- name: Initialize Reflex
75+
working-directory: ./docs/rcweb
76+
run: uv run reflex init
77+
78+
- name: Build frontend
79+
working-directory: ./docs/rcweb
80+
run: uv run reflex export

.github/workflows/export_docs.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,5 @@ cython_debug/
160160
# and can be added to the global gitignore or merged into this file. For a more nuclear
161161
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
162162
#.idea/
163+
164+
assets/chakra_color_mode_provider.js

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

docs/rcweb/rcweb/constants/css.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
"""App styling."""
22

33
import reflex as rx
4-
from . import fonts
4+
55
import reflex_chakra as rc
66

7+
from . import fonts
8+
79
font_weights = {
810
"bold": "800",
911
"heading": "700",
@@ -40,23 +42,6 @@ def get_code_style_rdx(color: str):
4042
"line_height": "1.5",
4143
}
4244

43-
tab_style = {
44-
"color": rx.color("slate", 9),
45-
"cursor": "pointer",
46-
"_hover": {
47-
"color": rx.color("slate", 11),
48-
},
49-
**fonts.small,
50-
"padding_x": "0.5em",
51-
"padding_y": "0.25em",
52-
"&[data-state='active']": {
53-
"color": rx.color("violet", 9),
54-
},
55-
"not:&[data-state='active']": {
56-
"color": rx.color("slate", 11),
57-
},
58-
}
59-
6045

6146
# General styles.
6247
SANS = "Instrument Sans"

docs/rcweb/rcweb/rcweb.py

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,19 @@
11
"""Welcome to Reflex! This file outlines the steps to create a basic app."""
22

33
import os
4-
from pathlib import Path
54
from collections import defaultdict
5+
from pathlib import Path
66
from types import SimpleNamespace
77

8-
import reflex as rx
9-
import reflex_chakra as rc
108
import flexdown
9+
import reflex as rx
10+
from reflex.utils.format import to_kebab_case, to_snake_case
1111

12-
from .utils.flexdown import xd
13-
from .utils.docpage import multi_docs
14-
from .constants import css
15-
16-
17-
def should_skip_compile(doc: flexdown.Document):
18-
"""Skip compilation if the markdown file has not been modified since the last compilation."""
19-
if not os.environ.get("REFLEX_PERSIST_WEB_DIR", False):
20-
return False
12+
import reflex_chakra as rc # noqa: F401
2113

22-
# Check if the doc has been compiled already.
23-
compiled_output = f".web/pages/{doc.replace('.md', '.js')}"
24-
# Get the timestamp of the compiled file.
25-
compiled_time = (
26-
os.path.getmtime(compiled_output) if os.path.exists(compiled_output) else 0
27-
)
28-
# Get the timestamp of the source file.
29-
source_time = os.path.getmtime(doc)
30-
return compiled_time > source_time
14+
from .constants import css
15+
from .utils.docpage import Route, multi_docs
16+
from .utils.flexdown import xd
3117

3218

3319
def find_flexdown_files(directory: str) -> list[str]:
@@ -40,14 +26,16 @@ def find_flexdown_files(directory: str) -> list[str]:
4026
A list of paths to Flexdown files.
4127
"""
4228
return [
43-
os.path.join(root, file).replace("\\", "/")
29+
(Path(root) / file).as_posix()
4430
for root, _, files in os.walk(directory)
4531
for file in files
4632
if file.endswith(".md")
4733
]
4834

4935

50-
def extract_components_from_metadata(document) -> list:
36+
def extract_components_from_metadata(
37+
document: flexdown.Document,
38+
) -> list[tuple[type, str]]:
5139
"""Extract components from the document metadata.
5240
5341
Args:
@@ -56,14 +44,14 @@ def extract_components_from_metadata(document) -> list:
5644
Returns:
5745
A list of tuples containing component instances and their string representation.
5846
"""
59-
components = []
47+
components: list[tuple[type, str]] = []
6048
for comp_str in document.metadata.get("components", []):
6149
component = eval(comp_str)
6250
if isinstance(component, type):
6351
components.append((component, comp_str))
6452
elif hasattr(component, "__self__"):
6553
components.append((component.__self__, comp_str))
66-
elif isinstance(component, SimpleNamespace) and hasattr(component, "__call__"):
54+
elif isinstance(component, SimpleNamespace) and hasattr(component, "__call__"): # noqa: B004
6755
components.append((component.__call__.__self__, comp_str))
6856
return components
6957

@@ -99,8 +87,10 @@ def convert_to_title_case(text: str) -> str:
9987

10088

10189
def create_doc_component(
102-
doc_path: str, base_dir: str, component_registry: defaultdict
103-
) -> rx.Component:
90+
doc_path: str,
91+
base_dir: str,
92+
component_registry: defaultdict[str, list[tuple[str, list[tuple[type, str]]]]],
93+
) -> Route:
10494
"""Create a document component for a given file path.
10595
10696
Args:
@@ -112,13 +102,14 @@ def create_doc_component(
112102
A component object representing the document page.
113103
"""
114104
doc_path = doc_path.replace("\\", "/")
115-
route_path = rx.utils.format.to_kebab_case(
105+
doc_path_path = Path(doc_path)
106+
route_path = to_kebab_case(
116107
f"/{doc_path.removeprefix(base_dir).replace('.md', '/')}"
117108
).replace("//", "/")
118-
category = os.path.basename(os.path.dirname(doc_path)).title()
109+
category = doc_path_path.parent.name.title()
119110
document = flexdown.parse_file(doc_path)
120-
title = rx.utils.format.to_snake_case(os.path.basename(doc_path).replace(".md", ""))
121-
component_list = [title, *extract_components_from_metadata(document)]
111+
title = to_snake_case(doc_path_path.name.replace(".md", ""))
112+
component_list = (title, extract_components_from_metadata(document))
122113
component_registry[category].append(component_list)
123114
return multi_docs(
124115
path=route_path,
@@ -129,7 +120,7 @@ def create_doc_component(
129120
)
130121

131122

132-
def generate_document_routes(doc_paths: list[str], base_dir: str) -> list[rx.Component]:
123+
def generate_document_routes(doc_paths: list[str], base_dir: str) -> list[Route]:
133124
"""Generate document components and routes from Flexdown file paths.
134125
135126
Args:
@@ -146,9 +137,7 @@ def generate_document_routes(doc_paths: list[str], base_dir: str) -> list[rx.Com
146137
]
147138

148139

149-
def setup_application_routes(
150-
app: rx.App, doc_routes: list[rx.Component], base_path: str
151-
):
140+
def setup_application_routes(app: rx.App, doc_routes: list[Route], base_path: str):
152141
"""Set up application routes based on document components.
153142
154143
Args:

docs/rcweb/rcweb/utils/blocks/code.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Code block components for documentation pages."""
22

33
import reflex as rx
4-
from ...constants import css, fonts
4+
5+
from rcweb.constants import css, fonts
56

67

78
@rx.memo
@@ -20,8 +21,6 @@ def code_block(code: str, language: str):
2021
padding="20px",
2122
style=fonts.code,
2223
margin="0",
23-
# TODO: use this when it's looking good
24-
# can_copy=True,
2524
),
2625
rx.button(
2726
rx.icon(
@@ -76,8 +75,6 @@ def code_block_dark(code: str, language: str):
7675
},
7776
padding="20px",
7877
margin="0",
79-
# TODO: use this when it's looking good
80-
# can_copy=True,
8178
),
8279
rx.button(
8380
rx.icon(

docs/rcweb/rcweb/utils/blocks/headings.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Template for documentation pages."""
22

33
import reflex as rx
4-
from ...constants import css, fonts
4+
5+
from rcweb.constants import css, fonts
56

67
icon_margins = {
78
"h1": "10px",
@@ -12,20 +13,21 @@
1213

1314

1415
def h_comp_common(
15-
text: rx.Var[str],
16+
text: rx.Var[str] | rx.Var[list[str]],
1617
heading: str,
1718
font_size: list[str] | str = "",
1819
font_weight: str = "",
1920
scroll_margin: str = "",
2021
margin_top: str = "",
2122
margin_bottom: str = "",
2223
convert_to_str: bool = False,
23-
style: dict = {},
24+
style: dict | None = None,
2425
) -> rx.Component:
26+
style = style or {}
2527
if convert_to_str:
26-
id_ = text.to(list[str])[0].lower().split().join("-")
28+
id_ = text.to(list)[0].to(str).lower().split(" ").join("-")
2729
else:
28-
id_ = text.lower().split().join("-")
30+
id_ = text.to(str).lower().split(" ").join("-")
2931
href = rx.State.router.page.full_path + "#" + id_
3032

3133
return rx.box(
@@ -70,7 +72,6 @@ def h_comp_common(
7072
on_click=lambda: rx.set_clipboard(href),
7173
margin_bottom="0.5em",
7274
),
73-
# border_top=f"1px solid {rx.color('mauve', 3)}" if heading == "h2" else None,
7475
_hover={
7576
"color": rx.color("violet", 9),
7677
},
@@ -86,7 +87,6 @@ def h1_comp(text: rx.Var[str]) -> rx.Component:
8687
text=text,
8788
heading="h1",
8889
style={
89-
# "color": c_color("slate", 12),
9090
"font-size": ["32px", "48px"],
9191
"font-style": "normal",
9292
"font-weight": "600",
@@ -105,7 +105,6 @@ def h1_comp_xd(text: rx.Var[str]) -> rx.Component:
105105
heading="h1",
106106
style=fonts.xx_large,
107107
margin_bottom="24px",
108-
# margin_top="1.5em",
109108
scroll_margin="4em",
110109
convert_to_str=True,
111110
)

docs/rcweb/rcweb/utils/blocks/typography.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Typography blocks for doc pages."""
22

33
import reflex as rx
4-
from ...constants import fonts
4+
5+
from rcweb.constants import fonts
56

67

78
def definition(title: str, *children) -> rx.Component:

0 commit comments

Comments
 (0)