Skip to content

Commit

Permalink
Restructure using source layout for pypi packaging.
Browse files Browse the repository at this point in the history
  • Loading branch information
nzlosh committed Oct 26, 2022
1 parent 98d68f9 commit 2a62ce8
Show file tree
Hide file tree
Showing 25 changed files with 100 additions and 106 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include src/err-stackstorm/*.plug
include src/err-stackstorm/html/*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
45 changes: 45 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
]
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

20 changes: 0 additions & 20 deletions setup.py

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/config.py → src/err-stackstorm/errst2lib/config.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/session.py → src/err-stackstorm/errst2lib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
98 changes: 32 additions & 66 deletions st2.py → src/err-stackstorm/st2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
),
)
3 changes: 0 additions & 3 deletions version.json

This file was deleted.

0 comments on commit 2a62ce8

Please sign in to comment.