Skip to content

Commit

Permalink
Cleanup documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
zpriddy committed Apr 16, 2020
1 parent bba4c59 commit 6359ef6
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 202 deletions.
1 change: 0 additions & 1 deletion docs-src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"sphinx.ext.napoleon",
"sphinx.ext.autodoc",
"sphinx_rtd_theme",
#"sphinx.ext.autodoc.typehints",
"sphinx_autodoc_typehints",
"sphinx.ext.viewcode",
"sphinx.ext.autosummary",
Expand Down
1 change: 1 addition & 0 deletions docs-src/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ glados
.. toctree::
:maxdepth: 6

glados
glados.bot
glados.configs
glados.core
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = glados
version = 0.0.1-dev15
version = 0.0.1-dev17
description = A library to help with slackbot development
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
1 change: 0 additions & 1 deletion src/glados/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def sections(self) -> List[str]:
Returns
-------
List[str]:
sorted list of sections in the yaml file
"""
if not self.config:
Expand Down
58 changes: 31 additions & 27 deletions src/glados/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Dict, TYPE_CHECKING, Optional
from typing import List, Dict, TYPE_CHECKING, Optional, NoReturn
import yaml
import logging

Expand All @@ -22,10 +22,10 @@ class Glados:

def __init__(
self,
config_file=None,
plugins_folder=None,
bots_config_dir=None,
plugins_config_dir=None,
config_file: Optional[str] = None,
plugins_folder: Optional[str] = None,
bots_config_dir: Optional[str] = None,
plugins_config_dir: Optional[str] = None,
):
self.router = GladosRouter()
self.plugins = list() # type: List[GladosPlugin]
Expand All @@ -41,7 +41,15 @@ def __init__(
self.enable_datastore = False
self.datastore = None # type: Optional[DataStore]

def read_config(self, bot_name=None):
def read_config(self, bot_name: Optional[str] = None) -> NoReturn:
"""Read the GLaDOS config file. If a bot name is provided it will only install that bot. Else it will install all bots.
Parameters
----------
bot_name
If provided, install only the bot with this name.
"""
# TODO: Fix logging setup
if not self.config_file:
logging.info("glados config file not set.")
Expand Down Expand Up @@ -113,16 +121,22 @@ def read_config(self, bot_name=None):
logging.warning("datastore section not found in config file")
self.enable_datastore = False

def import_bots(self):
def import_bots(self) -> NoReturn:
"""Import all discovered bots"""
logging.info("importing bots...")
importer = BotImporter(self.bots_config_dir)
importer.import_bots()
self.bots = importer.bots.copy()
logging.info(f"successfully imported {len(self.bots)} bots")

def import_plugins(self, bot_name=None):
"""Import all discovered plugins and add them to the plugin list."""
def import_plugins(self, bot_name: Optional[str] = None) -> NoReturn:
"""Import all discovered plugins and add them to the plugin list.
Parameters
----------
bot_name
If set GLaDOS will only import the bot name that is provided here.
"""
logging.info("Importing plugins...")
importer = PluginImporter(self.plugins_folder, self.plugins_config_dir)
importer.discover_plugins()
Expand All @@ -146,56 +160,46 @@ def import_plugins(self, bot_name=None):
self.add_plugin(plugin)
logging.info(f"successfully imported {len(self.plugins)} plugins")

def add_plugin(self, plugin: GladosPlugin):
def add_plugin(self, plugin: GladosPlugin) -> NoReturn:
"""Add a plugin to GLaDOS
Parameters
----------
plugin : GladosPlugin
plugin
the plugin to be added to GLaDOS
Returns
-------
"""
logging.debug(f"installing plugin: {plugin.name}")
self.plugins.append(plugin)
self.router.add_routes(plugin)

def add_bot(self, bot: GladosBot):
def add_bot(self, bot: GladosBot) -> NoReturn:
"""Add a new bot to GLaDOS.
Parameters
----------
bot : GladosBot
bot
the bot to be added to GLaDOS
Returns
-------
"""
self.bots[bot.name] = bot

def has_datastore(self):
def has_datastore(self) -> bool:
"""Returns True if there is a datastore else False"""
return (
True
if self.enable_datastore is True and self.datastore is not None
else False
)

def request(self, request: GladosRequest):
"""Send a request to GLaDOS.
"""Send a request to GLaDOS. This returns whatever the plugin returns.
This function will also set the datastore session for the request, try to find the interaction in the datastore and fetch it. This info is available in the request.
Parameters
----------
request : GladosRequest
request
the request to be sent to GLaDOS
Returns
-------
"""
# DataStore actions if enabled
if self.has_datastore():
Expand Down

0 comments on commit 6359ef6

Please sign in to comment.