1
0
mirror of https://github.com/craigerl/aprsd.git synced 2024-12-18 07:36:34 -05:00

Added pre-commit hooks

This patch adds pre-commit hook support to ensure
code passes basic checks prior to allowing a commit.
This commit is contained in:
Hemna 2021-01-06 17:50:02 -05:00
parent 8bd8b95b35
commit 75f610d971
10 changed files with 38 additions and 30 deletions

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

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

View File

@ -4,6 +4,8 @@ CHANGES
v1.5.0 v1.5.0
------ ------
* Added pre-commit hooks
* Update Changelog for v1.5.0
* Added QueryPlugin resend all delayed msgs or Flush * Added QueryPlugin resend all delayed msgs or Flush
* Added QueryPlugin * Added QueryPlugin
* Added support to save/load MsgTrack on exit/start * Added support to save/load MsgTrack on exit/start

View File

@ -17,7 +17,7 @@ cd ~/.venv_aprsd
./bin/aprsd # generates a config.yml template on first run ./bin/aprsd # generates a config.yml template on first run
vi ~/.aprsd/config.yml vi ~/.aprsd/config.yml
./bin/aprsd ./bin/aprsd

View File

@ -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 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 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 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 time of day, get weather, and fortune telling as well as version information
of aprsd itself. of aprsd itself.
@ -25,7 +25,7 @@ Typical use case
================ ================
Ham radio operator using an APRS enabled HAM radio sends a message to check 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 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 processing. The WeatherPlugin picks up the message, fetches the weather
for the area around the user who sent the request, and then responds with 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 * 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 * 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 * bash completion generation. Uses python click bash completion to generate completion code for your .bashrc/.zshrc
@ -173,7 +173,7 @@ Output
server 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 look for incomming commands to the callsign configured in the config file
:: ::
@ -319,12 +319,12 @@ LOCATION
Sending message_______________ 7(Tx3) Sending message_______________ 7(Tx3)
Raw : KM6XXX-9>APRS::KM6XXX :8 Miles NE Auburn CA 1673' 39.91150,-120.93450 0.1h ago{7 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 Message : 8 Miles E Auburn CA 1673' 38.91150,-120.93450 0.1h ago
Sending ack __________________ Tx(3) Sending ack __________________ Tx(3)
Raw : KM6XXX-9>APRS::KM6XXX :ack28 Raw : KM6XXX-9>APRS::KM6XXX :ack28
To : KM6XXX To : KM6XXX
Ack number : 28 Ack number : 28
Received message______________ Received message______________
@ -356,7 +356,7 @@ Release
To do release to pypi: To do release to pypi:
* Tag release with * Tag release with
git tag -v1.XX -m "New release" 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 python file is in your /plugins volume and the plugin will be installed at
container startup. The plugin may have dependencies that are required. container startup. The plugin may have dependencies that are required.
The plugin file should be copied to /plugins for loading by aprsd The plugin file should be copied to /plugins for loading by aprsd

View File

@ -383,10 +383,7 @@ def server(loglevel, quiet, disable_validation, config_file, flush):
rx_msg_queue = queue.Queue(maxsize=20) rx_msg_queue = queue.Queue(maxsize=20)
tx_msg_queue = queue.Queue(maxsize=20) tx_msg_queue = queue.Queue(maxsize=20)
msg_queues = { msg_queues = {"rx": rx_msg_queue, "tx": tx_msg_queue}
"rx": rx_msg_queue,
"tx": tx_msg_queue,
}
rx_thread = threads.APRSDRXThread(msg_queues=msg_queues, config=config) rx_thread = threads.APRSDRXThread(msg_queues=msg_queues, config=config)
tx_thread = threads.APRSDTXThread(msg_queues=msg_queues, config=config) tx_thread = threads.APRSDTXThread(msg_queues=msg_queues, config=config)

View File

@ -217,10 +217,7 @@ class TextMessage(Message):
def __repr__(self): def __repr__(self):
"""Build raw string to send over the air.""" """Build raw string to send over the air."""
return "{}>APRS::{}:{}{{{}\n".format( return "{}>APRS::{}:{}{{{}\n".format(
self.fromcall, self.fromcall, self.tocall.ljust(9), self._filter_for_send(), str(self.id)
self.tocall.ljust(9),
self._filter_for_send(),
str(self.id),
) )
def __str__(self): def __str__(self):

View File

@ -70,7 +70,7 @@ class PluginManager(object):
self.obj_list = [] 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: for name in files:
if fnmatch.fnmatch(name, pattern): if fnmatch.fnmatch(name, pattern):
LOG.debug("MODULE? '{}' '{}'".format(name, path)) LOG.debug("MODULE? '{}' '{}'".format(name, path))

View File

@ -2,8 +2,6 @@
import sys import sys
import unittest import unittest
import pytest
from aprsd import email from aprsd import email
if sys.version_info >= (3, 2): if sys.version_info >= (3, 2):
@ -12,7 +10,7 @@ else:
import mock import mock
class testMain(unittest.TestCase): class TestMain(unittest.TestCase):
@mock.patch("aprsd.email._imap_connect") @mock.patch("aprsd.email._imap_connect")
@mock.patch("aprsd.email._smtp_connect") @mock.patch("aprsd.email._smtp_connect")
def test_validate_email(self, imap_mock, smtp_mock): def test_validate_email(self, imap_mock, smtp_mock):

View File

@ -1,16 +1,13 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import sys
import unittest import unittest
from unittest import mock from unittest import mock
import pytest
import aprsd import aprsd
from aprsd import plugin from aprsd import plugin
from aprsd.fuzzyclock import fuzzy from aprsd.fuzzyclock import fuzzy
class testPlugin(unittest.TestCase): class TestPlugin(unittest.TestCase):
def setUp(self): def setUp(self):
self.fromcall = "KFART" self.fromcall = "KFART"
self.ack = 1 self.ack = 1
@ -41,11 +38,11 @@ class testPlugin(unittest.TestCase):
self.assertEqual(expected, actual) self.assertEqual(expected, actual)
@mock.patch("time.localtime") @mock.patch("time.localtime")
def test_Time(self, mock_time): def test_time(self, mock_time):
fake_time = mock.MagicMock() fake_time = mock.MagicMock()
h = fake_time.tm_hour = 16 h = fake_time.tm_hour = 16
m = fake_time.tm_min = 12 m = fake_time.tm_min = 12
s = fake_time.tm_sec = 55 fake_time.tm_sec = 55
mock_time.return_value = fake_time mock_time.return_value = fake_time
time_plugin = plugin.TimePlugin(self.config) time_plugin = plugin.TimePlugin(self.config)
@ -66,7 +63,7 @@ class testPlugin(unittest.TestCase):
self.assertEqual(expected, actual) self.assertEqual(expected, actual)
@mock.patch("time.localtime") @mock.patch("time.localtime")
def test_Ping(self, mock_time): def test_ping(self, mock_time):
fake_time = mock.MagicMock() fake_time = mock.MagicMock()
h = fake_time.tm_hour = 16 h = fake_time.tm_hour = 16
m = fake_time.tm_min = 12 m = fake_time.tm_min = 12

View File

@ -28,7 +28,7 @@ commands = sphinx-build -b html docs/source docs/html
[testenv:pep8] [testenv:pep8]
commands = commands =
flake8 {posargs} aprsd flake8 {posargs} aprsd tests
[testenv:fast8] [testenv:fast8]
basepython = python3 basepython = python3
@ -43,7 +43,7 @@ skip_install = true
deps = deps =
-r{toxinidir}/dev-requirements.txt -r{toxinidir}/dev-requirements.txt
commands = commands =
flake8 aprsd flake8 aprsd tests
[flake8] [flake8]
max-line-length = 99 max-line-length = 99