From cadf6307cd59b1c9b48e2646a3981b0a0ac8cb83 Mon Sep 17 00:00:00 2001 From: Daniel Nakov Date: Fri, 8 Nov 2024 03:07:25 +0000 Subject: [PATCH] make r2ai-plugin work r2pm --- main.py | 1 - r2ai/main.py | 1 + r2ai/plugin.py | 17 ++++++++++++++++- r2ai/tab.py | 17 ++++++++++------- 4 files changed, 27 insertions(+), 9 deletions(-) delete mode 100644 main.py diff --git a/main.py b/main.py deleted file mode 100644 index e0e255f..0000000 --- a/main.py +++ /dev/null @@ -1 +0,0 @@ -import r2ai.cli diff --git a/r2ai/main.py b/r2ai/main.py index 806dd6c..465c7cc 100755 --- a/r2ai/main.py +++ b/r2ai/main.py @@ -68,6 +68,7 @@ def run_rcfile_once(ai): def main(args, commands, dorepl=True): os.environ["TOKENIZERS_PARALLELISM"] = "false" + os.environ["TRANSFORMERS_NO_ADVISORY_WARNINGS"] = "1" try: r2aihome = os.path.dirname(os.path.realpath(__file__)) diff --git a/r2ai/plugin.py b/r2ai/plugin.py index 23d0ded..eeff3d3 100644 --- a/r2ai/plugin.py +++ b/r2ai/plugin.py @@ -1,7 +1,22 @@ """Entrypoint for the r2ai plugin and repl.""" - +import sys +import os import builtins import traceback + +current_dir = os.path.dirname(os.path.realpath(__file__)) +parent_dir = os.path.dirname(current_dir) +sys.path.insert(0, parent_dir) +os.environ["TRANSFORMERS_NO_ADVISORY_WARNINGS"] = "1" +try: + venv_dir = os.path.join(parent_dir, 'venv') + if os.path.exists(venv_dir): + site_packages = os.path.join(venv_dir, 'lib', 'python{}.{}'.format(*sys.version_info[:2]), 'site-packages') + if os.path.exists(site_packages): + sys.path.insert(0, site_packages) +except Exception: + pass + import r2lang from r2ai.main import r2ai_singleton, run_rcfile_once, runline, help_message diff --git a/r2ai/tab.py b/r2ai/tab.py index 589d855..e4c2d57 100644 --- a/r2ai/tab.py +++ b/r2ai/tab.py @@ -141,10 +141,13 @@ def tab_init(): pass except Exception: pass - readline.set_completer(completer.complete) - readline.set_completer_delims('\t\n;') - readline.set_completion_display_matches_hook(completer.display_matches) - if readline.__doc__.find("GNU") != -1: - readline.parse_and_bind('tab: complete') - else: - readline.parse_and_bind("bind ^I rl_complete") + try: + readline.set_completer(completer.complete) + readline.set_completer_delims('\t\n;') + readline.set_completion_display_matches_hook(completer.display_matches) + if readline.__doc__.find("GNU") != -1: + readline.parse_and_bind('tab: complete') + else: + readline.parse_and_bind("bind ^I rl_complete") + except Exception as e: + pass