refactor: Move find_common_root into aider/utils.py and update Coder class to use it

This commit is contained in:
Paul Gauthier (aider) 2024-08-22 13:55:32 -07:00
parent 8c886d7dd3
commit 221cde0fed
2 changed files with 11 additions and 7 deletions

View file

@ -434,13 +434,7 @@ class Coder:
bold = False
def find_common_root(self):
if len(self.abs_fnames) == 1:
self.root = os.path.dirname(list(self.abs_fnames)[0])
elif self.abs_fnames:
self.root = os.path.commonpath(list(self.abs_fnames))
else:
self.root = os.getcwd()
self.root = utils.find_common_root(self.abs_fnames)
self.root = utils.safe_abs_path(self.root)
def add_rel_fname(self, rel_fname):

View file

@ -272,6 +272,16 @@ class Spinner:
print("\r" + " " * (len(self.text) + 3))
import os
def find_common_root(abs_fnames):
if len(abs_fnames) == 1:
return os.path.dirname(list(abs_fnames)[0])
elif abs_fnames:
return os.path.commonpath(list(abs_fnames))
else:
return os.getcwd()
def check_pip_install_extra(io, module, prompt, pip_install_cmd):
try:
__import__(module)