Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
zpriddy committed Apr 16, 2020
1 parent 6359ef6 commit 4d813c8
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 97 deletions.
6 changes: 3 additions & 3 deletions docs-src/glados.bot.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
glados.bot module
=================
Bot
===

.. automodule:: glados.bot
:members:
:undoc-members:
:show-inheritance:
:no-show-inheritance:
4 changes: 2 additions & 2 deletions docs-src/glados.configs.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
glados.configs module
====================
Configs
=======

.. automodule:: glados.configs
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs-src/glados.core.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
glados.core module
==================
Core
====

.. automodule:: glados.core
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs-src/glados.db.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
glados.db module
=================
DataStore
=========

.. automodule:: glados.db
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs-src/glados.errors.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
glados.errors module
====================
Errors
======

.. automodule:: glados.errors
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs-src/glados.message_blocks.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
glados.message\_blocks module
=============================
Message Blocks
==============

.. automodule:: glados.message_blocks
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs-src/glados.plugin.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
glados.plugin module
====================
Plugin
======

.. automodule:: glados.plugin
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs-src/glados.request.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
glados.request module
=====================
Request
=======

.. automodule:: glados.request
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs-src/glados.route_type.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
glados.route\_type module
=========================
Route Type
==========

.. automodule:: glados.route_type
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs-src/glados.router.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
glados.router module
====================
Router
======

.. automodule:: glados.router
:members:
Expand Down
13 changes: 4 additions & 9 deletions docs-src/glados.rst
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
glados package
GLaDOS Package
==============

.. automodule:: glados
:members:
:undoc-members:
:show-inheritance:

Subpackages
-----------

.. toctree::

glados.slack_classes

Submodules
----------

Modules
-------
.. toctree::
:maxdepth: 7

glados.bot
glados.configs
Expand Down
4 changes: 2 additions & 2 deletions docs-src/glados.utils.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
glados.utils module
=====================
Utils
=====

.. automodule:: glados.utils
:members:
Expand Down
2 changes: 1 addition & 1 deletion docs-src/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Installation

The easiest way to install GLaDOS is by using pip

.. code-block:: python
.. code-block:: bash
$ pip3 install glados
7 changes: 3 additions & 4 deletions docs-src/modules.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
glados
======
Modules
=======

.. toctree::
:maxdepth: 6
:maxdepth: 7

glados
glados.bot
glados.configs
glados.core
Expand Down
22 changes: 21 additions & 1 deletion src/glados/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,26 @@


class Glados:
"""Glados is the core of the GLaDOS package."""
"""Glados is the core of the GLaDOS package.
Parameters
----------
config_file
path to config file
plugins_folder
path to plugins folder
bots_config_dir
path to bots config folder
plugins_config_dir
path to plugin config folder.
Notes
-----
If ``config_file`` is passed in and the file has ``plugins_folder``,
``bots_config_dir``, ``plugins_config_dir`` in it , then the other
parameters are not required
"""

def __init__(
self,
Expand All @@ -27,6 +46,7 @@ def __init__(
bots_config_dir: Optional[str] = None,
plugins_config_dir: Optional[str] = None,
):

self.router = GladosRouter()
self.plugins = list() # type: List[GladosPlugin]
self.bots = dict() # type: Dict[str, GladosBot]
Expand Down
95 changes: 47 additions & 48 deletions src/glados/plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable, Dict, Union
from typing import Callable, Dict, Union, List, NoReturn, Any
import yaml
import glob
import logging
Expand Down Expand Up @@ -36,14 +36,32 @@ def to_dict(self):
return dict(name=self.name)


# TODO
# Read the plugin config
# read the user config
# running_config = plugin_config.update(user_config
class PluginConfig:
def __init__(
self, name, config_file, module=None, enabled=False, bot=None, **kwargs
self,
name: str,
config_file: str,
module=None,
enabled=False,
bot=None,
**kwargs,
):
"""
Parameters
----------
name
Plugin Name
config_file
Path to config file for plugin
module
plugin python module name
enabled
enable this plugin
bot
what bot does this plugin use
kwargs
"""
if not bot:
bot = dict()
self.name = name
Expand All @@ -57,7 +75,7 @@ def __init__(
package = package.replace(".config.yaml", "")
self.package = package

def update(self, config: "PluginConfig", use_base_module: bool = True):
def update(self, config: "PluginConfig", use_base_module: bool = True) -> NoReturn:
"""Update a config object using the default values from the config object passed in.
Parameters
Expand All @@ -67,10 +85,6 @@ def update(self, config: "PluginConfig", use_base_module: bool = True):
the base config object only
use_base_module: bool
if set true use the value of module and package from the base config object only.
Returns
-------
"""
config = config.__dict__.copy()
self_config = self.__dict__
Expand All @@ -92,24 +106,21 @@ def to_yaml(self, user_config_only=True):

class PluginImporter:
def __init__(self, plugins_folder: str, plugins_config_folder: str):
"""Create the PluginImporter object."""
self.plugins = dict()
self.plugins_folder = plugins_folder
self.plugins_config_folder = plugins_config_folder
self.config_files = list()
self.plugin_configs = dict() # type: Dict[str, PluginConfig]

def discover_plugins(self):
"""Discover all plugin config files in the plugins folder
Returns
-------
list:
list of all yaml config files
"""
def discover_plugins(self) -> NoReturn:
"""Discover all plugin config files in the plugins folder"""
config_files = glob.glob(f"{self.plugins_folder}/**/*.yaml", recursive=True)
self.config_files = config_files

def load_discovered_plugins_config(self, write_to_user_config=True):
def load_discovered_plugins_config(
self, write_to_user_config: bool = True
) -> NoReturn:
"""Load all the yaml configs for the plugins"""
plugin_package_config = None
plugin_user_config = None
Expand Down Expand Up @@ -163,17 +174,17 @@ def load_discovered_plugins_config(self, write_to_user_config=True):

# TODO(zpriddy): Filter out warnings and errors if importing plugins in a limited way.

def import_discovered_plugins(self, bots: Dict[str, GladosBot]):
def import_discovered_plugins(self, bots: Dict[str, GladosBot]) -> NoReturn:
"""Import all discovered plugins and store them in self.plugins.
Parameters
----------
bots : Dict[str, GladosBot]
bots
dict of all the imported bots
Returns
-------
None:
:obj: `NoReturn`:
the results are updated in self.plugins
"""
Expand Down Expand Up @@ -217,9 +228,9 @@ class GladosPlugin:
Parameters
----------
name : str
the name of the plugin
bot : GladosBot
config
PluginConfig object for the plugin.
bot
the GLaDOS bot that this plugin will use
"""

Expand All @@ -238,21 +249,17 @@ def __init__(self, config: PluginConfig, bot: GladosBot, **kwargs):

def add_route(
self, route_type: RouteType, route: Union[EventRoutes, str], function: Callable
):
) -> NoReturn:
"""Add a new route to the plugin
Parameters
----------
route_type : RouteType
route_type
what type of route this is this
route : Union[EventRoutes, str]
route
what is the route to be added
function : Callable
function
the function to be executed when this route runs
Returns
-------
"""
if type(route) is EventRoutes:
route = route.name
Expand All @@ -265,21 +272,17 @@ def add_route(
)
self._routes[new_route.route_type.value][new_route.route] = new_route

def send_request(self, request: GladosRequest, **kwargs):
def send_request(self, request: GladosRequest, **kwargs) -> Any:
"""This is the function to be called when sending a request to a plugin.
This function is responsible for validating the slack signature if needed. It also returns
and empty string if the function called returns None.
Parameters
----------
request : GladosRequest
request
the request object to be sent
kwargs :
Returns
-------
kwargs
"""
if request.route_type in VERIFY_ROUTES:
self.bot.validate_slack_signature(request)
Expand All @@ -301,6 +304,7 @@ def send_request(self, request: GladosRequest, **kwargs):
return response

def respond_to_url(self, request: GladosRequest, text: str, **kwargs):
"""When you click on a link that was sent via slack it sends a callback, This is to handle that"""
if not request.response_url:
logging.error("no response_url provided in request.")
return
Expand All @@ -309,13 +313,8 @@ def respond_to_url(self, request: GladosRequest, text: str, **kwargs):
logging.info(f"slack response: {r}")

@property
def routes(self):
"""List all routes for the plugin.
Returns
-------
"""
def routes(self) -> List[GladosRoute]:
"""List all routes for the plugin."""
routes = list()
[
routes.extend(route_object)
Expand Down

0 comments on commit 4d813c8

Please sign in to comment.