Linter config improvements, code style fixes

This commit is contained in:
Teemu Ikonen 2023-01-19 14:03:11 +02:00
parent 760f80fb49
commit 3ebf88d0f7
7 changed files with 54 additions and 56 deletions

View File

@ -2,8 +2,7 @@
# SPDX-License-Identifier: GPL-3.0-only
import argparse
import gi
import gpxpy
import importlib.resources as resources
import os
import re
import signal
@ -12,26 +11,28 @@ import time
import tokenize
from datetime import datetime
import importlib.resources as resources
import gi
import gpxpy
import satellite.nmea as nmea
import satellite.quectel as quectel
from satellite import __version__
from .mm_pydbus_source import QuectelNmeaSource
from .nmeasource import (
ModemNoNMEAError,
ModemLockedError,
ModemError,
NmeaSourceNotFoundError,
GnssShareNmeaSource,
ModemError,
ModemLockedError,
ModemNoNMEAError,
NmeaSourceNotFoundError,
)
from .util import bearing_to_arrow, have_touchscreen, now, unique_filename
from .widgets import text_barchart, DataFrame
from satellite import __version__
from .widgets import DataFrame, text_barchart
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
gi.require_version('Handy', '1')
from gi.repository import Gdk, Gio, GLib, Gtk, Handy # noqa: E402
from gi.repository import GLib, Gdk, Gio, Gtk, Handy # noqa: E402, I100
appname = 'Satellite'
app_id = 'page.codeberg.tpikonen.satellite'
@ -54,9 +55,9 @@ class SatelliteApp(Gtk.Application):
parser.add_argument(
'-s', '--source', dest='source',
default='quectel',
help='Select NMEA source. Options are '
'\'quectel\' (default) for Quectel Modems or '
'\'gnss-share\' when using gnss-share')
help="Select NMEA source. Options are "
"\'quectel\' (default) for Quectel Modems or "
"\'gnss-share\' when using gnss-share")
self.args = parser.parse_args()
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT,
@ -90,7 +91,7 @@ class SatelliteApp(Gtk.Application):
self.source = None
self.infolabel.set_markup("<tt>" + "\n"*10 + "</tt>")
self.infolabel.set_markup("<tt>" + "\n" * 10 + "</tt>")
self.dataframe = DataFrame()
# self.dataframe.header.set_text("Satellite info")
@ -175,7 +176,6 @@ class SatelliteApp(Gtk.Application):
GLib.timeout_add(1000, self.init_source, None)
def on_shutdown(self, app):
"""Called after main loop exits."""
print("Cleaning up...")
self.gpx_write()
if self.source is not None:
@ -418,16 +418,14 @@ class SatelliteApp(Gtk.Application):
("mode_indicator", "Modes (GP,GL,GA)", lambda x: str(x)),
("actives", "Active / in use sats", get_actives),
("visibles", "Receiving sats", lambda x: str(len(
list(r for r in x if r['snr'] > 0.0)))),
[r for r in x if r['snr'] > 0.0]))),
("visibles", "Visible sats", lambda x: str(len(x))),
# ("fixage", "Age of fix", lambda x: to_str(x, "%0.0f s")),
("fixage", "Age of update / fix", get_ages),
("systime", "Sys. Time", lambda x: x.strftime(utcfmt)),
("latlon", "Latitude",
lambda x: "%0.6f" % x[0] if x else "-"),
("latlon", "Longitude",
lambda x: "%0.6f" % x[1] if x else "-"),
("altitude", "Altitude", lambda x: to_str(x, "%0.1f m")),
("latlon", "Latitude", lambda x: "%0.6f" % x[0] if x else "-"),
("latlon", "Longitude", lambda x: "%0.6f" % x[1] if x else "-"),
("altitude", "Altitude", lambda x: to_str(x, "%0.1f m")),
# ("fixtime", "Time of fix",
# lambda x: x.strftime(utcfmt) if x else "-"),
# ("date", "Date of fix",
@ -471,10 +469,9 @@ class SatelliteApp(Gtk.Application):
self.last_mode = mode
def set_speedlabel(self, speed, bearing=None):
spd = str(int(3.6*speed)) if speed else "-"
spd = str(int(3.6 * speed)) if speed else "-"
arrow = bearing_to_arrow(bearing) if bearing is not None else ""
speedfmt = ('<span size="50000">%s%s</span>\n' +
'<span size="30000">%s</span>')
speedfmt = '<span size="50000">%s%s</span>\n<span size="30000">%s</span>'
speedstr = speedfmt % (spd, arrow, "km/h")
self.speedlabel.set_markup(speedstr)

View File

@ -2,18 +2,19 @@
# SPDX-License-Identifier: GPL-3.0-only
import re
import satellite.modem_manager_defs as mm
from satellite.nmeasource import (
NmeaSource,
NmeaSourceNotFoundError,
ModemError,
ModemLockedError,
ModemNoNMEAError,
)
from pydbus import SystemBus
from pynmea2.nmea import NMEASentence
import satellite.modem_manager_defs as mm
from satellite.nmeasource import (
ModemError,
ModemLockedError,
ModemNoNMEAError,
NmeaSource,
NmeaSourceNotFoundError,
)
class ModemManagerPyDBusNmeaSource(NmeaSource):
@ -105,12 +106,12 @@ class QuectelNmeaSource(ModemManagerPyDBusNmeaSource):
return self.fix_talker(super()._really_get())
def fix_talker(self, nmeas):
pq_re = re.compile(r'''
pq_re = re.compile(r"""
^\s*\$?
(?P<talker>PQ)
(?P<sentence>\w{3})
(?P<data>[^*]*)
(?:[*](?P<checksum>[A-F0-9]{2}))$''', re.VERBOSE)
(?:[*](?P<checksum>[A-F0-9]{2}))$""", re.VERBOSE)
out = []
for nmea in (n for n in nmeas.split('\r\n') if n):
mo = pq_re.match(nmea)

View File

@ -2,9 +2,10 @@
# SPDX-License-Identifier: GPL-3.0-only
import datetime
import pynmea2
import re
import pynmea2
MS_PER_KNOT = 0.514444
lastfix_dt = None
@ -61,9 +62,9 @@ def get_latlon(mdict):
lat_min = float(lat[2:])
lon_deg = float(lon[:3])
lon_min = float(lon[3:])
flat = lat_deg + lat_min/60
flat = lat_deg + lat_min / 60
flat = -1 * flat if lat_dir == 'S' else flat
flon = lon_deg + lon_min/60
flon = lon_deg + lon_min / 60
flon = -1 * flon if lon_dir == 'W' else flon
return (flat, flon)
@ -182,7 +183,7 @@ def parse(nmeas, always_add_prefix=False):
return float(s) if s else empty_val
def add_prn_prefix(prns, talker, always=always_add_prefix):
"""Add constellation prefix to PRN string"""
"""Add constellation prefix to PRN string."""
beidou_prefix = "C"
galileo_prefix = "E"
glonass_prefix = "R"
@ -227,7 +228,7 @@ def parse(nmeas, always_add_prefix=False):
'snr': fl(getattr(msg, f'snr_{n}', None), 0.0),
})
elif isinstance(msg, pynmea2.types.GSA):
for n in range(1, 12+1):
for n in range(1, 12 + 1):
prns = getattr(msg, f'sv_id{n:02d}')
if prns and prns.isdigit():
actives.append(add_prn_prefix(prns, msg.talker))

View File

@ -2,7 +2,6 @@
# SPDX-License-Identifier: GPL-3.0-only
import re
from datetime import datetime, timezone
from .util import (

View File

@ -1,11 +1,10 @@
# Copyright 2021-2022 Teemu Ikonen
# SPDX-License-Identifier: GPL-3.0-only
import gi
import os
from datetime import datetime, timezone
import gi
gi.require_version('Gdk', '3.0')
from gi.repository import Gdk # noqa: E402
@ -16,15 +15,13 @@ week_now = int((now.timestamp() - gps_epoch.timestamp()) / one_week)
def have_touchscreen():
"""Return True if the default seat of default display has touch capability
"""
"""Return True if the default seat of default display has touch capability."""
return bool(Gdk.Display.get_default_seat(
Gdk.Display.get_default()).get_capabilities() & Gdk.SeatCapabilities.TOUCH)
def datetime_from_gpstime(week, millisecs, fix_week=False):
"""Return a datetime object formed from GPS week number and
milliseconds from week start.
"""Return a datetime from GPS week number and milliseconds from week start.
If fix_week is True, set the bits above 10 in week number from
current date, see
@ -38,7 +35,7 @@ def datetime_from_gpstime(week, millisecs, fix_week=False):
def gpstime_from_datetime(dt):
"""Return a (gps_week, millisec) tuple from a datetime object"""
"""Return a (gps_week, millisec) tuple from a datetime object."""
if dt < gps_epoch:
raise ValueError("Time cannot be less than GPS epoch")
ts = dt.timestamp()
@ -51,7 +48,7 @@ def gpstime_from_datetime(dt):
def unique_filename(namestem, ext, timestamp=False):
if timestamp:
namestem += "-" + datetime.now().isoformat(
'_', 'seconds').replace(':', '.')
'_', 'seconds').replace(':', '.')
name = None
for count in ('~%d' % n if n > 0 else '' for n in range(100)):
test = namestem + count + ext
@ -77,7 +74,7 @@ def bearing_to_arrow(bearing):
'\u2196',
'\u2191',
]
edges = list(22.5 + 45.0 * n for n in range(0, 8)) + [360.0]
edges = [22.5 + 45.0 * n for n in range(0, 8)] + [360.0]
angle = bearing - (bearing // 360) * 360
index = next(ind for (ind, e) in enumerate(edges) if angle < e)

View File

@ -1,10 +1,9 @@
# Copyright 2021-2022 Teemu Ikonen
# SPDX-License-Identifier: GPL-3.0-only
import gi
import importlib.resources as resources
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
from gi.repository import Gtk # noqa: E402
@ -18,8 +17,7 @@ def text_barchart(data, highlights, height=None, width=30):
height Number of lines in the generated bar chart
width Width of the generated bar chart in chars
"""
sdata = list((d[0] if d[0] else '',
int(d[1]) if d[1] else 0) for d in data)
sdata = [(d[0] if d[0] else '', int(d[1]) if d[1] else 0) for d in data]
sdata.sort(key=lambda x: x[1], reverse=True)
dstr = ''
@ -41,14 +39,14 @@ def text_barchart(data, highlights, height=None, width=30):
cmax_xaxis = cmaxbar + 3
for d in sdata[:barlines]:
block = '\u2585' if d[0] in highlights else '='
dstr += "%3s\u2502%s %d\n" % (d[0], block*int(scale*d[1]), d[1])
dstr += "%3s\u2502%s %d\n" % (d[0], block * int(scale * d[1]), d[1])
if barlines < len(sdata):
dstr += " \u256a\n"
elif (len(sdata) - axislines) < height:
# Add empty lines to y-axis
dstr += ' \u2502\n' * (height - len(sdata) - axislines)
dstr += " \u251c" + '\u2500'*(cmax_xaxis) + '\u2524\n'
dstr += " 0" + ' '*(cmax_xaxis - 1) + str(max_xaxis)
dstr += " \u251c" + '\u2500' * (cmax_xaxis) + '\u2524\n'
dstr += " 0" + ' ' * (cmax_xaxis - 1) + str(max_xaxis)
return dstr

View File

@ -1,3 +1,8 @@
[flake8]
exclude=.git,__pycache__,build
max-line-length=88
ignore = B902, BLK100, CCR001, CNL100, D1, I201, Q000, W503
[pycodestyle]
count=1
max-line-length = 88