Skip to content

Commit 9e24446

Browse files
authored
fix: Fix default encoding when opening / writing files
fix: Fix default encoding when opening / writing files
2 parents 00f64ac + 6282584 commit 9e24446

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

code_embedder/code_embedding.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _read_readme(self, readme_path: str) -> list[str]:
5353
if not readme_path.endswith(".md"):
5454
raise ValueError("README path must end with .md")
5555

56-
with open(readme_path) as readme_file:
56+
with open(readme_path, encoding="utf-8") as readme_file:
5757
return readme_file.readlines()
5858

5959
def _extract_scripts(
@@ -86,5 +86,5 @@ def _update_readme(
8686

8787
updated_readme += readme_content[readme_content_cursor:]
8888

89-
with open(readme_path, "w") as readme_file:
89+
with open(readme_path, "w", encoding="utf-8") as readme_file:
9090
readme_file.writelines(updated_readme)

code_embedder/script_content_reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def _read_full_script(self, scripts: list[ScriptMetadata]) -> list[ScriptMetadat
2424

2525
for script in scripts:
2626
try:
27-
with open(script.path) as script_file:
27+
with open(script.path, encoding="utf-8") as script_file:
2828
script.content = script_file.read()
2929
scripts_with_full_contents.append(script)
3030

tests/test_code_embedding.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_code_embedder(
4343
) -> None:
4444
# Create a temporary copy of the original file
4545
temp_readme_path = tmp_path / "readme.md"
46-
with open(before_code_embedding_path) as readme_file:
46+
with open(before_code_embedding_path, encoding="utf-8") as readme_file:
4747
temp_readme_path.write_text(readme_file.read())
4848

4949
code_embedder = CodeEmbedder(
@@ -55,10 +55,10 @@ def test_code_embedder(
5555

5656
code_embedder()
5757

58-
with open(after_code_embedding_path) as expected_file:
58+
with open(after_code_embedding_path, encoding="utf-8") as expected_file:
5959
expected_readme_content = expected_file.readlines()
6060

61-
with open(temp_readme_path) as updated_file:
61+
with open(temp_readme_path, encoding="utf-8") as updated_file:
6262
updated_readme_content = updated_file.readlines()
6363

6464
assert updated_readme_content == expected_readme_content

0 commit comments

Comments
 (0)