Skip to content

Force UTF-8 for Shiny Express on Windows #1203

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 3 commits into from
Mar 13, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Bug fixes

* On Windows, Shiny Express app files are now read in as UTF-8. (#1203)

### Other changes

## [0.8.1] - 2024-03-06
Expand Down
4 changes: 2 additions & 2 deletions shiny/_custom_component_template_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def update_names_in_files(dir: Path):
for item in dir.iterdir():
if item.is_file():
# Only do this for files
with open(item, "r") as f:
with open(item, "r", encoding="utf-8") as f:
file_contents = f.read()
# First, "custom_component" -> "new_component_name"
file_contents = file_contents.replace(
Expand All @@ -151,7 +151,7 @@ def update_names_in_files(dir: Path):
old_capital_case_name, capital_case_name
)

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

# Loop over dirs_to_update and run the update function on them
Expand Down
4 changes: 2 additions & 2 deletions shiny/_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class DocStringWithExample(str): ...
class ExampleWriter:
def write_example(self, app_files: list[str]) -> str:
app_file = app_files[0]
with open(app_file) as f:
with open(app_file, encoding="utf-8") as f:
code = f.read()

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

with open(app_path) as f:
with open(app_path, encoding="utf-8") as f:
for line in f:
if "from shiny.express" in line:
return True
Expand Down
2 changes: 1 addition & 1 deletion shiny/express/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def express_server(input: Inputs, output: Outputs, session: Session):


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

tree = ast.parse(content, file)
Expand Down
6 changes: 3 additions & 3 deletions shiny/quarto.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ def convert_code_cells_to_app_py(json_file: str | Path, app_file: str | Path) ->
app_file = Path(app_file)

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

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

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

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


Expand Down