Skip to content

fix: Fix default encoding when opening / writing files #51

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 2 commits into from
Mar 4, 2025
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
4 changes: 2 additions & 2 deletions code_embedder/code_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _read_readme(self, readme_path: str) -> list[str]:
if not readme_path.endswith(".md"):
raise ValueError("README path must end with .md")

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

def _extract_scripts(
Expand Down Expand Up @@ -86,5 +86,5 @@ def _update_readme(

updated_readme += readme_content[readme_content_cursor:]

with open(readme_path, "w") as readme_file:
with open(readme_path, "w", encoding="utf-8") as readme_file:
readme_file.writelines(updated_readme)
2 changes: 1 addition & 1 deletion code_embedder/script_content_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _read_full_script(self, scripts: list[ScriptMetadata]) -> list[ScriptMetadat

for script in scripts:
try:
with open(script.path) as script_file:
with open(script.path, encoding="utf-8") as script_file:
script.content = script_file.read()
scripts_with_full_contents.append(script)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_code_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_code_embedder(
) -> None:
# Create a temporary copy of the original file
temp_readme_path = tmp_path / "readme.md"
with open(before_code_embedding_path) as readme_file:
with open(before_code_embedding_path, encoding="utf-8") as readme_file:
temp_readme_path.write_text(readme_file.read())

code_embedder = CodeEmbedder(
Expand All @@ -55,10 +55,10 @@ def test_code_embedder(

code_embedder()

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

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

assert updated_readme_content == expected_readme_content
Expand Down