diff --git a/CHANGELOG.md b/CHANGELOG.md index 51cd06725..b8e9bc1ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/shiny/_custom_component_template_questions.py b/shiny/_custom_component_template_questions.py index 00e64e4b0..4ca5b3350 100644 --- a/shiny/_custom_component_template_questions.py +++ b/shiny/_custom_component_template_questions.py @@ -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( @@ -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 diff --git a/shiny/_docstring.py b/shiny/_docstring.py index 8505f96b0..96029dfe4 100644 --- a/shiny/_docstring.py +++ b/shiny/_docstring.py @@ -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" @@ -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 diff --git a/shiny/express/_run.py b/shiny/express/_run.py index 53f112d25..f771731fd 100644 --- a/shiny/express/_run.py +++ b/shiny/express/_run.py @@ -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) diff --git a/shiny/quarto.py b/shiny/quarto.py index 5f0d5efc2..f9cba0e68 100644 --- a/shiny/quarto.py +++ b/shiny/quarto.py @@ -36,7 +36,7 @@ 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( @@ -44,7 +44,7 @@ def convert_code_cells_to_app_py(json_file: str | Path, app_file: str | Path) -> " 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: @@ -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)