Skip to content

Commit d8d0fd2

Browse files
committed
Rename reactpy.web.export
1 parent 1455f70 commit d8d0fd2

File tree

5 files changed

+60
-18
lines changed

5 files changed

+60
-18
lines changed

src/build_scripts/copy_dir.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# dependencies = []
44
# ///
55

6-
# ruff: noqa: INP001
76
import logging
87
import shutil
98
import sys

src/reactpy/web/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from reactpy.web.module import (
22
export,
3+
import_components,
34
module_from_file,
45
module_from_string,
56
module_from_url,
67
)
78

89
__all__ = [
910
"export",
11+
"import_components",
1012
"module_from_file",
1113
"module_from_string",
1214
"module_from_url",

src/reactpy/web/module.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pathlib import Path
88
from typing import Any, NewType, overload
99

10+
from reactpy._warnings import warn
1011
from reactpy.config import REACTPY_DEBUG, REACTPY_WEB_MODULES_DIR
1112
from reactpy.core.vdom import Vdom
1213
from reactpy.types import ImportSourceDict, VdomConstructor
@@ -222,7 +223,7 @@ class WebModule:
222223

223224

224225
@overload
225-
def export(
226+
def import_components(
226227
web_module: WebModule,
227228
export_names: str,
228229
fallback: Any | None = ...,
@@ -231,15 +232,15 @@ def export(
231232

232233

233234
@overload
234-
def export(
235+
def import_components(
235236
web_module: WebModule,
236237
export_names: list[str] | tuple[str, ...],
237238
fallback: Any | None = ...,
238239
allow_children: bool = ...,
239240
) -> list[VdomConstructor]: ...
240241

241242

242-
def export(
243+
def import_components(
243244
web_module: WebModule,
244245
export_names: str | list[str] | tuple[str, ...],
245246
fallback: Any | None = None,
@@ -281,6 +282,38 @@ def export(
281282
]
282283

283284

285+
@overload
286+
def export(
287+
web_module: WebModule,
288+
export_names: str,
289+
fallback: Any | None = ...,
290+
allow_children: bool = ...,
291+
) -> VdomConstructor: ...
292+
293+
294+
@overload
295+
def export(
296+
web_module: WebModule,
297+
export_names: list[str] | tuple[str, ...],
298+
fallback: Any | None = ...,
299+
allow_children: bool = ...,
300+
) -> list[VdomConstructor]: ...
301+
302+
303+
def export(
304+
web_module: WebModule,
305+
export_names: str | list[str] | tuple[str, ...],
306+
fallback: Any | None = None,
307+
allow_children: bool = True,
308+
) -> VdomConstructor | list[VdomConstructor]:
309+
warn(
310+
"The 'export' function is deprecated and will be removed in a future release. "
311+
"Use 'import_components' instead.",
312+
DeprecationWarning,
313+
)
314+
return import_components(web_module, export_names, fallback, allow_children)
315+
316+
284317
def _make_export(
285318
web_module: WebModule,
286319
name: str,

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def pytest_addoption(parser: Parser) -> None:
3636

3737
@pytest.fixture(autouse=True, scope="session")
3838
def install_playwright():
39-
subprocess.run(["playwright", "install", "chromium"], check=True) # noqa: S607, S603
40-
subprocess.run(["playwright", "install-deps"], check=True) # noqa: S607, S603
39+
subprocess.run(["playwright", "install", "chromium"], check=True) # noqa: S607
40+
subprocess.run(["playwright", "install-deps"], check=True) # noqa: S607
4141

4242

4343
@pytest.fixture(autouse=True, scope="session")
@@ -49,7 +49,7 @@ def rebuild():
4949
# passed to the subprocess.
5050
env = os.environ.copy()
5151
env.pop("HATCH_ENV_ACTIVE", None)
52-
subprocess.run(["hatch", "build", "-t", "wheel"], check=True, env=env) # noqa: S607, S603
52+
subprocess.run(["hatch", "build", "-t", "wheel"], check=True, env=env) # noqa: S607
5353

5454

5555
@pytest.fixture(autouse=True, scope="function")

tests/test_web/test_module.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
async def test_that_js_module_unmount_is_called(display: DisplayFixture):
22-
SomeComponent = reactpy.web.export(
22+
SomeComponent = reactpy.web.import_components(
2323
reactpy.web.module_from_file(
2424
"set-flag-when-unmount-is-called",
2525
JS_FIXTURES_DIR / "set-flag-when-unmount-is-called.js",
@@ -52,7 +52,7 @@ def ShowCurrentComponent():
5252

5353

5454
async def test_module_from_url(browser):
55-
SimpleButton = reactpy.web.export(
55+
SimpleButton = reactpy.web.import_components(
5656
reactpy.web.module_from_url("/static/simple-button.js", resolve_exports=False),
5757
"SimpleButton",
5858
)
@@ -72,7 +72,7 @@ def ShowSimpleButton():
7272

7373

7474
async def test_module_from_file(display: DisplayFixture):
75-
SimpleButton = reactpy.web.export(
75+
SimpleButton = reactpy.web.import_components(
7676
reactpy.web.module_from_file(
7777
"simple-button", JS_FIXTURES_DIR / "simple-button.js"
7878
),
@@ -163,14 +163,14 @@ def test_module_missing_exports():
163163
module = WebModule("test", NAME_SOURCE, None, {"a", "b", "c"}, None, False)
164164

165165
with pytest.raises(ValueError, match="does not export 'x'"):
166-
reactpy.web.export(module, "x")
166+
reactpy.web.import_components(module, "x")
167167

168168
with pytest.raises(ValueError, match=r"does not export \['x', 'y'\]"):
169-
reactpy.web.export(module, ["x", "y"])
169+
reactpy.web.import_components(module, ["x", "y"])
170170

171171

172172
async def test_module_exports_multiple_components(display: DisplayFixture):
173-
Header1, Header2 = reactpy.web.export(
173+
Header1, Header2 = reactpy.web.import_components(
174174
reactpy.web.module_from_file(
175175
"exports-two-components", JS_FIXTURES_DIR / "exports-two-components.js"
176176
),
@@ -190,7 +190,7 @@ async def test_imported_components_can_render_children(display: DisplayFixture):
190190
module = reactpy.web.module_from_file(
191191
"component-can-have-child", JS_FIXTURES_DIR / "component-can-have-child.js"
192192
)
193-
Parent, Child = reactpy.web.export(module, ["Parent", "Child"])
193+
Parent, Child = reactpy.web.import_components(module, ["Parent", "Child"])
194194

195195
await display.show(
196196
lambda: Parent(
@@ -222,7 +222,7 @@ async def test_keys_properly_propagated(display: DisplayFixture):
222222
module = reactpy.web.module_from_file(
223223
"keys-properly-propagated", JS_FIXTURES_DIR / "keys-properly-propagated.js"
224224
)
225-
GridLayout = reactpy.web.export(module, "GridLayout")
225+
GridLayout = reactpy.web.import_components(module, "GridLayout")
226226

227227
await display.show(
228228
lambda: GridLayout(
@@ -277,7 +277,7 @@ async def test_subcomponent_notation_as_str_attrs(display: DisplayFixture):
277277
"subcomponent-notation",
278278
JS_FIXTURES_DIR / "subcomponent-notation.js",
279279
)
280-
InputGroup, InputGroupText, FormControl, FormLabel = reactpy.web.export(
280+
InputGroup, InputGroupText, FormControl, FormLabel = reactpy.web.import_components(
281281
module, ["InputGroup", "InputGroup.Text", "Form.Control", "Form.Label"]
282282
)
283283

@@ -337,7 +337,7 @@ async def test_subcomponent_notation_as_obj_attrs(display: DisplayFixture):
337337
"subcomponent-notation",
338338
JS_FIXTURES_DIR / "subcomponent-notation.js",
339339
)
340-
InputGroup, Form = reactpy.web.export(module, ["InputGroup", "Form"])
340+
InputGroup, Form = reactpy.web.import_components(module, ["InputGroup", "Form"])
341341

342342
content = reactpy.html.div(
343343
{"id": "the-parent"},
@@ -394,7 +394,7 @@ async def test_callable_prop_with_javacript(display: DisplayFixture):
394394
module = reactpy.web.module_from_file(
395395
"callable-prop", JS_FIXTURES_DIR / "callable-prop.js"
396396
)
397-
Component = reactpy.web.export(module, "Component")
397+
Component = reactpy.web.import_components(module, "Component")
398398

399399
@reactpy.component
400400
def App():
@@ -415,3 +415,11 @@ def test_module_from_string():
415415
reactpy.web.module_from_string("temp", "old")
416416
with assert_reactpy_did_log(r"Existing web module .* will be replaced with"):
417417
reactpy.web.module_from_string("temp", "new")
418+
419+
420+
def test_deprecated_export():
421+
module = reactpy.web.module_from_string(
422+
"temp", "export function Component() { return 'hello' }"
423+
)
424+
with pytest.warns(DeprecationWarning, match="The 'export' function is deprecated"):
425+
reactpy.web.export(module, "Component")

0 commit comments

Comments
 (0)