Skip to content

Commit bdc2ee7

Browse files
authored
site requires internal components to build pyi (#6362)
* site requires internal components to build pyi * add more explicit dependencies * add field to raise if failed imports * proof of concept works, add pyyaml and sort those deps
1 parent 7c1e017 commit bdc2ee7

4 files changed

Lines changed: 34 additions & 6 deletions

File tree

.github/workflows/build_packages.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,5 @@ jobs:
4949
run-uv-sync: false
5050
- name: Build ${{ matrix.name }}
5151
run: uv build --directory "${{ matrix.dir }}"
52+
env:
53+
PYI_GENERATOR_RAISE_FAILED_IMPORTS: "1"

packages/reflex-base/src/reflex_base/utils/pyi_generator.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import json
1010
import logging
1111
import multiprocessing
12+
import os
1213
import re
1314
import subprocess
1415
import sys
@@ -25,6 +26,7 @@
2526
from typing import Any, ClassVar, get_args, get_origin
2627

2728
from reflex_base.components.component import DEFAULT_TRIGGERS_AND_DESC, Component
29+
from reflex_base.environment import interpret_boolean_env
2830
from reflex_base.vars.base import Var
2931

3032

@@ -1621,6 +1623,15 @@ def _scan_files(self, files: list[Path]):
16211623
self.written_files.append(result)
16221624
return
16231625

1626+
raise_on_failed_imports_key = "PYI_GENERATOR_RAISE_FAILED_IMPORTS"
1627+
raise_on_failed_imports = os.getenv(raise_on_failed_imports_key)
1628+
1629+
raise_if_failed_imports = (
1630+
interpret_boolean_env(raise_on_failed_imports, raise_on_failed_imports_key)
1631+
if raise_on_failed_imports is not None
1632+
else False
1633+
)
1634+
16241635
# Pre-import all modules sequentially to populate sys.modules
16251636
# so forked workers inherit the cache and skip redundant imports.
16261637
importable_files: list[Path] = []
@@ -1631,6 +1642,8 @@ def _scan_files(self, files: list[Path]):
16311642
importable_files.append(file)
16321643
except Exception:
16331644
logger.exception(f"Failed to import {module_import}")
1645+
if raise_if_failed_imports:
1646+
raise
16341647

16351648
# Generate stubs in parallel using forked worker processes.
16361649
ctx = multiprocessing.get_context("fork")

packages/reflex-site-shared/pyproject.toml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ readme = "README.md"
66
authors = [{ name = "Khaleel Al-Adhami", email = "khaleel@reflex.dev" }]
77
maintainers = [{ name = "Khaleel Al-Adhami", email = "khaleel@reflex.dev" }]
88
requires-python = ">=3.10"
9-
dependencies = ["reflex"]
9+
dependencies = [
10+
"email-validator",
11+
"httpx",
12+
"pyyaml",
13+
"reflex-components-internal",
14+
"reflex",
15+
"ruff-format",
16+
]
1017

1118

1219
[tool.hatch.version]
@@ -22,13 +29,15 @@ targets.wheel.artifacts = ["*.pyi"]
2229

2330
[tool.hatch.build.hooks.reflex-pyi]
2431
dependencies = [
25-
"ruff",
26-
"reflex",
32+
"email-validator",
33+
"httpx",
34+
"pyyaml",
2735
"reflex-base",
2836
"reflex-components-code",
2937
"reflex-components-core",
3038
"reflex-components-dataeditor",
3139
"reflex-components-gridjs",
40+
"reflex-components-internal",
3241
"reflex-components-lucide",
3342
"reflex-components-markdown",
3443
"reflex-components-moment",
@@ -37,9 +46,9 @@ dependencies = [
3746
"reflex-components-react-player",
3847
"reflex-components-recharts",
3948
"reflex-components-sonner",
40-
"httpx",
41-
"email-validator",
49+
"reflex",
4250
"ruff-format",
51+
"ruff",
4352
]
4453

4554
[build-system]

uv.lock

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)