Skip to content

Commit

Permalink
Use utf-8 for reading files (#1200)
Browse files Browse the repository at this point in the history
  • Loading branch information
Archmonger authored Mar 6, 2024
1 parent 618e579 commit 3f05f81
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 5 deletions.
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

0 comments on commit 3f05f81

Please sign in to comment.