From bda3f970bd713cf553dcca47beb22682a49c7081 Mon Sep 17 00:00:00 2001 From: Fred Wright Date: Fri, 14 Jul 2017 15:46:45 -0700 Subject: [PATCH] Fixes some pylint issues. This doesn't fix all complaints by pylint, but significantly reduces their number. Ditto for pep8 complaints. Also makes a couple of related cosmetic edits. TESTED: Ran "scons build-all check" with no errors. Both "pylint" and "pep8" targets report fewer issues. --- SConstruct | 3 ++- gegps | 3 ++- gps/__init__.py | 6 +++--- gps/fake.py | 2 +- gps/gps.py | 3 +-- gps/misc.py | 4 ++-- gpscat | 6 ++++-- gpsfake | 5 +++-- gpsprof | 3 ++- gpssim.py | 5 +++-- test_maidenhead.py | 1 + test_misc.py | 1 + valgrind-audit.py | 1 + xgps | 33 ++++++++++++++++++--------------- xgpsspeed | 19 ++++++++++++------- 15 files changed, 56 insertions(+), 39 deletions(-) diff --git a/SConstruct b/SConstruct index 689c0fdc..319f1bbc 100644 --- a/SConstruct +++ b/SConstruct @@ -1766,7 +1766,8 @@ if len(python_progs) > 0: '''C0302,C0322,C0324,C0323,C0321,C0330,R0201,R0801,R0902,R0903,''' '''R0904,R0911,R0912,R0913,R0914,R0915,W0110,W0201,W0121,W0123,''' '''W0231,W0232,W0234,W0401,W0403,W0141,W0142,W0603,W0614,W0640,''' - '''W0621,W1504,E0602,E0611,E1101,E1102,E1103,F0401 gps/*.py *.py ''' + '''W0621,W1504,E0602,E0611,E1101,E1102,E1103,F0401,I0011 ''' + '''gps/*.py *.py ''' + " ".join(python_progs)]) # Additional Python readability style checks diff --git a/gegps b/gegps index c48b26b7..861ca1af 100755 --- a/gegps +++ b/gegps @@ -25,10 +25,11 @@ from __future__ import absolute_import, print_function, division import getopt -import gps import os import sys +import gps + KML_OPEN_IN_GE = '''\ diff --git a/gps/__init__.py b/gps/__init__.py index 553d30ea..06b87597 100644 --- a/gps/__init__.py +++ b/gps/__init__.py @@ -7,11 +7,11 @@ # Preserve this property! from __future__ import absolute_import # Ensure Python2 behaves like Python 3 -api_major_version = 5 # bumped on incompatible changes -api_minor_version = 0 # bumped on compatible changes - from .gps import * from .misc import * +api_major_version = 5 # bumped on incompatible changes +api_minor_version = 0 # bumped on compatible changes + # The 'client' module exposes some C utility functions for Python clients. # The 'packet' module exposes the packet getter via a Python interface. diff --git a/gps/fake.py b/gps/fake.py index 9d850518..a4b9c1b5 100644 --- a/gps/fake.py +++ b/gps/fake.py @@ -78,6 +78,7 @@ import select import signal import socket +import stat import subprocess import sys import termios # fcntl, array, struct @@ -87,7 +88,6 @@ import gps from gps import polybytes from . import packet as sniffer -import stat # The magic number below has to be derived from observation. If # it's too high you'll slow the tests down a lot. If it's too low diff --git a/gps/gps.py b/gps/gps.py index 22e023f1..1b5d6456 100755 --- a/gps/gps.py +++ b/gps/gps.py @@ -20,7 +20,6 @@ from __future__ import absolute_import, print_function, division from .client import * -from .misc import isotime NaN = float('nan') @@ -213,7 +212,7 @@ def default(k, dflt, vbit=0): self.driver_mode = default("native", 0) self.mincycle = default("mincycle", NaN) self.serialmode = default("serialmode", "8N1") - # FIXME: decode DEVICSES + # FIXME: decode DEVICES # FIXME: decode PPS elif self.data.get("class") == "TPV": self.device = default("device", "missing") diff --git a/gps/misc.py b/gps/misc.py index 78b97093..f76bb89e 100644 --- a/gps/misc.py +++ b/gps/misc.py @@ -152,7 +152,7 @@ def EarthDistance(c1, c2): f = 1 / 298.257223563 b = 6356752.314245 # meters; b = (1 - f)a - MILES_PER_KILOMETER = 0.621371 + # MILES_PER_KILOMETER = 1000.0 / (.3048 * 5280.0) MAX_ITERATIONS = 200 CONVERGENCE_THRESHOLD = 1e-12 # .000,000,000,001 @@ -171,7 +171,7 @@ def EarthDistance(c1, c2): sinU2 = math.sin(U2) cosU2 = math.cos(U2) - for iteration in range(MAX_ITERATIONS): + for _ in range(MAX_ITERATIONS): sinLambda = math.sin(Lambda) cosLambda = math.cos(Lambda) sinSigma = math.sqrt((cosU2 * sinLambda) ** 2 + diff --git a/gpscat b/gpscat index 037b57da..97a8a74f 100755 --- a/gpscat +++ b/gpscat @@ -10,15 +10,17 @@ # Preserve this property! from __future__ import absolute_import, print_function, division -import curses.ascii import getopt -import gps.packet as sniffer import os import select import socket import sys import termios +import curses.ascii + +import gps.packet as sniffer + # The spec says 82, but some receivers (TN-200, GSW 2.3.2) output 86 characters # the Skyrtaq S2525F8 emits 100 chars NMEA_MAX = 102 diff --git a/gpsfake b/gpsfake index a6163090..932a7ffb 100755 --- a/gpsfake +++ b/gpsfake @@ -14,8 +14,6 @@ from __future__ import absolute_import, print_function, division import getopt -import gps -import gps.fake as gpsfake # The "as" pacifies pychecker import os import platform import pty @@ -23,6 +21,9 @@ import socket import sys import time +import gps +import gps.fake as gpsfake # The "as" pacifies pychecker + try: my_input = raw_input except NameError: diff --git a/gpsprof b/gpsprof index a8c8dc84..23a18c21 100755 --- a/gpsprof +++ b/gpsprof @@ -12,7 +12,6 @@ from __future__ import absolute_import, print_function, division import copy import getopt -import gps import math import os import signal @@ -20,6 +19,8 @@ import socket import sys import time +import gps + class Baton(object): "Ship progress indication to stderr." diff --git a/gpssim.py b/gpssim.py index 60176633..de456de0 100644 --- a/gpssim.py +++ b/gpssim.py @@ -5,13 +5,14 @@ This is proof-of-concept code, not production ready; some functions are stubs. """ -import gps -import gpslib import math import random import sys import time +import gps +import gpslib + # First, the mathematics. We simulate a moving viewpoint on the Earth # and a satellite with specified orbital elements in the sky. diff --git a/test_maidenhead.py b/test_maidenhead.py index cc756d00..665fd493 100755 --- a/test_maidenhead.py +++ b/test_maidenhead.py @@ -12,6 +12,7 @@ from __future__ import absolute_import, print_function, division import sys + import gps.clienthelpers errors = 0 diff --git a/test_misc.py b/test_misc.py index 23415603..111d8e06 100755 --- a/test_misc.py +++ b/test_misc.py @@ -8,6 +8,7 @@ from __future__ import absolute_import, print_function, division import sys + import gps.misc errors = 0 diff --git a/valgrind-audit.py b/valgrind-audit.py index fcd8b8c5..9254d0d4 100755 --- a/valgrind-audit.py +++ b/valgrind-audit.py @@ -12,6 +12,7 @@ from __future__ import absolute_import, print_function, division import sys + import gps.fake debuglevel = 1 diff --git a/xgps b/xgps index 784cb680..776fa6a4 100755 --- a/xgps +++ b/xgps @@ -7,33 +7,36 @@ usage: xgps [-D level] [-hV?] [-l degmfmt] [-u units] [-r rotation] [server[:port[:device]]] ''' +# This file is Copyright (c) 2010 by the GPSD project +# BSD terms apply: see the file COPYING in the distribution root for details. +# # This code runs compatibly under Python 2 and 3.x for x >= 2. # Preserve this property! from __future__ import absolute_import, print_function, division -gui_about = '''\ -This is xgps, a test client for the gpsd daemon. - -By Eric S. Raymond for the GPSD project, December 2009 -''' -# -# This file is Copyright (c) 2010 by the GPSD project -# BSD terms apply: see the file COPYING in the distribution root for details. - import math import socket import sys import time -from gi.repository import GObject +import gps +import gps.clienthelpers + +import cairo + +# Gtk3 imports. Gtk3 requires the require_version(), which then causes +# pylint to complain about the subsequent "non-top" imports. import gi gi.require_version('Gtk', '3.0') -from gi.repository import Gtk -from gi.repository import Gdk -import cairo +from gi.repository import GObject # pylint: disable=wrong-import-position +from gi.repository import Gtk # pylint: disable=wrong-import-position +from gi.repository import Gdk # pylint: disable=wrong-import-position -import gps -import gps.clienthelpers +gui_about = '''\ +This is xgps, a test client for the gpsd daemon. + +By Eric S. Raymond for the GPSD project, December 2009 +''' # Use our own MAXCHANNELS value, due to the tradeoff between max sats and # the window size. Ideally, this should be dynamic. diff --git a/xgpsspeed b/xgpsspeed index 0f6638a5..e48e6288 100755 --- a/xgpsspeed +++ b/xgpsspeed @@ -11,13 +11,6 @@ # Preserve this property! from __future__ import absolute_import, print_function, division -import gi -gi.require_version('Gtk', '3.0') -from gi.repository import Gtk -from gi.repository import Gdk -import cairo -from gi.repository import GObject -import gps from math import pi from math import cos from math import sin @@ -25,6 +18,18 @@ from math import sqrt from math import radians from socket import error as SocketError +import gps + +import cairo + +# Gtk3 imports. Gtk3 requires the require_version(), which then causes +# pylint to complain about the subsequent "non-top" imports. +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk # pylint: disable=wrong-import-position +from gi.repository import Gdk # pylint: disable=wrong-import-position +from gi.repository import GObject # pylint: disable=wrong-import-position + class Speedometer(Gtk.DrawingArea): def __init__(self, speed_unit=None):