From 75f610d9710e155beb3b32f679514d2d8c482064 Mon Sep 17 00:00:00 2001 From: Hemna Date: Wed, 6 Jan 2021 17:50:02 -0500 Subject: [PATCH] Added pre-commit hooks This patch adds pre-commit hook support to ensure code passes basic checks prior to allowing a commit. --- .pre-commit-config.yaml | 18 ++++++++++++++++++ ChangeLog | 2 ++ INSTALL.txt | 2 +- README.rst | 15 +++++++-------- aprsd/main.py | 5 +---- aprsd/messaging.py | 5 +---- aprsd/plugin.py | 2 +- tests/test_main.py | 4 +--- tests/test_plugin.py | 11 ++++------- tox.ini | 4 ++-- 10 files changed, 38 insertions(+), 30 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..8f4e04d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,18 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files +- repo: https://github.com/psf/black + rev: 19.3b0 + hooks: + - id: black + +- repo: https://gitlab.com/pycqa/flake8 + rev: 3.8.1 + hooks: + - id: flake8 + additional_dependencies: [flake8-bugbear] diff --git a/ChangeLog b/ChangeLog index b49b2d0..51d5364 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ CHANGES v1.5.0 ------ +* Added pre-commit hooks +* Update Changelog for v1.5.0 * Added QueryPlugin resend all delayed msgs or Flush * Added QueryPlugin * Added support to save/load MsgTrack on exit/start diff --git a/INSTALL.txt b/INSTALL.txt index aae80b3..41d77a1 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -17,7 +17,7 @@ cd ~/.venv_aprsd ./bin/aprsd # generates a config.yml template on first run -vi ~/.aprsd/config.yml +vi ~/.aprsd/config.yml ./bin/aprsd diff --git a/README.rst b/README.rst index 5c8e02e..a616292 100644 --- a/README.rst +++ b/README.rst @@ -17,7 +17,7 @@ Listen on amateur radio aprs-is network for messages and respond to them. You must have an amateur radio callsign to use this software. APRSD gets messages for the configured HAM callsign, and sends those messages to a list of plugins for processing. There are a set of core plugins that -provide responding to messages to check email, get location, ping, +provide responding to messages to check email, get location, ping, time of day, get weather, and fortune telling as well as version information of aprsd itself. @@ -25,7 +25,7 @@ Typical use case ================ Ham radio operator using an APRS enabled HAM radio sends a message to check -the weather. an APRS message is sent, and then picked up by APRSD. The +the weather. an APRS message is sent, and then picked up by APRSD. The APRS packet is decoded, and the message is sent through the list of plugins for processing. The WeatherPlugin picks up the message, fetches the weather for the area around the user who sent the request, and then responds with @@ -38,7 +38,7 @@ APRSD Capabilities * server - The main aprsd server processor. Send/Rx APRS messages to HAM callsign * send-message - use aprsd to send a command/message to aprsd server. Used for development testing -* sample-config - generate a sample aprsd.yml config file for use/editing +* sample-config - generate a sample aprsd.yml config file for use/editing * bash completion generation. Uses python click bash completion to generate completion code for your .bashrc/.zshrc @@ -173,7 +173,7 @@ Output server ====== -This is the main server command that will listen to APRS-IS servers and +This is the main server command that will listen to APRS-IS servers and look for incomming commands to the callsign configured in the config file :: @@ -319,12 +319,12 @@ LOCATION Sending message_______________ 7(Tx3) Raw : KM6XXX-9>APRS::KM6XXX :8 Miles NE Auburn CA 1673' 39.91150,-120.93450 0.1h ago{7 - To : KM6XXX + To : KM6XXX Message : 8 Miles E Auburn CA 1673' 38.91150,-120.93450 0.1h ago Sending ack __________________ Tx(3) Raw : KM6XXX-9>APRS::KM6XXX :ack28 - To : KM6XXX + To : KM6XXX Ack number : 28 Received message______________ @@ -356,7 +356,7 @@ Release To do release to pypi: -* Tag release with +* Tag release with git tag -v1.XX -m "New release" @@ -414,4 +414,3 @@ Provide a csv list of pypi installable plugins. Then make sure the plugin python file is in your /plugins volume and the plugin will be installed at container startup. The plugin may have dependencies that are required. The plugin file should be copied to /plugins for loading by aprsd - diff --git a/aprsd/main.py b/aprsd/main.py index 416c996..2e58e5a 100644 --- a/aprsd/main.py +++ b/aprsd/main.py @@ -383,10 +383,7 @@ def server(loglevel, quiet, disable_validation, config_file, flush): rx_msg_queue = queue.Queue(maxsize=20) tx_msg_queue = queue.Queue(maxsize=20) - msg_queues = { - "rx": rx_msg_queue, - "tx": tx_msg_queue, - } + msg_queues = {"rx": rx_msg_queue, "tx": tx_msg_queue} rx_thread = threads.APRSDRXThread(msg_queues=msg_queues, config=config) tx_thread = threads.APRSDTXThread(msg_queues=msg_queues, config=config) diff --git a/aprsd/messaging.py b/aprsd/messaging.py index 32229e0..57f9465 100644 --- a/aprsd/messaging.py +++ b/aprsd/messaging.py @@ -217,10 +217,7 @@ class TextMessage(Message): def __repr__(self): """Build raw string to send over the air.""" return "{}>APRS::{}:{}{{{}\n".format( - self.fromcall, - self.tocall.ljust(9), - self._filter_for_send(), - str(self.id), + self.fromcall, self.tocall.ljust(9), self._filter_for_send(), str(self.id) ) def __str__(self): diff --git a/aprsd/plugin.py b/aprsd/plugin.py index 8a1b4f8..9ef83ba 100644 --- a/aprsd/plugin.py +++ b/aprsd/plugin.py @@ -70,7 +70,7 @@ class PluginManager(object): self.obj_list = [] - for path, subdirs, files in os.walk(dir_path): + for path, _subdirs, files in os.walk(dir_path): for name in files: if fnmatch.fnmatch(name, pattern): LOG.debug("MODULE? '{}' '{}'".format(name, path)) diff --git a/tests/test_main.py b/tests/test_main.py index b6a8b06..1aecc1c 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -2,8 +2,6 @@ import sys import unittest -import pytest - from aprsd import email if sys.version_info >= (3, 2): @@ -12,7 +10,7 @@ else: import mock -class testMain(unittest.TestCase): +class TestMain(unittest.TestCase): @mock.patch("aprsd.email._imap_connect") @mock.patch("aprsd.email._smtp_connect") def test_validate_email(self, imap_mock, smtp_mock): diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 886064f..c2f860d 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -1,16 +1,13 @@ # -*- coding: utf-8 -*- -import sys import unittest from unittest import mock -import pytest - import aprsd from aprsd import plugin from aprsd.fuzzyclock import fuzzy -class testPlugin(unittest.TestCase): +class TestPlugin(unittest.TestCase): def setUp(self): self.fromcall = "KFART" self.ack = 1 @@ -41,11 +38,11 @@ class testPlugin(unittest.TestCase): self.assertEqual(expected, actual) @mock.patch("time.localtime") - def test_Time(self, mock_time): + def test_time(self, mock_time): fake_time = mock.MagicMock() h = fake_time.tm_hour = 16 m = fake_time.tm_min = 12 - s = fake_time.tm_sec = 55 + fake_time.tm_sec = 55 mock_time.return_value = fake_time time_plugin = plugin.TimePlugin(self.config) @@ -66,7 +63,7 @@ class testPlugin(unittest.TestCase): self.assertEqual(expected, actual) @mock.patch("time.localtime") - def test_Ping(self, mock_time): + def test_ping(self, mock_time): fake_time = mock.MagicMock() h = fake_time.tm_hour = 16 m = fake_time.tm_min = 12 diff --git a/tox.ini b/tox.ini index 1682b3c..ba64524 100644 --- a/tox.ini +++ b/tox.ini @@ -28,7 +28,7 @@ commands = sphinx-build -b html docs/source docs/html [testenv:pep8] commands = - flake8 {posargs} aprsd + flake8 {posargs} aprsd tests [testenv:fast8] basepython = python3 @@ -43,7 +43,7 @@ skip_install = true deps = -r{toxinidir}/dev-requirements.txt commands = - flake8 aprsd + flake8 aprsd tests [flake8] max-line-length = 99