Skip to content

Commit ca2247c

Browse files
authored
improve build performance (#1652)
1 parent 0064465 commit ca2247c

File tree

4 files changed

+112
-86
lines changed

4 files changed

+112
-86
lines changed

pcweb/flexdown.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,11 @@ def markdown(text):
646646
return xd.get_default_block().render_fn(content=text)
647647

648648

649+
def markdown_codeblock(value: str, **props: object) -> rx.Component:
650+
"""Render a code block using the Shiki-based code block component."""
651+
return rx._x.code_block(value, **props)
652+
653+
649654
def markdown_with_shiki(*args, **kwargs):
650655
"""
651656
Wrapper for the markdown component with a customized component map.
@@ -657,8 +662,6 @@ def markdown_with_shiki(*args, **kwargs):
657662
"""
658663
return rx.markdown(
659664
*args,
660-
component_map={
661-
"codeblock": lambda value, **props: rx._x.code_block(value, **props)
662-
},
665+
component_map={"codeblock": markdown_codeblock},
663666
**kwargs,
664667
)

pcweb/templates/docpage/blocks/demo.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
"""Components for rendering code demos in the documentation."""
22

3-
import reflex as rx
43
import textwrap
54
from typing import Any
5+
6+
import reflex as rx
7+
import ruff_api
8+
69
from .code import code_block, code_block_dark
7-
import black
810

911

1012
def docdemobox(*children, **props) -> rx.Component:
@@ -42,14 +44,12 @@ def doccode(
4244
"""
4345
# For Python snippets, lint the code with black.
4446
if language == "python":
45-
code = black.format_str(
46-
textwrap.dedent(code), mode=black.FileMode(line_length=60)
47-
).strip()
47+
code = ruff_api.format_string(path="", source=textwrap.dedent(code)).strip()
4848

4949
# If needed, only display a subset of the lines.
5050
if lines is not None:
5151
code = textwrap.dedent(
52-
"\n".join(code.strip().split("\n")[lines[0] : lines[1]])
52+
"\n".join(code.strip().splitlines()[lines[0] : lines[1]])
5353
).strip()
5454

5555
# Create the code snippet.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ readme = "README.md"
99
requires-python = ">=3.11"
1010
dependencies = [
1111
"email-validator==2.2.0",
12-
"black>=25.0",
1312
"pandas>=1.5.3",
1413
"psycopg[binary]==3.2.9",
1514
"plotly-express==0.4.1",
@@ -28,7 +27,8 @@ dependencies = [
2827
"typesense>=1.1.1",
2928
"fastapi",
3029
"reflex-hosting-cli>=0.1.56",
31-
"python-frontmatter>=1.1.0"
30+
"python-frontmatter>=1.1.0",
31+
"ruff-api>=0.1.0",
3232
]
3333

3434
[dependency-groups]

0 commit comments

Comments
 (0)