From 36b2eff71c5c1bf23e34761a64c66361c1efd4aa Mon Sep 17 00:00:00 2001 From: Hemna Date: Tue, 12 Jan 2021 15:59:13 -0500 Subject: [PATCH] Added Makefile, pre-commit. Also update for 1.5.0 This patch Adds the Makefile for setting up a dev environment as well as fixing the plugin for the 1.5.0 release of aprsd. --- .gitignore | 2 +- .pre-commit-config.yaml | 47 +++++++++++++++++++ AUTHORS | 1 + ChangeLog | 5 ++ LICENSE.txt | 1 - Makefile | 58 ++++++++++++++++++++++++ README.rst | 2 +- aprsd_slack_plugin/__init__.py | 2 - aprsd_slack_plugin/aprsd_slack_plugin.py | 14 +++--- dev-requirements.in | 1 + docs/conf.py | 1 - requirements.txt | 2 +- setup.cfg | 12 +++-- tests/test_plugin.py | 4 +- 14 files changed, 132 insertions(+), 20 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 AUTHORS create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index b491a90..7a4c686 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,4 @@ venv dist .pytest_cache .mypy_cache -build \ No newline at end of file +build diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..42761b3 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,47 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: detect-private-key + - id: check-merge-conflict + - id: check-case-conflict + - id: check-docstring-first + - id: check-builtin-literals + +- repo: https://github.com/asottile/setup-cfg-fmt + rev: v1.16.0 + hooks: + - id: setup-cfg-fmt + +- repo: https://github.com/asottile/add-trailing-comma + rev: v2.0.2 + hooks: + - id: add-trailing-comma + args: [--py36-plus] + +- repo: https://github.com/asottile/pyupgrade + rev: v2.7.4 + hooks: + - id: pyupgrade + args: + - --py3-plus + +- repo: https://github.com/pre-commit/mirrors-isort + rev: v5.7.0 + hooks: + - id: isort + +- repo: https://github.com/psf/black + rev: 20.8b1 + hooks: + - id: black + +- repo: https://gitlab.com/pycqa/flake8 + rev: 3.8.4 + hooks: + - id: flake8 + additional_dependencies: [flake8-bugbear] diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..cc71ac7 --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Hemna diff --git a/ChangeLog b/ChangeLog index fffa439..8b7d79b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,11 @@ CHANGES ======= +v1.0.3 +------ + +* Plugin gets the version from pbr version now + v1.0.2 ------ diff --git a/LICENSE.txt b/LICENSE.txt index 68c771a..67db858 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -173,4 +173,3 @@ defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..469a129 --- /dev/null +++ b/Makefile @@ -0,0 +1,58 @@ +.PHONY: virtual dev build-requirements black isort flake8 + +all: pip dev + +virtual: .venv/bin/pip # Creates an isolated python 3 environment + +.venv/bin/pip: + virtualenv -p /usr/bin/python3 .venv + +.venv/bin/aprsd: virtual + test -s .venv/bin/aprsd || .venv/bin/pip install -q -e . + +install: virtual + .venv/bin/pip install -Ur requirements.txt + +dev-pre-commit: + test -s .git/hooks/pre-commit || .venv/bin/pre-commit install + +dev-requirements: + test -s .venv/bin/twine || .venv/bin/pip install -q -r dev-requirements.txt + +pip: virtual + .venv/bin/pip install -q -U pip + +dev: pip install dev-requirements dev-pre-commit + +pip-tools: + test -s .venv/bin/pip-compile || .venv/bin/pip install pip-tools + +clean: + rm -rf dist/* + rm -rf .venv + +test: dev + .venv/bin/pre-commit run --all-files + tox -p + +build: test + rm -rf dist/* + .venv/bin/python3 setup.py sdist bdist_wheel + .venv/bin/twine check dist/* + +upload: build + .venv/bin/twine upload dist/* + +update-requirements: dev pip-tools + .venv/bin/pip-compile -q -U requirements.in + .venv/bin/pip-compile -q -U dev-requirements.in + +.venv/bin/tox: # install tox + test -s .venv/bin/tox || .venv/bin/pip install -q -U tox + +check: .venv/bin/tox # Code format check with isort and black + tox -efmt-check + tox -epep8 + +fix: .venv/bin/tox # fixes code formatting with isort and black + tox -efmt diff --git a/README.rst b/README.rst index cc80111..8c572a4 100644 --- a/README.rst +++ b/README.rst @@ -10,7 +10,7 @@ aprsd_slack_plugin .. image:: https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336 :target: https://timothycrosley.github.io/isort/ -This project is a python plugin for the APRSD server daemon written by +This project is a python plugin for the APRSD server daemon written by Craig Lamparter. The plugin looks for location APRS commands from a ham radio, then reports that location to a slack channel. This is basically a location proxy. diff --git a/aprsd_slack_plugin/__init__.py b/aprsd_slack_plugin/__init__.py index 5407727..c0094f0 100644 --- a/aprsd_slack_plugin/__init__.py +++ b/aprsd_slack_plugin/__init__.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at diff --git a/aprsd_slack_plugin/aprsd_slack_plugin.py b/aprsd_slack_plugin/aprsd_slack_plugin.py index 01448d0..c8bb940 100644 --- a/aprsd_slack_plugin/aprsd_slack_plugin.py +++ b/aprsd_slack_plugin/aprsd_slack_plugin.py @@ -1,6 +1,7 @@ import logging from aprsd import plugin +from aprsd.plugins import location as location_plugin from slack_sdk import WebClient from slack_sdk.errors import SlackApiError @@ -59,7 +60,7 @@ class SlackCommandPlugin(plugin.APRSDPluginBase): LOG.error( "APRSD config is missing slack: bot_token:. " "Please install the slack app and get the " - "Bot User OAth Access Token." + "Bot User OAth Access Token.", ) return False @@ -69,7 +70,7 @@ class SlackCommandPlugin(plugin.APRSDPluginBase): if not self.slack_channel: LOG.error( "APRSD config is missing slack: slack_channel: " - "Please add a slack channel name to send messages." + "Please add a slack channel name to send messages.", ) return False @@ -83,8 +84,8 @@ class SlackCommandPlugin(plugin.APRSDPluginBase): return # now call the location plugin to get the location info - location_plugin = plugin.LocationPlugin(self.config) - location = location_plugin.command(fromcall, message, ack) + lp = location_plugin.LocationPlugin(self.config) + location = lp.command(fromcall, message, ack) if location: reply = location @@ -94,8 +95,9 @@ class SlackCommandPlugin(plugin.APRSDPluginBase): except SlackApiError as e: LOG.error( "Failed to send message to channel '{}' because '{}'".format( - self.slack_channel, str(e) - ) + self.slack_channel, + str(e), + ), ) else: LOG.debug("SlackCommandPlugin couldn't get location for '{}'".format(fromcall)) diff --git a/dev-requirements.in b/dev-requirements.in index e3b4e76..b4fc8da 100644 --- a/dev-requirements.in +++ b/dev-requirements.in @@ -9,3 +9,4 @@ isort pbr Sphinx aprsd +pre-commit diff --git a/docs/conf.py b/docs/conf.py index 434cf9d..0faf919 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Configuration file for the Sphinx documentation builder. # diff --git a/requirements.txt b/requirements.txt index 9ad168e..0a7accd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ # # pip-compile # -aprsd # via -r requirements.in +aprsd>=1.5.0 # via -r requirements.in pbr # via -r requirements.in, aprsd requests # via aprsd six # via aprsd, click-completion, imapclient diff --git a/setup.cfg b/setup.cfg index 96de98f..3b7d511 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,11 +1,10 @@ [metadata] name = aprsd_slack_plugin -summary = Amateur radio APRS daemon which listens for messages and responds -description-file = - README.rst -long-description-content-type = text/x-rst; charset=UTF-8 +long_description = file: README.rst +long_description_content_type = text/x-rst author = Walter A. Boring IV -author-email = something@somewhere.com +author_email = something@somewhere.com +license_file = LICENSE.txt classifier = Topic :: Communications :: Ham Radio Operating System :: POSIX :: Linux @@ -14,6 +13,9 @@ classifier = Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 +description_file = + README.rst +summary = Amateur radio APRS daemon which listens for messages and responds [global] setup-hooks = diff --git a/tests/test_plugin.py b/tests/test_plugin.py index ecee105..9d6e4bb 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -6,7 +6,7 @@ from aprsd_slack_plugin import aprsd_slack_plugin as slack_plugin if sys.version_info >= (3, 2): from unittest import mock else: - import mock + from unittest import mock class TestPlugin(unittest.TestCase): @@ -15,7 +15,7 @@ class TestPlugin(unittest.TestCase): mock_command.return_value = "" config = { - "slack": {"signing_secret": "something", "bot_token": "sometoken", "channel": "hemna"} + "slack": {"signing_secret": "something", "bot_token": "sometoken", "channel": "hemna"}, } p = slack_plugin.SlackCommandPlugin(config)