diff --git a/src/vectorcode/cli_utils.py b/src/vectorcode/cli_utils.py index 0131a5e2..8ac428d2 100644 --- a/src/vectorcode/cli_utils.py +++ b/src/vectorcode/cli_utils.py @@ -492,7 +492,7 @@ async def load_config_file(path: Optional[Union[str, Path]] = None): break if path and os.path.isfile(path): logger.debug(f"Loading config from {path}") - with open(path) as fin: + with open(path, encoding="utf-8") as fin: content = fin.read() if content: config = json5.loads(content) @@ -681,7 +681,7 @@ def get_lock(self, path: str | os.PathLike) -> AsyncFileLock: lock_file = os.path.join(path, "vectorcode.lock") logger.info(f"Creating {lock_file} for locking.") if not os.path.isfile(lock_file): - with open(lock_file, mode="w") as fin: + with open(lock_file, mode="w", encoding="utf-8") as fin: fin.write("") path = lock_file if self.__locks.get(path) is None: @@ -719,7 +719,7 @@ def from_path(cls, spec_path: str, project_root: Optional[str] = None): def __init__(self, spec: str | GitIgnoreSpec, base_dir: str = "."): if isinstance(spec, str): - with open(spec) as fin: + with open(spec, encoding="utf-8") as fin: self.spec = GitIgnoreSpec.from_lines( (i.strip() for i in fin.readlines()) ) diff --git a/src/vectorcode/mcp_main.py b/src/vectorcode/mcp_main.py index 808ba6f4..dd2421eb 100644 --- a/src/vectorcode/mcp_main.py +++ b/src/vectorcode/mcp_main.py @@ -218,7 +218,7 @@ async def query_tool( for result in result_paths: if isinstance(result, str): if os.path.isfile(result): - with open(result) as fin: + with open(result, encoding="utf-8") as fin: rel_path = os.path.relpath(result, config.project_root) results.append( f"{rel_path}\n{fin.read()}", diff --git a/src/vectorcode/subcommands/init.py b/src/vectorcode/subcommands/init.py index bba9af63..ed893fc4 100644 --- a/src/vectorcode/subcommands/init.py +++ b/src/vectorcode/subcommands/init.py @@ -49,7 +49,7 @@ def load_hooks(): global __HOOK_CONTENTS for file in glob.glob(str(__GLOBAL_HOOKS_PATH / "*")): hook_name = Path(file).stem - with open(file) as fin: + with open(file, encoding="utf-8") as fin: lines = fin.readlines() if not __lines_are_empty(lines): __HOOK_CONTENTS[hook_name] = lines @@ -65,7 +65,7 @@ def __init__(self, path: str | Path, git_dir: Optional[str | Path] = None): self.path = path self.lines: list[str] = [] if os.path.isfile(self.path): - with open(self.path) as fin: + with open(self.path, encoding="utf-8") as fin: self.lines.extend(fin.readlines()) def has_vectorcode_hooks(self, force: bool = False) -> bool: @@ -92,7 +92,7 @@ def inject_hook(self, content: list[str], force: bool = False): self.lines.append(self.prefix + "\n") self.lines.extend(i if i.endswith("\n") else i + "\n" for i in content) self.lines.append(self.suffix + "\n") - with open(self.path, "w") as fin: + with open(self.path, "w", encoding="utf-8") as fin: if os.path.islink(self.path): # pragma: nocover logger.warning(f"{self.path} is a symlink.") fin.writelines(self.lines) diff --git a/src/vectorcode/subcommands/query/__init__.py b/src/vectorcode/subcommands/query/__init__.py index 22ab5abc..78e8a3cb 100644 --- a/src/vectorcode/subcommands/query/__init__.py +++ b/src/vectorcode/subcommands/query/__init__.py @@ -151,7 +151,7 @@ def make_output_path(path: str, absolute: bool) -> str: if not os.path.isfile(io_path): logger.warning(f"{io_path} is no longer a valid file.") continue - with open(io_path) as fin: + with open(io_path, encoding="utf-8") as fin: structured_result.append({"path": output_path, "document": fin.read()}) else: res = cast(Chunk, res) diff --git a/src/vectorcode/subcommands/vectorise.py b/src/vectorcode/subcommands/vectorise.py index 2ce0b249..fd0b1619 100644 --- a/src/vectorcode/subcommands/vectorise.py +++ b/src/vectorcode/subcommands/vectorise.py @@ -219,13 +219,13 @@ def load_files_from_include(project_root: str) -> list[str]: specs: Optional[pathspec.GitIgnoreSpec] = None if os.path.isfile(include_file_path): logger.debug("Loading from local `vectorcode.include`.") - with open(include_file_path) as fin: + with open(include_file_path, encoding="utf-8") as fin: specs = pathspec.GitIgnoreSpec.from_lines( lines=(os.path.expanduser(i) for i in fin.readlines()), ) elif os.path.isfile(GLOBAL_INCLUDE_SPEC): logger.debug("Loading from global `vectorcode.include`.") - with open(GLOBAL_INCLUDE_SPEC) as fin: + with open(GLOBAL_INCLUDE_SPEC, encoding="utf-8") as fin: specs = pathspec.GitIgnoreSpec.from_lines( lines=(os.path.expanduser(i) for i in fin.readlines()), )