mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 06:15:00 +00:00
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:
parent
1a7732c851
commit
534ff2ad1e
1 changed files with 11 additions and 3 deletions
|
@ -27,7 +27,9 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
|
||||||
|
|
||||||
|
|
||||||
class Coder:
|
class Coder:
|
||||||
fnames = set()
|
fnames = dict()
|
||||||
|
relative_to_fname = dict()
|
||||||
|
|
||||||
last_modified = 0
|
last_modified = 0
|
||||||
repo = None
|
repo = None
|
||||||
|
|
||||||
|
@ -60,10 +62,17 @@ class Coder:
|
||||||
self.console.print(
|
self.console.print(
|
||||||
"[red bold]No suitable git repo, will not automatically commit edits."
|
"[red bold]No suitable git repo, will not automatically commit edits."
|
||||||
)
|
)
|
||||||
|
self.find_common_root()
|
||||||
|
|
||||||
|
self.set_relative_fnames()
|
||||||
|
|
||||||
self.pretty = pretty
|
self.pretty = pretty
|
||||||
self.show_diffs = show_diffs
|
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):
|
def find_common_root(self):
|
||||||
common_prefix = os.path.commonprefix(list(self.fnames))
|
common_prefix = os.path.commonprefix(list(self.fnames))
|
||||||
self.root = os.path.dirname(common_prefix)
|
self.root = os.path.dirname(common_prefix)
|
||||||
|
@ -81,10 +90,9 @@ class Coder:
|
||||||
|
|
||||||
if num_repos == 0:
|
if num_repos == 0:
|
||||||
self.console.print("[red bold]Files are not in a git repo.")
|
self.console.print("[red bold]Files are not in a git repo.")
|
||||||
|
return
|
||||||
if num_repos > 1:
|
if num_repos > 1:
|
||||||
self.console.print("[red bold]Files are in different git repos.")
|
self.console.print("[red bold]Files are in different git repos.")
|
||||||
if num_repos != 1:
|
|
||||||
self.find_common_root()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# https://github.com/gitpython-developers/GitPython/issues/427
|
# https://github.com/gitpython-developers/GitPython/issues/427
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue