Skip to content

Use utf-8 for reading files #1200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/about/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/py/reactpy/reactpy/_console/rewrite_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/py/reactpy/reactpy/web/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()}"
Expand Down
2 changes: 1 addition & 1 deletion src/py/reactpy/reactpy/web/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading