Skip to content

Commit 518fc05

Browse files
jcheng5wch
andauthored
Force UTF-8 for Shiny Express on Windows (#1203)
Co-authored-by: Winston Chang <winston@posit.co>
1 parent 037b6f8 commit 518fc05

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
### Bug fixes
1717

18+
* On Windows, Shiny Express app files are now read in as UTF-8. (#1203)
19+
1820
### Other changes
1921

2022
## [0.8.1] - 2024-03-06

shiny/_custom_component_template_questions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def update_names_in_files(dir: Path):
138138
for item in dir.iterdir():
139139
if item.is_file():
140140
# Only do this for files
141-
with open(item, "r") as f:
141+
with open(item, "r", encoding="utf-8") as f:
142142
file_contents = f.read()
143143
# First, "custom_component" -> "new_component_name"
144144
file_contents = file_contents.replace(
@@ -151,7 +151,7 @@ def update_names_in_files(dir: Path):
151151
old_capital_case_name, capital_case_name
152152
)
153153

154-
with open(item, "w") as f:
154+
with open(item, "w", encoding="utf-8") as f:
155155
f.write(file_contents)
156156

157157
# Loop over dirs_to_update and run the update function on them

shiny/_docstring.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class DocStringWithExample(str): ...
6161
class ExampleWriter:
6262
def write_example(self, app_files: list[str]) -> str:
6363
app_file = app_files[0]
64-
with open(app_file) as f:
64+
with open(app_file, encoding="utf-8") as f:
6565
code = f.read()
6666

6767
return f"```.python\n{code.strip()}\n```\n"
@@ -209,7 +209,7 @@ def is_express_app(app_path: str) -> bool:
209209
if not os.path.exists(app_path):
210210
return False
211211

212-
with open(app_path) as f:
212+
with open(app_path, encoding="utf-8") as f:
213213
for line in f:
214214
if "from shiny.express" in line:
215215
return True

shiny/express/_run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def express_server(input: Inputs, output: Outputs, session: Session):
9191

9292

9393
def run_express(file: Path) -> Tag | TagList:
94-
with open(file) as f:
94+
with open(file, encoding="utf-8") as f:
9595
content = f.read()
9696

9797
tree = ast.parse(content, file)

shiny/quarto.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ def convert_code_cells_to_app_py(json_file: str | Path, app_file: str | Path) ->
3636
app_file = Path(app_file)
3737

3838
if app_file.exists():
39-
with open(app_file, "r") as f:
39+
with open(app_file, "r", encoding="utf-8") as f:
4040
first_line = f.readline().strip()
4141
if first_line != "# This file generated by Quarto; do not edit by hand.":
4242
raise ValueError(
4343
f"Not overwriting app file {app_file}, because it does not appear to be generated by Quarto. "
4444
" If this is incorrect, remove the file and try again."
4545
)
4646

47-
with open(json_file, "r") as f:
47+
with open(json_file, "r", encoding="utf-8") as f:
4848
data = cast(QuartoShinyCodeCells, json.load(f))
4949

5050
if data["schema_version"] != 1:
@@ -93,7 +93,7 @@ def server(input: Inputs, output: Outputs, session: Session) -> None:
9393
)
9494
"""
9595

96-
with open(app_file, "w") as f:
96+
with open(app_file, "w", encoding="utf-8") as f:
9797
f.write(app_content)
9898

9999

0 commit comments

Comments
 (0)