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.
This commit is contained in:
Hemna 2021-01-12 15:59:13 -05:00
parent 2a7167745b
commit 36b2eff71c
14 changed files with 132 additions and 20 deletions

2
.gitignore vendored
View File

@ -11,4 +11,4 @@ venv
dist
.pytest_cache
.mypy_cache
build
build

47
.pre-commit-config.yaml Normal file
View File

@ -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]

1
AUTHORS Normal file
View File

@ -0,0 +1 @@
Hemna <waboring@hemna.com>

View File

@ -1,6 +1,11 @@
CHANGES
=======
v1.0.3
------
* Plugin gets the version from pbr version now
v1.0.2
------

View File

@ -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.

58
Makefile Normal file
View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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:<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: <name> "
"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))

View File

@ -9,3 +9,4 @@ isort
pbr
Sphinx
aprsd
pre-commit

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#

View File

@ -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

View File

@ -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 =

View File

@ -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)