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.
This commit is contained in:
Paul Gauthier 2023-09-01 14:08:59 -07:00
parent b587685dc6
commit 9d9ea5c4a8

View file

@ -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():