From 31cd7c35c96500ea0c5adba714669c8a8fc75326 Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Sat, 11 Oct 2025 16:34:14 +0300 Subject: [PATCH] [+] fix relative_to error, vim config --- dotfiles/.py3.vimrc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/dotfiles/.py3.vimrc b/dotfiles/.py3.vimrc index b798dd3..033685e 100644 --- a/dotfiles/.py3.vimrc +++ b/dotfiles/.py3.vimrc @@ -187,10 +187,18 @@ class EditorConfigModeline: @classmethod def find_entry( cls, - config: dict[str, str], - file_path: pathlib.Path + file_path: pathlib.Path, + config: Optional[dict[str, str]] = None, ) -> Optional[str]: - rel_path = file_path.relative_to(pathlib.Path.cwd()) + if config is None: + return None + + project_root = pathlib.Path.cwd() + + if file_path.is_relative_to(project_root): + rel_path = file_path.relative_to(pathlib.Path.cwd()) + else: + rel_path = file_path for pattern, modeline in config.items(): if fnmatch.fnmatch(str(rel_path), pattern): @@ -206,7 +214,7 @@ class EditorConfigModeline: buf_name = vim.current.buffer.name file_path = pathlib.Path(buf_name).resolve() - entry = self.find_entry(config, file_path) + entry = self.find_entry(file_path, config=config) logger.info(dict(modeline=entry))