From 5717e1ebd39d3735070b6594ee356fe6b3dffc78 Mon Sep 17 00:00:00 2001 From: Joe Cheng Date: Thu, 7 Mar 2024 14:24:28 -0500 Subject: [PATCH 1/3] Force UTF-8 for Shiny Express on Windows --- shiny/express/_run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 5819cee6d5f94e91f6718116fde339967591d479 Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Wed, 13 Mar 2024 17:28:02 -0500 Subject: [PATCH 2/3] Read in files as UTF-8 --- shiny/_custom_component_template_questions.py | 4 ++-- shiny/_docstring.py | 4 ++-- shiny/quarto.py | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) 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/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) From 56d28880c25653d8a6615ff9db5dca467c860022 Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Wed, 13 Mar 2024 17:31:27 -0500 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) 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