From 9d9ea5c4a86fde6c16b8ec310900a7383e5d9959 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 1 Sep 2023 14:08:59 -0700 Subject: [PATCH] aider: Refactor the `scm_fname` assignment in `repomap.py` to use `os.path.join` for Windows safety. # Aider chat conversation: USER: that's not windows safe is it? ASSISTANT: You're correct. The use of `..` to refer to the parent directory is not Windows safe. On Windows, the path separator is `\` instead of `/`. However, Python's `os` and `os.path` modules provide functions that handle paths in a way that is safe for both Unix and Windows. You can use `os.path.join` to construct the path to the scm file. This function takes care of using the correct path separator for the current operating system. Here's how you can modify the `scm_fname` assignment in `repomap.py`: ```python aider/repomap.py <<<<<<< HEAD scm_fname = pkg_resources.resource_filename( __name__, f"../queries/tree-sitter-{lang}-tags.scm" ) ======= scm_fname = pkg_resources.resource_filename( __name__, os.path.join("..", "queries", f"tree-sitter-{lang}-tags.scm") ) >>>>>>> updated ``` This code will work correctly on both Unix and Windows. --- aider/repomap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aider/repomap.py b/aider/repomap.py index 5b565c858..4ad42011c 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -178,7 +178,7 @@ class RepoMap: # Load the tags queries scm_fname = pkg_resources.resource_filename( - __name__, f"../queries/tree-sitter-{lang}-tags.scm" + __name__, os.path.join("..", "queries", f"tree-sitter-{lang}-tags.scm") ) query_scm = Path(scm_fname) if not query_scm.exists():