Skip to content

Commit

Permalink
fix: on windows, Path.read_text is not utf8 by default
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Jul 11, 2024
1 parent 1a28643 commit 681f69b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion solara/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ def markdown(target: typing.Optional[Path] = None):


def write_script(name: str, target: typing.Optional[Path]):
code = (HERE / "template" / f"{name}.py").read_text()
code = (HERE / "template" / f"{name}.py").read_text(encoding="utf-8")
if target is None:
target = Path("sol.py")
else:
Expand Down
6 changes: 2 additions & 4 deletions solara/autorouting.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,9 @@ def get_args(f):
solara.Button(
icon_name="mdi-pencil", icon=True, href=url, target="_blank", style={"position": "absolute", "top": "0px", "right": "0px"}
)
# solara.Markdown(path.read_text(), unsafe_solara_execute=True)
component(path.read_text(), unsafe_solara_execute=True)
component(path.read_text(encoding="utf-8"), unsafe_solara_execute=True)
else:
# content = solara.Markdown(path.read_text(), unsafe_solara_execute=True)
content = component(path.read_text(), unsafe_solara_execute=True)
content = component(path.read_text(encoding="utf-8"), unsafe_solara_execute=True)

main = solara.Div(
classes=["solara-autorouter-content"],
Expand Down
4 changes: 2 additions & 2 deletions solara/components/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def watch():
try:
async for _ in watchfiles.awatch(value):
print(value, "changed, reloading css") # noqa
set_css_content_reloaded(cast(Path, value).read_text())
set_css_content_reloaded(cast(Path, value).read_text(encoding="utf-8"))
except RuntimeError:
pass # swallow the RuntimeError: Already borrowed errors from watchfiles
except Exception:
Expand All @@ -70,7 +70,7 @@ async def watch():
if css_content_reloaded is not None:
css_content = css_content_reloaded
else:
css_content = value.read_text() if isinstance(value, Path) else value
css_content = value.read_text(encoding="utf-8") if isinstance(value, Path) else value
# del value
hash = hashlib.sha256(css_content.encode("utf-8")).hexdigest()
# the key is unique for this component + value
Expand Down
2 changes: 1 addition & 1 deletion solara/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def on_file_change(self, name):
path = Path(name)
if path.suffix == ".vue":
logger.info("Vue file changed: %s", name)
template_content = path.read_text()
template_content = path.read_text(encoding="utf-8")
for context in list(kernel_context.contexts.values()):
with context:
for filepath, widget in context.templates.items():
Expand Down

0 comments on commit 681f69b

Please sign in to comment.