Skip to content

Commit bb63511

Browse files
committed
Remove module_from_template
1 parent df3c0f7 commit bb63511

File tree

4 files changed

+1
-91
lines changed

4 files changed

+1
-91
lines changed

src/reactpy/future.py

Whitespace-only changes.

src/reactpy/types.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Exports common types from:
22
33
- :mod:`reactpy.core.types`
4-
- :mod:`reactpy.backend.types`
54
"""
65

76
from reactpy.core.component import Component

src/reactpy/web/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
export,
33
module_from_file,
44
module_from_string,
5-
module_from_template,
65
module_from_url,
76
)
87

98
__all__ = [
9+
"export",
1010
"module_from_file",
1111
"module_from_string",
12-
"module_from_template",
1312
"module_from_url",
14-
"export",
1513
]

src/reactpy/web/module.py

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
import shutil
66
from dataclasses import dataclass
77
from pathlib import Path
8-
from string import Template
98
from typing import Any, NewType, overload
10-
from urllib.parse import urlparse
119

12-
from reactpy._warnings import warn
1310
from reactpy.config import REACTPY_DEBUG_MODE, REACTPY_WEB_MODULES_DIR
1411
from reactpy.core.types import ImportSourceDict, VdomDictConstructor
1512
from reactpy.core.vdom import make_vdom_constructor
@@ -73,90 +70,6 @@ def module_from_url(
7370
)
7471

7572

76-
_FROM_TEMPLATE_DIR = "__from_template__"
77-
78-
79-
def module_from_template(
80-
template: str,
81-
package: str,
82-
cdn: str = "https://esm.sh",
83-
fallback: Any | None = None,
84-
resolve_exports: bool | None = None,
85-
resolve_exports_depth: int = 5,
86-
unmount_before_update: bool = False,
87-
) -> WebModule:
88-
"""Create a :class:`WebModule` from a framework template
89-
90-
This is useful for experimenting with component libraries that do not already
91-
support ReactPy's :ref:`Custom Javascript Component` interface.
92-
93-
.. warning::
94-
95-
This approach is not recommended for use in a production setting because the
96-
framework templates may use unpinned dependencies that could change without
97-
warning. It's best to author a module adhering to the
98-
:ref:`Custom Javascript Component` interface instead.
99-
100-
**Templates**
101-
102-
- ``react``: for modules exporting React components
103-
104-
Parameters:
105-
template:
106-
The name of the framework template to use with the given ``package``.
107-
package:
108-
The name of a package to load. May include a file extension (defaults to
109-
``.js`` if not given)
110-
cdn:
111-
Where the package should be loaded from. The CDN must distribute ESM modules
112-
fallback:
113-
What to temporarily display while the module is being loaded.
114-
resolve_imports:
115-
Whether to try and find all the named exports of this module.
116-
resolve_exports_depth:
117-
How deeply to search for those exports.
118-
unmount_before_update:
119-
Cause the component to be unmounted before each update. This option should
120-
only be used if the imported package fails to re-render when props change.
121-
Using this option has negative performance consequences since all DOM
122-
elements must be changed on each render. See :issue:`461` for more info.
123-
"""
124-
warn(
125-
"module_from_template() is deprecated due to instability - use the Javascript "
126-
"Components API instead. This function will be removed in a future release.",
127-
DeprecationWarning,
128-
)
129-
template_name, _, template_version = template.partition("@")
130-
template_version = "@" + template_version if template_version else ""
131-
132-
# We do this since the package may be any valid URL path. Thus we may need to strip
133-
# object parameters or query information so we save the resulting template under the
134-
# correct file name.
135-
package_name = urlparse(package).path
136-
137-
# downstream code assumes no trailing slash
138-
cdn = cdn.rstrip("/")
139-
140-
template_file_name = template_name + module_name_suffix(package_name)
141-
142-
template_file = Path(__file__).parent / "templates" / template_file_name
143-
if not template_file.exists():
144-
msg = f"No template for {template_file_name!r} exists"
145-
raise ValueError(msg)
146-
147-
variables = {"PACKAGE": package, "CDN": cdn, "VERSION": template_version}
148-
content = Template(template_file.read_text(encoding="utf-8")).substitute(variables)
149-
150-
return module_from_string(
151-
_FROM_TEMPLATE_DIR + "/" + package_name,
152-
content,
153-
fallback,
154-
resolve_exports,
155-
resolve_exports_depth,
156-
unmount_before_update=unmount_before_update,
157-
)
158-
159-
16073
def module_from_file(
16174
name: str,
16275
file: str | Path,

0 commit comments

Comments
 (0)