diff --git a/setup.py b/setup.py index acee8a4..d8959a1 100644 --- a/setup.py +++ b/setup.py @@ -44,14 +44,7 @@ def get_long_description() -> str: python_requires=">=3.7.0", zip_safe=False, install_requires=[ - "PyDictionary==1.5.2", - "requests==2.21.0", - "wikipedia==1.4.0", - "google==2.0.2", - "beautifulsoup4==4.7.1", - "deuces==0.2", - "httplib2==0.18.0", - "flightradar24==0.2" + ], classifiers=[ "Development Status :: 4 - Beta", diff --git a/src/honeybot/api/main.py b/src/honeybot/api/main.py index 185aa0e..78370ce 100644 --- a/src/honeybot/api/main.py +++ b/src/honeybot/api/main.py @@ -7,6 +7,10 @@ import sys import time import os +import pathlib +import pkg_resources +import setuptools +import subprocess # from pathlib import Path try: @@ -149,53 +153,61 @@ def print_running_infos(self): print(key, self.info[key]) print('-'*3) - def load_plugins(self): - """ - Load plugins that are specified in the plugins list. - - Args: - plugins_to_load (list of str): List of plugins to load. - - Examples: - TODO - """ - logger.info("Loading plugins...") + def load_plugins_from_folder(self, category_folder, from_conf=None, from_dir=None): - to_load = [] - plugs = os.path.join(self.settings_path, "PLUGINS.conf") - with open(plugs) as f: - to_load = f.read().split("\n") - to_load = list(filter(lambda x: x != "", to_load)) + if from_dir is not None: + to_load = [f for f in os.listdir(from_dir) if self.is_valid_plug_name(f)] + elif from_conf is not None: + to_load = [] + plugs = from_conf + with open(plugs) as f: + to_load = f.read().split("\n") + to_load = list(filter(lambda x: x != "", to_load)) + print('Loading', category_folder) for folder in to_load: print("loading plugin:", folder) try: sys.path.append(self.root_path) module = importlib.import_module( - "plugins.downloaded.{}.main".format(folder)) + "plugins.{}.{}.main".format(category_folder, folder)) obj = module self.plugins.append(obj) except ModuleNotFoundError as e: logger.warning(f"{folder}: module import error, skipped' {e}") - print() - print('loading core plugins') - for folder in os.listdir(os.path.join(self.info['plugins_path'], 'core')): - if self.is_valid_plug_name(folder): - print("loading plugin:", folder) - try: - module = importlib.import_module( - "plugins.core.{}.main".format(folder)) - obj = module - self.plugins.append(obj) - except ModuleNotFoundError as e: - logger.warning(f"{folder}: module import error, skipped' {e}") - else: - if not folder.startswith('__'): - logger.warning(f"{folder}: name not valid") + try: + req_path = os.path.join(self.info['cwd'], 'plugins', category_folder, folder, 'requirements.txt') + if os.path.exists(req_path): + with pathlib.Path(req_path).open() as requirements_txt: + install_requires = [ + str(requirement) + for requirement + in pkg_resources.parse_requirements(requirements_txt) + ] + print('installing', install_requires) + subprocess.check_call([sys.executable, '-m', 'pip', 'install', *install_requires]) + except Exception as e: + logger.debug(e) + + def load_plugins(self): + """ + Load plugins that are specified in the plugins list. + + Args: + plugins_to_load (list of str): List of plugins to load. + + Examples: + TODO + """ + + logger.info("Loading plugins...") - + conf_path = os.path.join(self.settings_path, "PLUGINS.conf") + dir_path = os.path.join(self.info['plugins_path'], 'core') + self.load_plugins_from_folder('downloaded', from_conf=conf_path) + self.load_plugins_from_folder('core', from_dir=dir_path) logger.info("Loaded plugins") print('---') diff --git a/src/honeybot/plugins/downloaded/bitcoin/requirements.txt b/src/honeybot/plugins/downloaded/bitcoin/requirements.txt new file mode 100644 index 0000000..663bd1f --- /dev/null +++ b/src/honeybot/plugins/downloaded/bitcoin/requirements.txt @@ -0,0 +1 @@ +requests \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/blackjack/poker_assets/hand.py b/src/honeybot/plugins/downloaded/blackjack/poker_assets/hand.py index 41970f3..69d01b4 100644 --- a/src/honeybot/plugins/downloaded/blackjack/poker_assets/hand.py +++ b/src/honeybot/plugins/downloaded/blackjack/poker_assets/hand.py @@ -4,7 +4,7 @@ # parts not necessary for blackjack but required for poker commented out -# import deuces +# import deuces "deuces==0.2", # import best5 # import board # import card diff --git a/src/honeybot/plugins/downloaded/blackjack/requirements.txt b/src/honeybot/plugins/downloaded/blackjack/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/honeybot/plugins/downloaded/book_of_day/requirements.txt b/src/honeybot/plugins/downloaded/book_of_day/requirements.txt new file mode 100644 index 0000000..a98ae43 --- /dev/null +++ b/src/honeybot/plugins/downloaded/book_of_day/requirements.txt @@ -0,0 +1,2 @@ +requests +beautifulsoup4 \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/comic/requirements.txt b/src/honeybot/plugins/downloaded/comic/requirements.txt new file mode 100644 index 0000000..663bd1f --- /dev/null +++ b/src/honeybot/plugins/downloaded/comic/requirements.txt @@ -0,0 +1 @@ +requests \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/converter/requirements.txt b/src/honeybot/plugins/downloaded/converter/requirements.txt new file mode 100644 index 0000000..a98ae43 --- /dev/null +++ b/src/honeybot/plugins/downloaded/converter/requirements.txt @@ -0,0 +1,2 @@ +requests +beautifulsoup4 \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/corona/requirements.txt b/src/honeybot/plugins/downloaded/corona/requirements.txt new file mode 100644 index 0000000..a98ae43 --- /dev/null +++ b/src/honeybot/plugins/downloaded/corona/requirements.txt @@ -0,0 +1,2 @@ +requests +beautifulsoup4 \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/dadjoke/requirements.txt b/src/honeybot/plugins/downloaded/dadjoke/requirements.txt new file mode 100644 index 0000000..663bd1f --- /dev/null +++ b/src/honeybot/plugins/downloaded/dadjoke/requirements.txt @@ -0,0 +1 @@ +requests \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/dictionary/requirements.txt b/src/honeybot/plugins/downloaded/dictionary/requirements.txt new file mode 100644 index 0000000..68035b8 --- /dev/null +++ b/src/honeybot/plugins/downloaded/dictionary/requirements.txt @@ -0,0 +1 @@ +PyDictionary==1.5.2 \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/flight/requirements.txt b/src/honeybot/plugins/downloaded/flight/requirements.txt new file mode 100644 index 0000000..ab05efe --- /dev/null +++ b/src/honeybot/plugins/downloaded/flight/requirements.txt @@ -0,0 +1 @@ +flightradar24==0.2 \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/google/requirements.txt b/src/honeybot/plugins/downloaded/google/requirements.txt new file mode 100644 index 0000000..0ec0ccc --- /dev/null +++ b/src/honeybot/plugins/downloaded/google/requirements.txt @@ -0,0 +1 @@ +google==2.0.2 \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/horoscope/requirements.txt b/src/honeybot/plugins/downloaded/horoscope/requirements.txt new file mode 100644 index 0000000..a98ae43 --- /dev/null +++ b/src/honeybot/plugins/downloaded/horoscope/requirements.txt @@ -0,0 +1,2 @@ +requests +beautifulsoup4 \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/monero/requirements.txt b/src/honeybot/plugins/downloaded/monero/requirements.txt new file mode 100644 index 0000000..663bd1f --- /dev/null +++ b/src/honeybot/plugins/downloaded/monero/requirements.txt @@ -0,0 +1 @@ +requests \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/news/requirements.txt b/src/honeybot/plugins/downloaded/news/requirements.txt new file mode 100644 index 0000000..a98ae43 --- /dev/null +++ b/src/honeybot/plugins/downloaded/news/requirements.txt @@ -0,0 +1,2 @@ +requests +beautifulsoup4 \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/onthisday/requirements.txt b/src/honeybot/plugins/downloaded/onthisday/requirements.txt new file mode 100644 index 0000000..663bd1f --- /dev/null +++ b/src/honeybot/plugins/downloaded/onthisday/requirements.txt @@ -0,0 +1 @@ +requests \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/pynews/requirements.txt b/src/honeybot/plugins/downloaded/pynews/requirements.txt new file mode 100644 index 0000000..a98ae43 --- /dev/null +++ b/src/honeybot/plugins/downloaded/pynews/requirements.txt @@ -0,0 +1,2 @@ +requests +beautifulsoup4 \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/pypi/requirements.txt b/src/honeybot/plugins/downloaded/pypi/requirements.txt new file mode 100644 index 0000000..a98ae43 --- /dev/null +++ b/src/honeybot/plugins/downloaded/pypi/requirements.txt @@ -0,0 +1,2 @@ +requests +beautifulsoup4 \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/repostats/requirements.txt b/src/honeybot/plugins/downloaded/repostats/requirements.txt new file mode 100644 index 0000000..a98ae43 --- /dev/null +++ b/src/honeybot/plugins/downloaded/repostats/requirements.txt @@ -0,0 +1,2 @@ +requests +beautifulsoup4 \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/story/requirements.txt b/src/honeybot/plugins/downloaded/story/requirements.txt new file mode 100644 index 0000000..a98ae43 --- /dev/null +++ b/src/honeybot/plugins/downloaded/story/requirements.txt @@ -0,0 +1,2 @@ +requests +beautifulsoup4 \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/tpbquote/requirements.txt b/src/honeybot/plugins/downloaded/tpbquote/requirements.txt new file mode 100644 index 0000000..a98ae43 --- /dev/null +++ b/src/honeybot/plugins/downloaded/tpbquote/requirements.txt @@ -0,0 +1,2 @@ +requests +beautifulsoup4 \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/transfer-rumour/requirements.txt b/src/honeybot/plugins/downloaded/transfer-rumour/requirements.txt new file mode 100644 index 0000000..a98ae43 --- /dev/null +++ b/src/honeybot/plugins/downloaded/transfer-rumour/requirements.txt @@ -0,0 +1,2 @@ +requests +beautifulsoup4 \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/translate/requirements.txt b/src/honeybot/plugins/downloaded/translate/requirements.txt new file mode 100644 index 0000000..1f40574 --- /dev/null +++ b/src/honeybot/plugins/downloaded/translate/requirements.txt @@ -0,0 +1,2 @@ +requests +httplib2 \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/weather/requirements.txt b/src/honeybot/plugins/downloaded/weather/requirements.txt new file mode 100644 index 0000000..663bd1f --- /dev/null +++ b/src/honeybot/plugins/downloaded/weather/requirements.txt @@ -0,0 +1 @@ +requests \ No newline at end of file diff --git a/src/honeybot/plugins/downloaded/wikipedia/requirements.txt b/src/honeybot/plugins/downloaded/wikipedia/requirements.txt new file mode 100644 index 0000000..a9bc6c2 --- /dev/null +++ b/src/honeybot/plugins/downloaded/wikipedia/requirements.txt @@ -0,0 +1 @@ +wikipedia \ No newline at end of file