From 2a62ce87a444859215a9ff139a7e26a6020f8137 Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 26 Oct 2022 23:38:32 +0200 Subject: [PATCH] Restructure using source layout for pypi packaging. --- CHANGELOG.md | 9 +- MANIFEST.in | 2 + README.md | 2 +- pyproject.toml | 45 ++++++++ requirements.txt | 3 - setup.py | 20 ---- .../err-stackstorm/errst2lib}/__init__.py | 0 .../errst2lib}/authentication_controller.py | 6 +- .../errst2lib}/authentication_handler.py | 6 +- .../errst2lib}/chat_adapters.py | 0 .../err-stackstorm/errst2lib}/config.py | 4 +- .../errst2lib}/credentials_adapters.py | 0 .../err-stackstorm/errst2lib}/enquiry.py | 0 .../err-stackstorm/errst2lib}/errors.py | 0 .../err-stackstorm/errst2lib}/session.py | 2 +- .../errst2lib}/session_manager.py | 6 +- .../errst2lib}/stackstorm_api.py | 0 .../errst2lib}/store_adapters.py | 0 .../err-stackstorm/errst2lib}/version.py | 0 .../err-stackstorm/html}/errbot_icon.png | Bin {html => src/err-stackstorm/html}/index.html | 0 .../err-stackstorm/html}/st2_logo.png | Bin st2.plug => src/err-stackstorm/st2.plug | 0 st2.py => src/err-stackstorm/st2.py | 98 ++++++------------ version.json | 3 - 25 files changed, 100 insertions(+), 106 deletions(-) create mode 100644 MANIFEST.in create mode 100644 pyproject.toml delete mode 100644 requirements.txt delete mode 100644 setup.py rename {lib => src/err-stackstorm/errst2lib}/__init__.py (100%) rename {lib => src/err-stackstorm/errst2lib}/authentication_controller.py (97%) rename {lib => src/err-stackstorm/errst2lib}/authentication_handler.py (98%) rename {lib => src/err-stackstorm/errst2lib}/chat_adapters.py (100%) rename {lib => src/err-stackstorm/errst2lib}/config.py (96%) rename {lib => src/err-stackstorm/errst2lib}/credentials_adapters.py (100%) rename {lib => src/err-stackstorm/errst2lib}/enquiry.py (100%) rename {lib => src/err-stackstorm/errst2lib}/errors.py (100%) rename {lib => src/err-stackstorm/errst2lib}/session.py (98%) rename {lib => src/err-stackstorm/errst2lib}/session_manager.py (92%) rename {lib => src/err-stackstorm/errst2lib}/stackstorm_api.py (100%) rename {lib => src/err-stackstorm/errst2lib}/store_adapters.py (100%) rename {lib => src/err-stackstorm/errst2lib}/version.py (100%) rename {html => src/err-stackstorm/html}/errbot_icon.png (100%) rename {html => src/err-stackstorm/html}/index.html (100%) rename {html => src/err-stackstorm/html}/st2_logo.png (100%) rename st2.plug => src/err-stackstorm/st2.plug (100%) rename st2.py => src/err-stackstorm/st2.py (89%) delete mode 100644 version.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bcb3a0..03aff42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [2.3.0] Unreleased ### Added + - Proof of concept for enquiry support. + ### Changed + - Restructured source layout for pypi packaging. + - Restructured and updated documentation. + - Switched from setup.py to pyproject.toml + ### Removed + - Removed `check_latest_version` function. ## [2.2.0] 2021-11-27 ### Added diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..d9d43aa --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include src/err-stackstorm/*.plug +include src/err-stackstorm/html/* diff --git a/README.md b/README.md index 0c39124..2215968 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # err-stackstorm -A plugin to bring StackStorm ChatOps to Errbot. +StackStorm ChatOps for Errbot. [![CircleCI](https://circleci.com/gh/nzlosh/err-stackstorm.svg?style=svg)](https://circleci.com/gh/nzlosh/err-stackstorm) [![Documentation Status](https://readthedocs.org/projects/err-stackstorm/badge/?version=latest)](https://err-stackstorm.readthedocs.io/en/latest/?badge=latest) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..7433ad4 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,45 @@ +[build-system] +requires = [ + "setuptools>=61.0" +] +build-backend = "setuptools.build_meta" + +[project] +name = "err-stackstorm" +version = "2.2.1" +authors = [{ name="Err-stackstorm maintainers", email="nzlosh@yahoo.com" }] +keywords = [ + "errbot", + "stackstorm", +] +description = "StackStorm ChatOps for Errbot" +readme = "README.md" +requires-python = ">=3.7" + +license = {text = "Apache-2.0"} + +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", +] + +dependencies = [ + "requests>=2.20.0", + "sseclient", + "jsonschema", +] + +[project.urls] +"Homepage" = "https://github.com/nzlosh/err-stackstorm" +"Bug Tracker" = "https://github.com/nzlosh/err-stackstorm/issues" +"Documentation" = "https://err-stackstorm.readthedocs.io/" + +[tool.setuptools] +# available as beta since setuptools version 61.0.0 +include-package-data = true + +[tool.pytest.ini_options] +pythonpath = [ + "src/err-stackstorm" +] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index af8bba4..0000000 --- a/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -requests>=2.20.0 -sseclient -jsonschema diff --git a/setup.py b/setup.py deleted file mode 100644 index e7cf0ba..0000000 --- a/setup.py +++ /dev/null @@ -1,20 +0,0 @@ -import setuptools - -from lib.version import ERR_STACKSTORM_VERSION - -setuptools.setup( - name="err-stackstorm", - version=ERR_STACKSTORM_VERSION, - author="Err-StackStorm Plugin contributors", - author_email="nzlosh@yahoo.com", - description="An Errbot plugin for StackStorm ChatOps.", - long_description="Not available", - long_description_content_type="text/markdown", - url="https://github.com/nzlosh/err-stackstorm", - packages=setuptools.find_packages(), - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: Apache 2.0 License", - "Operating System :: OS Independent", - ], -) diff --git a/lib/__init__.py b/src/err-stackstorm/errst2lib/__init__.py similarity index 100% rename from lib/__init__.py rename to src/err-stackstorm/errst2lib/__init__.py diff --git a/lib/authentication_controller.py b/src/err-stackstorm/errst2lib/authentication_controller.py similarity index 97% rename from lib/authentication_controller.py rename to src/err-stackstorm/errst2lib/authentication_controller.py index a4e5ff5..4547d0b 100644 --- a/lib/authentication_controller.py +++ b/src/err-stackstorm/errst2lib/authentication_controller.py @@ -3,9 +3,9 @@ from errbot.backends.base import Identifier -from lib.errors import SessionInvalidError -from lib.session import generate_password -from lib.session_manager import SessionManager +from errst2lib.errors import SessionInvalidError +from errst2lib.session import generate_password +from errst2lib.session_manager import SessionManager LOG = logging.getLogger("errbot.plugin.st2.auth_ctrl") diff --git a/lib/authentication_handler.py b/src/err-stackstorm/errst2lib/authentication_handler.py similarity index 98% rename from lib/authentication_handler.py rename to src/err-stackstorm/errst2lib/authentication_handler.py index 7a8df15..3225d22 100644 --- a/lib/authentication_handler.py +++ b/src/err-stackstorm/errst2lib/authentication_handler.py @@ -5,9 +5,9 @@ import requests -from lib.authentication_controller import BotPluginIdentity -from lib.credentials_adapters import St2ApiKey, St2UserCredentials, St2UserToken -from lib.errors import SessionInvalidError +from errst2lib.authentication_controller import BotPluginIdentity +from errst2lib.credentials_adapters import St2ApiKey, St2UserCredentials, St2UserToken +from errst2lib.errors import SessionInvalidError LOG = logging.getLogger("errbot.plugin.st2.auth_handler") diff --git a/lib/chat_adapters.py b/src/err-stackstorm/errst2lib/chat_adapters.py similarity index 100% rename from lib/chat_adapters.py rename to src/err-stackstorm/errst2lib/chat_adapters.py diff --git a/lib/config.py b/src/err-stackstorm/errst2lib/config.py similarity index 96% rename from lib/config.py rename to src/err-stackstorm/errst2lib/config.py index afe1d41..fb4f27c 100644 --- a/lib/config.py +++ b/src/err-stackstorm/errst2lib/config.py @@ -1,8 +1,8 @@ # coding:utf-8 import logging -from lib.authentication_handler import AuthHandlerFactory -from lib.credentials_adapters import CredentialsFactory +from errst2lib.authentication_handler import AuthHandlerFactory +from errst2lib.credentials_adapters import CredentialsFactory LOG = logging.getLogger(__name__) diff --git a/lib/credentials_adapters.py b/src/err-stackstorm/errst2lib/credentials_adapters.py similarity index 100% rename from lib/credentials_adapters.py rename to src/err-stackstorm/errst2lib/credentials_adapters.py diff --git a/lib/enquiry.py b/src/err-stackstorm/errst2lib/enquiry.py similarity index 100% rename from lib/enquiry.py rename to src/err-stackstorm/errst2lib/enquiry.py diff --git a/lib/errors.py b/src/err-stackstorm/errst2lib/errors.py similarity index 100% rename from lib/errors.py rename to src/err-stackstorm/errst2lib/errors.py diff --git a/lib/session.py b/src/err-stackstorm/errst2lib/session.py similarity index 98% rename from lib/session.py rename to src/err-stackstorm/errst2lib/session.py index 88fd17f..fcfe870 100644 --- a/lib/session.py +++ b/src/err-stackstorm/errst2lib/session.py @@ -6,7 +6,7 @@ from datetime import datetime as dt from random import SystemRandom -from lib.errors import SessionConsumedError, SessionExpiredError +from errst2lib.errors import SessionConsumedError, SessionExpiredError LOG = logging.getLogger("errbot.plugin.st2.session") diff --git a/lib/session_manager.py b/src/err-stackstorm/errst2lib/session_manager.py similarity index 92% rename from lib/session_manager.py rename to src/err-stackstorm/errst2lib/session_manager.py index e20619e..57e5552 100644 --- a/lib/session_manager.py +++ b/src/err-stackstorm/errst2lib/session_manager.py @@ -1,9 +1,9 @@ # coding:utf-8 import logging -from lib.errors import SessionExistsError, SessionInvalidError -from lib.session import Session -from lib.store_adapters import SessionStore, StoreAdapterFactory +from errst2lib.errors import SessionExistsError, SessionInvalidError +from errst2lib.session import Session +from errst2lib.store_adapters import SessionStore, StoreAdapterFactory LOG = logging.getLogger("errbot.plugin.st2.session_mgr") diff --git a/lib/stackstorm_api.py b/src/err-stackstorm/errst2lib/stackstorm_api.py similarity index 100% rename from lib/stackstorm_api.py rename to src/err-stackstorm/errst2lib/stackstorm_api.py diff --git a/lib/store_adapters.py b/src/err-stackstorm/errst2lib/store_adapters.py similarity index 100% rename from lib/store_adapters.py rename to src/err-stackstorm/errst2lib/store_adapters.py diff --git a/lib/version.py b/src/err-stackstorm/errst2lib/version.py similarity index 100% rename from lib/version.py rename to src/err-stackstorm/errst2lib/version.py diff --git a/html/errbot_icon.png b/src/err-stackstorm/html/errbot_icon.png similarity index 100% rename from html/errbot_icon.png rename to src/err-stackstorm/html/errbot_icon.png diff --git a/html/index.html b/src/err-stackstorm/html/index.html similarity index 100% rename from html/index.html rename to src/err-stackstorm/html/index.html diff --git a/html/st2_logo.png b/src/err-stackstorm/html/st2_logo.png similarity index 100% rename from html/st2_logo.png rename to src/err-stackstorm/html/st2_logo.png diff --git a/st2.plug b/src/err-stackstorm/st2.plug similarity index 100% rename from st2.plug rename to src/err-stackstorm/st2.plug diff --git a/st2.py b/src/err-stackstorm/st2.py similarity index 89% rename from st2.py rename to src/err-stackstorm/st2.py index 0f2e99c..a701084 100644 --- a/st2.py +++ b/src/err-stackstorm/st2.py @@ -9,20 +9,20 @@ import requests from errbot import BotPlugin, Command, arg_botcmd, botcmd, re_botcmd, webhook -from lib.authentication_controller import AuthenticationController, BotPluginIdentity -from lib.authentication_handler import AuthHandlerFactory, ClientSideAuthHandler -from lib.chat_adapters import ChatAdapterFactory -from lib.config import PluginConfiguration -from lib.credentials_adapters import St2ApiKey, St2UserCredentials, St2UserToken -from lib.enquiry import Enquiry, EnquiryManager -from lib.errors import ( +from errst2lib.authentication_controller import AuthenticationController, BotPluginIdentity +from errst2lib.authentication_handler import AuthHandlerFactory, ClientSideAuthHandler +from errst2lib.chat_adapters import ChatAdapterFactory +from errst2lib.config import PluginConfiguration +from errst2lib.credentials_adapters import St2ApiKey, St2UserCredentials, St2UserToken +from errst2lib.enquiry import Enquiry, EnquiryManager +from errst2lib.errors import ( SessionConsumedError, SessionExistsError, SessionExpiredError, SessionInvalidError, ) -from lib.stackstorm_api import StackStormAPI -from lib.version import ERR_STACKSTORM_VERSION +from errst2lib.stackstorm_api import StackStormAPI +from errst2lib.version import ERR_STACKSTORM_VERSION LOG = logging.getLogger("errbot.plugin.st2") @@ -64,32 +64,6 @@ def __init__(self, bot, name): self.run_listener = True self.st2events_listener = None - def check_latest_version(self): - url = "https://raw.githubusercontent.com/nzlosh/err-stackstorm/master/version.json" - try: - response = requests.get(url, timeout=5) - - if response.status_code != 200: - LOG.warning( - "Unable to fetch err-stackstorm version from {}. HTTP code: {}".format( - url, response.status_code - ) - ) - return True - except Exception as err: - LOG.warning("Exception checking version from {}. {}".format(url, err)) - return True - - latest = response.json().get("version") - if latest is None: - LOG.warning("Failed to read err-stackstorm 'version' from {}.".format(url)) - return True - - if ERR_STACKSTORM_VERSION != latest: - LOG.info("err-stackstorm can be updated to {}.".format(latest)) - else: - LOG.info("err-stackstorm {} is up to date.".format(ERR_STACKSTORM_VERSION)) - def authenticate_bot_credentials(self): """ Create a session and associate valid StackStorm credentials with it for the bot to use. @@ -153,7 +127,6 @@ def activate(self): LOG.info("Activate St2 plugin") self.dynamic_commands() - self.check_latest_version() self.start_poller(self.cfg.timer_update, self.validate_bot_credentials) self.st2events_listener = threading.Thread( @@ -272,16 +245,8 @@ def enquiry_reply(self, msg, args_str): if len(args) == 0: yield "Respond to what?" return + # TODO : Implement logic to use enquiry context to select next question. - if args[0] == "reply": - yield "Let me get the current enquiry" - yield "Here's the next question ..." - elif args[0] == "full": - yield "Expect to be given a valid JSON object" - elif args[0].startswith("q"): - yield "Answering specific question" - else: - yield "Sorry, I don't know what you mean" # ~ chat_user = msg.frm # ~ st2token, err_msg = self.get_token(chat_user) # ~ if st2token is False: @@ -623,27 +588,28 @@ def enquiry_reply(plugin, msg, args): doc=f"Usage: {self.cfg.plugin_prefix}enquiry_list\n" "List enquiries awaiting respond.", ), - Command( - lambda plugin, msg, args: self.enquiry_get(msg, args), - name=f"{self.cfg.plugin_prefix}enquiry_get", - cmd_type=botcmd, - cmd_kwargs={"admin_only": False}, - doc=f"Usage: {self.cfg.plugin_prefix}enquiry_get\n" "View an enquiry.", - ), - Command( - lambda plugin, msg, args: self.enquiry_set(msg, args), - name=f"{self.cfg.plugin_prefix}enquiry_set", - cmd_type=botcmd, - cmd_kwargs={"admin_only": False}, - doc=f"Usage: {self.cfg.plugin_prefix}enquiry_set\n" "Set an active enquiry.", - ), - Command( - enquiry_reply, - name=f"{self.cfg.plugin_prefix}enquiry_reply", - cmd_type=botcmd, - cmd_kwargs={"admin_only": False}, - doc=f"Usage: {self.cfg.plugin_prefix}enquiry_reply\n" "Respond to an enquiry.", - ), + # TODO: Add the enquiry code when it's completed. + # ~ Command( + # ~ lambda plugin, msg, args: self.enquiry_get(msg, args), + # ~ name=f"{self.cfg.plugin_prefix}enquiry_get", + # ~ cmd_type=botcmd, + # ~ cmd_kwargs={"admin_only": False}, + # ~ doc=f"Usage: {self.cfg.plugin_prefix}enquiry_get\n" "View an enquiry.", + # ~ ), + # ~ Command( + # ~ lambda plugin, msg, args: self.enquiry_set(msg, args), + # ~ name=f"{self.cfg.plugin_prefix}enquiry_set", + # ~ cmd_type=botcmd, + # ~ cmd_kwargs={"admin_only": False}, + # ~ doc=f"Usage: {self.cfg.plugin_prefix}enquiry_set\n" "Set an active enquiry.", + # ~ ), + # ~ Command( + # ~ enquiry_reply, + # ~ name=f"{self.cfg.plugin_prefix}enquiry_reply", + # ~ cmd_type=botcmd, + # ~ cmd_kwargs={"admin_only": False}, + # ~ doc=f"Usage: {self.cfg.plugin_prefix}enquiry_reply\n" "Respond to an enquiry.", + # ~ ), Help_Command, ), ) diff --git a/version.json b/version.json deleted file mode 100644 index 0f8325f..0000000 --- a/version.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "version": "2.2.0" -}