From b2a608d3697fc2be8d1e3b17d47c067e593049a9 Mon Sep 17 00:00:00 2001 From: santaspeen Date: Fri, 26 Jul 2024 17:07:32 +0300 Subject: [PATCH] [+] Add supports for pip packets --- src/modules/PluginsLoader/__init__.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/modules/PluginsLoader/__init__.py b/src/modules/PluginsLoader/__init__.py index 36afaa0..ff7c61a 100644 --- a/src/modules/PluginsLoader/__init__.py +++ b/src/modules/PluginsLoader/__init__.py @@ -7,17 +7,15 @@ # Licence: FPA # (c) kuitoi.su 2023 import asyncio -import importlib import inspect import os +import subprocess import sys import types from contextlib import contextmanager from pathlib import Path from threading import Thread -from pip._internal.utils.entrypoints import main as pip_main - from core import get_logger @@ -118,12 +116,19 @@ def __init__(self, plugins_dir): ev.register("_plugins_get", lambda x: list(self.plugins.keys())) console.add_command("plugins", lambda x: self.loaded_str[:-2]) console.add_command("pl", lambda x: self.loaded_str[:-2]) - console.add_command("install", self._pip_install) sys.path.append(self._pip_dir) + os.makedirs(self._pip_dir, exist_ok=True) + console.add_command("install", self._pip_install) def _pip_install(self, x): + self.log.debug(f"_pip_install {x}") if len(x) > 0: - pip_main(['install', x[0], '--target', self._pip_dir]) + try: + subprocess.check_call(['pip', 'install', *x, '--target', self._pip_dir]) + return "Success" + except subprocess.CalledProcessError as e: + self.log.debug(f"error: {e}") + return f"Failed to install packages" else: return "Invalid syntax"