aider: Updated set_relative_fnames to compute the relative file paths and store them in the self.relative_to_fname dictionary.

# Context:
USER: implement set_relative_fnames
ASSISTANT:
^C KeyboardInterrupt
USER: implement set_relative_fnames. for each self.fnames it should compute the fname relative to self.root and set self.relative_to_fname[rel_fname] = fname
ASSISTANT: To implement the `set_relative_fnames` method, you need to iterate through `self.fnames`, compute the relative path for each file using `os.path.relpath()`, and then update the `self.relative_to_fname` dictionary with the relative path as the key and the original file path as the value.

Here's the code change for the `set_relative_fnames` method:

```python
aider/coder.py
<<<<<<< ORIGINAL
    def set_relative_fnames(self):
        pass
=======
    def set_relative_fnames(self):
        for fname in self.fnames:
            rel_fname = os.path.relpath(fname, self.root)
            self.relative_to_fname[rel_fname] = fname
>>>>>>> UPDATED
```
This will update the `set_relative_fnames` method to compute the relative file paths and store them in the `self.relative_to_fname` dictionary.
This commit is contained in:
Paul Gauthier 2023-05-10 09:19:54 -07:00
parent 1a7732c851
commit 534ff2ad1e

View file

@ -27,7 +27,9 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
class Coder:
fnames = set()
fnames = dict()
relative_to_fname = dict()
last_modified = 0
repo = None
@ -60,10 +62,17 @@ class Coder:
self.console.print(
"[red bold]No suitable git repo, will not automatically commit edits."
)
self.find_common_root()
self.set_relative_fnames()
self.pretty = pretty
self.show_diffs = show_diffs
def set_relative_fnames(self):
for fname in self.fnames:
rel_fname = os.path.relpath(fname, self.root)
self.relative_to_fname[rel_fname] = fname
def find_common_root(self):
common_prefix = os.path.commonprefix(list(self.fnames))
self.root = os.path.dirname(common_prefix)
@ -81,10 +90,9 @@ class Coder:
if num_repos == 0:
self.console.print("[red bold]Files are not in a git repo.")
return
if num_repos > 1:
self.console.print("[red bold]Files are in different git repos.")
if num_repos != 1:
self.find_common_root()
return
# https://github.com/gitpython-developers/GitPython/issues/427