Skip to content

Commit

Permalink
chore: add explicit utf-8 file encoding (#30)
Browse files Browse the repository at this point in the history
Closes #25.
  • Loading branch information
fynnfluegge authored Jan 20, 2024
1 parent f6f3907 commit d6cf1a1
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 205 deletions.
8 changes: 6 additions & 2 deletions codeqai/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def to_json(self):


def load_vector_cache(filename) -> Dict[str, VectorCache]:
with open(get_cache_path() + "/" + filename, "r") as vector_cache_file:
with open(
get_cache_path() + "/" + filename, "r", encoding="utf-8"
) as vector_cache_file:
vector_cache_json = json.load(vector_cache_file)
vector_cache = {}
for key, value in vector_cache_json.items():
Expand All @@ -36,7 +38,9 @@ def load_vector_cache(filename) -> Dict[str, VectorCache]:


def save_vector_cache(vector_cache, filename):
with open(get_cache_path() + "/" + filename, "w") as vector_cache_file:
with open(
get_cache_path() + "/" + filename, "w", encoding="utf-8"
) as vector_cache_file:
json.dump(vector_cache, default=VectorCache.to_json, fp=vector_cache_file)


Expand Down
2 changes: 1 addition & 1 deletion codeqai/codeparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def parse_code_files(code_files: list[str]) -> list[Document]:
documents = []
code_splitter = None
for code_file in code_files:
with open(code_file, "r") as file:
with open(code_file, "r", encoding="utf-8") as file:
file_bytes = file.read().encode()
commit_hash = repo.get_commit_hash(code_file)

Expand Down
6 changes: 2 additions & 4 deletions codeqai/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json
import os
import platform
from pathlib import Path

import inquirer
import yaml
Expand All @@ -27,13 +25,13 @@ def get_config_path():


def load_config():
with open(get_config_path(), "r") as config_file:
with open(get_config_path(), "r", encoding="utf-8") as config_file:
config = yaml.safe_load(config_file)
return config


def save_config(config):
with open(get_config_path(), "w") as config_file:
with open(get_config_path(), "w", encoding="utf-8") as config_file:
yaml.dump(config, config_file, default_flow_style=False)


Expand Down
Loading

0 comments on commit d6cf1a1

Please sign in to comment.