From 7b77dbb88d15733eb165e2be05b096553ab4e096 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 1 Sep 2023 14:06:51 -0700 Subject: [PATCH] aider: Updated package data to include the queries directory and modified repomap.py to use pkg_resources to access the scm files at runtime. # Aider chat conversation: USER: the `scm_fname` is using a path in my local filesystem. how do i package up the queries directory for pip install in a way that the script can find those scm files at runtime ASSISTANT: To package the queries directory for pip install, you need to include it in your package data in the `setup.py` file. This will ensure that the directory is included when your package is installed. Then, you can use the `pkg_resources` module to access the files at runtime. This module is part of `setuptools`, so it's already installed if you're using pip. Here are the steps: 1. Modify `setup.py` to include the queries directory in the package data. ```python setup.py <<<<<<< HEAD packages=find_packages(), include_package_data=True, ======= packages=find_packages(), include_package_data=True, package_data={ '': ['queries/*'], }, >>>>>>> updated ``` 2. Modify `aider/repomap.py` to use `pkg_resources` to access the scm files at runtime. ```python aider/repomap.py <<<<<<< HEAD scm_fname = ( f"/Users/gauthier/tmp/py-tree-sitter-languages/queries/tree-sitter-{lang}-tags.scm" ) ======= scm_fname = pkg_resources.resource_filename( __name__, f"queries/tree-sitter-{lang}-tags.scm" ) >>>>>>> updated ``` Please note that the `queries` directory should be in the same directory as the `repomap.py` file for this to work. If it's in a different location, you'll need to adjust the path in the `resource_filename` call accordingly. --- aider/repomap.py | 4 ++-- setup.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/aider/repomap.py b/aider/repomap.py index 1b99c5111..1c90ab655 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -177,8 +177,8 @@ class RepoMap: parser = get_parser(lang) # Load the tags queries - scm_fname = ( - f"/Users/gauthier/tmp/py-tree-sitter-languages/queries/tree-sitter-{lang}-tags.scm" + scm_fname = pkg_resources.resource_filename( + __name__, f"queries/tree-sitter-{lang}-tags.scm" ) query_scm = Path(scm_fname) if not query_scm.exists(): diff --git a/setup.py b/setup.py index bc6efe6ca..412c18e0d 100644 --- a/setup.py +++ b/setup.py @@ -17,6 +17,9 @@ setup( version=__version__, packages=find_packages(), include_package_data=True, + package_data={ + '': ['queries/*'], + }, install_requires=requirements, python_requires='>=3.9', entry_points={