mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 01:35:00 +00:00
feat: optimize slow imports loading based on version and executable
This commit is contained in:
parent
ed7a9c6562
commit
f54b6860db
1 changed files with 33 additions and 5 deletions
|
@ -705,24 +705,52 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
||||||
|
|
||||||
|
|
||||||
def launch_slow_imports_thread():
|
def launch_slow_imports_thread():
|
||||||
thread = threading.Thread(target=load_slow_imports)
|
thread = threading.Thread(target=check_and_load_imports)
|
||||||
thread.daemon = True
|
thread.daemon = True
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
|
|
||||||
|
def check_and_load_imports():
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
installs_file = Path.home() / ".aider" / "installs.json"
|
||||||
|
key = (__version__, sys.executable)
|
||||||
|
|
||||||
|
try:
|
||||||
|
if installs_file.exists():
|
||||||
|
with open(installs_file, "r") as f:
|
||||||
|
installs = json.load(f)
|
||||||
|
else:
|
||||||
|
installs = {}
|
||||||
|
|
||||||
|
if str(key) not in installs:
|
||||||
|
load_slow_imports()
|
||||||
|
installs[str(key)] = True
|
||||||
|
installs_file.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
with open(installs_file, "w") as f:
|
||||||
|
json.dump(installs, f)
|
||||||
|
else:
|
||||||
|
thread = threading.Thread(target=load_slow_imports)
|
||||||
|
thread.daemon = True
|
||||||
|
thread.start()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error in check_and_load_imports: {e}", file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
def load_slow_imports():
|
def load_slow_imports():
|
||||||
# These imports are deferred in various ways to
|
# These imports are deferred in various ways to
|
||||||
# improve startup time.
|
# improve startup time.
|
||||||
# This func is called in a thread to load them in the background
|
# This func is called either synchronously or in a thread
|
||||||
# while we wait for the user to type their first message.
|
# depending on whether it's been run before for this version and executable.
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import httpx # noqa: F401
|
import httpx # noqa: F401
|
||||||
import litellm # noqa: F401
|
import litellm # noqa: F401
|
||||||
import networkx # noqa: F401
|
import networkx # noqa: F401
|
||||||
import numpy # noqa: F401
|
import numpy # noqa: F401
|
||||||
except Exception:
|
except Exception as e:
|
||||||
pass
|
print(f"Error in load_slow_imports: {e}", file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue