From 8e313a3eb881c6eb504dcd3d3c408639fce002f9 Mon Sep 17 00:00:00 2001 From: Zach Date: Thu, 27 May 2021 14:17:28 -0400 Subject: [PATCH] add formatting workflow (#61) * add formatting workflow * Fix code style issues with oitnb Co-authored-by: Lint Action --- .github/workflows/formatting.yml | 23 ++++++++++++++++ .github/workflows/tests.yml | 1 + packetraven/__main__.py | 4 +-- packetraven/connections/serial.py | 2 +- packetraven/gui/base.py | 44 +++++++++++++++---------------- setup.py | 4 +-- tests/test_database.py | 2 +- tests/test_predicts.py | 4 +-- 8 files changed, 54 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/formatting.yml diff --git a/.github/workflows/formatting.yml b/.github/workflows/formatting.yml new file mode 100644 index 00000000..c8ea67ea --- /dev/null +++ b/.github/workflows/formatting.yml @@ -0,0 +1,23 @@ +name: formatting + +on: pull_request + +jobs: + run-linters: + name: Run formatter + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v1 + - name: Install dependencies + run: | + pip install wheel + pip install -e .[development] + - name: Run linters / formatters + uses: wearerequired/lint-action@master + with: + oitnb_command_prefix: isort --fss --fass .; + oitnb: true + auto_fix: true diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 95be0bfd..c17f890b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -37,6 +37,7 @@ jobs: - name: Install dependencies run: | pip install wheel + pip install flake8 pip install -e .[testing] - name: Lint with flake8 run: | diff --git a/packetraven/__main__.py b/packetraven/__main__.py index 6c4c6314..ec31b924 100644 --- a/packetraven/__main__.py +++ b/packetraven/__main__.py @@ -25,7 +25,7 @@ from packetraven.packets import APRSPacket from packetraven.packets.tracks import APRSTrack, LocationPacketTrack from packetraven.packets.writer import write_packet_tracks -from packetraven.predicts import PredictionAPIURL, PredictionError, get_predictions +from packetraven.predicts import get_predictions, PredictionAPIURL, PredictionError from packetraven.utilities import get_logger, read_configuration, repository_root LOGGER = get_logger('packetraven', log_format='%(asctime)s | %(message)s') @@ -43,7 +43,7 @@ def main(): args_parser.add_argument( '--tnc', help='comma-separated list of serial ports / text files of a TNC parsing APRS packets from analog audio to ASCII' - ' (set to `auto` to use the first open serial port)', + ' (set to `auto` to use the first open serial port)', ) args_parser.add_argument( '--database', help='PostGres database table `user@hostname:port/database/table`' diff --git a/packetraven/connections/serial.py b/packetraven/connections/serial.py index 0a0de7cf..567e8b67 100644 --- a/packetraven/connections/serial.py +++ b/packetraven/connections/serial.py @@ -5,8 +5,8 @@ from packetraven.connections.base import ( APRSPacketSource, LOGGER, - TimeIntervalError, next_open_serial_port, + TimeIntervalError, ) from packetraven.packets import APRSPacket diff --git a/packetraven/gui/base.py b/packetraven/gui/base.py index ef1ca112..87eb8479 100644 --- a/packetraven/gui/base.py +++ b/packetraven/gui/base.py @@ -21,7 +21,7 @@ from packetraven.packets import APRSPacket from packetraven.packets.tracks import LocationPacketTrack, PredictedTrajectory from packetraven.packets.writer import write_packet_tracks -from packetraven.predicts import PredictionError, get_predictions +from packetraven.predicts import get_predictions, PredictionError from packetraven.utilities import get_logger @@ -707,7 +707,7 @@ def toggle(self): connection.location for connection in self.__connections if isinstance(connection, SerialTNC) - or isinstance(connection, RawAPRSTextFile) + or isinstance(connection, RawAPRSTextFile) ] api_key = self.__configuration['aprs_fi']['aprs_fi_key'] @@ -995,7 +995,7 @@ def retrieve_packets(self): sticky='w', row=self.__elements[f'{callsign}.source'].grid_info()['row'], column=self.__elements[f'{callsign}.source'].grid_info()['column'] - + 4, + + 4, columnspan=3, ) self.__add_text_box( @@ -1007,9 +1007,9 @@ def retrieve_packets(self): sticky='w', row=self.__elements[f'{callsign}.callsign'].grid_info()['row'], column=self.__elements[f'{callsign}.callsign'].grid_info()[ - 'column' - ] - + 3, + 'column' + ] + + 3, ) self.__add_text_box( window, @@ -1020,7 +1020,7 @@ def retrieve_packets(self): sticky='w', row=self.__elements[f'{callsign}.packets'].grid_info()['row'], column=self.__elements[f'{callsign}.packets'].grid_info()['column'] - + 3, + + 3, ) separator = Separator(window, orient=tkinter.HORIZONTAL) @@ -1066,9 +1066,9 @@ def retrieve_packets(self): sticky='w', row=self.__elements[f'{callsign}.coordinates'].grid_info()['row'], column=self.__elements[f'{callsign}.coordinates'].grid_info()[ - 'column' - ] - + 3, + 'column' + ] + + 3, ) self.__add_text_box( window, @@ -1079,9 +1079,9 @@ def retrieve_packets(self): sticky='w', row=self.__elements[f'{callsign}.distance'].grid_info()['row'], column=self.__elements[f'{callsign}.distance'].grid_info()[ - 'column' - ] - + 3, + 'column' + ] + + 3, ) self.__add_text_box( window, @@ -1092,9 +1092,9 @@ def retrieve_packets(self): sticky='w', row=self.__elements[f'{callsign}.ground_speed'].grid_info()['row'], column=self.__elements[f'{callsign}.ground_speed'].grid_info()[ - 'column' - ] - + 3, + 'column' + ] + + 3, ) separator = Separator(window, orient=tkinter.HORIZONTAL) @@ -1134,9 +1134,9 @@ def retrieve_packets(self): 'row' ], column=self.__elements[ - f'{callsign}.distance_downrange' - ].grid_info()['column'] - + 3, + f'{callsign}.distance_downrange' + ].grid_info()['column'] + + 3, ) self.__add_text_box( window, @@ -1149,9 +1149,9 @@ def retrieve_packets(self): 'row' ], column=self.__elements[ - f'{callsign}.distance_overground' - ].grid_info()['column'] - + 3, + f'{callsign}.distance_overground' + ].grid_info()['column'] + + 3, ) separator = Separator(window, orient=tkinter.VERTICAL) diff --git a/setup.py b/setup.py index 9c62e008..427caa95 100644 --- a/setup.py +++ b/setup.py @@ -103,8 +103,8 @@ 'tablecrow>=1.3.6', ], extras_require={ - 'testing': ['flake8', 'pytest', 'pytest-cov', 'pytest-xdist', 'pytz'], - 'development': ['oitnb'], + 'testing': ['pytest', 'pytest-cov', 'pytest-xdist', 'pytz'], + 'development': ['flake8', 'isort', 'oitnb'], }, entry_points={'console_scripts': ['packetraven=packetraven.__main__:main']}, ) diff --git a/tests/test_database.py b/tests/test_database.py index 9baf70df..45fd4b2c 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -6,7 +6,7 @@ import pytest from sshtunnel import SSHTunnelForwarder from tablecrow.tables.base import random_open_tcp_port -from tablecrow.tables.postgres import PostGresTable, SSH_DEFAULT_PORT, database_has_table +from tablecrow.tables.postgres import database_has_table, PostGresTable, SSH_DEFAULT_PORT from tablecrow.utilities import split_hostname_port from packetraven import APRSDatabaseTable diff --git a/tests/test_predicts.py b/tests/test_predicts.py index f23afd7f..0a008420 100644 --- a/tests/test_predicts.py +++ b/tests/test_predicts.py @@ -80,8 +80,8 @@ def test_float_prediction(): burst_altitude, descent_rate, float_end_time=datetime.now() - + timedelta(seconds=burst_altitude / ascent_rate) - + timedelta(hours=1), + + timedelta(seconds=burst_altitude / ascent_rate) + + timedelta(hours=1), ) response_json = cusf_api.get()