diff --git a/docs/source/about/changelog.rst b/docs/source/about/changelog.rst index bc8e164b4..b2297c20c 100644 --- a/docs/source/about/changelog.rst +++ b/docs/source/about/changelog.rst @@ -22,6 +22,7 @@ Unreleased - :pull:`1118` - `module_from_template` is broken with a recent release of `requests` - :pull:`1131` - `module_from_template` did not work when using Flask backend +- :pull:`1200` - Fixed `UnicodeDecodeError` when using `reactpy.web.export` **Added** diff --git a/src/py/reactpy/reactpy/_console/rewrite_camel_case_props.py b/src/py/reactpy/reactpy/_console/rewrite_camel_case_props.py index e5d1860c2..d706adecf 100644 --- a/src/py/reactpy/reactpy/_console/rewrite_camel_case_props.py +++ b/src/py/reactpy/reactpy/_console/rewrite_camel_case_props.py @@ -29,7 +29,7 @@ def rewrite_camel_case_props(paths: list[str]) -> None: for p in map(Path, paths): for f in [p] if p.is_file() else p.rglob("*.py"): - result = generate_rewrite(file=f, source=f.read_text()) + result = generate_rewrite(file=f, source=f.read_text(encoding="utf-8")) if result is not None: f.write_text(result) diff --git a/src/py/reactpy/reactpy/_console/rewrite_keys.py b/src/py/reactpy/reactpy/_console/rewrite_keys.py index 64ed42f33..08db9e227 100644 --- a/src/py/reactpy/reactpy/_console/rewrite_keys.py +++ b/src/py/reactpy/reactpy/_console/rewrite_keys.py @@ -51,7 +51,7 @@ def rewrite_keys(paths: list[str]) -> None: for p in map(Path, paths): for f in [p] if p.is_file() else p.rglob("*.py"): - result = generate_rewrite(file=f, source=f.read_text()) + result = generate_rewrite(file=f, source=f.read_text(encoding="utf-8")) if result is not None: f.write_text(result) diff --git a/src/py/reactpy/reactpy/web/module.py b/src/py/reactpy/reactpy/web/module.py index c3192da4e..e1a5db82f 100644 --- a/src/py/reactpy/reactpy/web/module.py +++ b/src/py/reactpy/reactpy/web/module.py @@ -145,7 +145,7 @@ def module_from_template( raise ValueError(msg) variables = {"PACKAGE": package, "CDN": cdn, "VERSION": template_version} - content = Template(template_file.read_text()).substitute(variables) + content = Template(template_file.read_text(encoding="utf-8")).substitute(variables) return module_from_string( _FROM_TEMPLATE_DIR + "/" + package_name, @@ -270,7 +270,7 @@ def module_from_string( target_file = _web_module_path(name) - if target_file.exists() and target_file.read_text() != content: + if target_file.exists() and target_file.read_text(encoding="utf-8") != content: logger.info( f"Existing web module {name!r} will " f"be replaced with {target_file.resolve()}" diff --git a/src/py/reactpy/reactpy/web/utils.py b/src/py/reactpy/reactpy/web/utils.py index 295559496..338fa504a 100644 --- a/src/py/reactpy/reactpy/web/utils.py +++ b/src/py/reactpy/reactpy/web/utils.py @@ -29,7 +29,7 @@ def resolve_module_exports_from_file( return set() export_names, references = resolve_module_exports_from_source( - file.read_text(), exclude_default=is_re_export + file.read_text(encoding="utf-8"), exclude_default=is_re_export ) for ref in references: