Skip to content

Commit

Permalink
minor pep8 blemishes missed by black
Browse files Browse the repository at this point in the history
  • Loading branch information
phobson committed Oct 21, 2019
1 parent 10c9ce7 commit 2f077d3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
14 changes: 7 additions & 7 deletions metar/Datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def string(self, units=None):
if not units:
units = self._units
else:
if not units.upper() in pressure.legal_units:
if units.upper() not in pressure.legal_units:
raise UnitsError("unrecognized pressure unit: '" + units + "'")
units = units.upper()
val = self.value(units)
Expand All @@ -143,10 +143,10 @@ def __init__(self, value, units=None, gtlt=None):
if not units:
self._units = "MPS"
else:
if not units.upper() in speed.legal_units:
if units.upper() not in speed.legal_units:
raise UnitsError("unrecognized speed unit: '" + units + "'")
self._units = units.upper()
if gtlt and not gtlt in speed.legal_gtlt:
if gtlt and gtlt not in speed.legal_gtlt:
raise ValueError(
"unrecognized greater-than/less-than symbol: '" + gtlt + "'"
)
Expand Down Expand Up @@ -188,7 +188,7 @@ def string(self, units=None):
if not units:
units = self._units
else:
if not units.upper() in speed.legal_units:
if units.upper() not in speed.legal_units:
raise UnitsError("unrecognized speed unit: '" + units + "'")
units = units.upper()
val = self.value(units)
Expand Down Expand Up @@ -217,7 +217,7 @@ def __init__(self, value, units=None, gtlt=None):
if not units:
self._units = "M"
else:
if not units.upper() in distance.legal_units:
if units.upper() not in distance.legal_units:
raise UnitsError("unrecognized distance unit: '" + units + "'")
self._units = units.upper()

Expand All @@ -230,7 +230,7 @@ def __init__(self, value, units=None, gtlt=None):
gtlt = ">"
except:
pass
if gtlt and not gtlt in distance.legal_gtlt:
if gtlt and gtlt not in distance.legal_gtlt:
raise ValueError(
"unrecognized greater-than/less-than symbol: '" + gtlt + "'"
)
Expand Down Expand Up @@ -401,7 +401,7 @@ def __init__(self, value, units=None, gtlt=None):
gtlt = ">"
except:
pass
if gtlt and not gtlt in precipitation.legal_gtlt:
if gtlt and gtlt not in precipitation.legal_gtlt:
raise ValueError(
"unrecognized greater-than/less-than symbol: '" + gtlt + "'"
)
Expand Down
17 changes: 7 additions & 10 deletions metar/Metar.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# logger
_logger = logging.getLogger(__name__)


# Exceptions
class ParserError(Exception):
"""Exception raised when an unparseable group is found in body of the report."""
Expand Down Expand Up @@ -318,6 +319,7 @@ def xlate_loc(loc):
"COR": "manually corrected report",
}


# Helper functions
def _sanitize(code):
"""Some string prep to improve parsing fidelity."""
Expand Down Expand Up @@ -439,7 +441,7 @@ def __init__(self, metarcode, month=None, year=None, utcdelta=None, strict=True)
if debug:
_report_match(handler, m.group())
handler(self, m.groupdict())
code = code[m.end() :]
code = code[m.end():]
if self._trend:
code = self._do_trend_handlers(code)
if not repeatable:
Expand All @@ -459,7 +461,7 @@ def __init__(self, metarcode, month=None, year=None, utcdelta=None, strict=True)
if debug:
_report_match(handler, m.group())
handler(self, m.groupdict())
code = code[m.end() :]
code = code[m.end():]
igroup = ifailed
ifailed = -2 # if it's still -2 when we run out of main-body
# groups, we'll try parsing this group as a remark
Expand Down Expand Up @@ -515,7 +517,7 @@ def _do_trend_handlers(self, code):
_report_match(handler, m.group())
self._trend_groups.append(m.group().strip())
handler(self, m.groupdict())
code = code[m.end() :]
code = code[m.end():]
if not repeatable:
break
m = pattern.match(code)
Expand Down Expand Up @@ -855,12 +857,7 @@ def _handlePrecip24hrRemark(self, d):
"""
value = float(d["precip"]) / 100.0
if d["type"] == "6":
if (
self.cycle == 3
or self.cycle == 9
or self.cycle == 15
or self.cycle == 21
):
if self.cycle in [3, 9, 15, 21]:
self.precip_3hr = precipitation(value, "IN")
else:
self.precip_6hr = precipitation(value, "IN")
Expand Down Expand Up @@ -1209,7 +1206,7 @@ def peak_wind(self, units="KT"):
text = wind_speed
else:
text = "%s at %s" % (self.wind_dir_peak.compass(), wind_speed)
if not self.peak_wind_time is None:
if self.peak_wind_time is not None:
text += " at %s" % self.peak_wind_time.strftime("%H:%M")
return text

Expand Down
6 changes: 4 additions & 2 deletions parse_metar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
#
from __future__ import print_function

import sys, os
import sys
import os
from metar import Metar
import string
import getopt
import profile, pstats
import profile
import pstats


def usage():
Expand Down
7 changes: 6 additions & 1 deletion sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@
from metar import Metar

# A sample METAR report
code = "METAR KEWR 111851Z VRB03G19KT 2SM R04R/3000VP6000FT TSRA BR FEW015 BKN040CB BKN065 OVC200 22/22 A2987 RMK AO2 PK WND 29028/1817 WSHFT 1812 TSB05RAB22 SLP114 FRQ LTGICCCCG TS OHD AND NW-N-E MOV NE P0013 T02270215"
code = (
"METAR KEWR 111851Z VRB03G19KT 2SM R04R/3000VP6000FT TSRA BR FEW015 "
"BKN040CB BKN065 OVC200 22/22 A2987 RMK AO2 PK WND 29028/1817 WSHFT "
"1812 TSB05RAB22 SLP114 FRQ LTGICCCCG TS OHD AND NW-N-E MOV NE P0013 "
"T02270215"
)

print("-----------------------------------------------------------------------")
print("METAR: ", code)
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[aliases]
test = pytest

[pep8]
max-line-length = 90

0 comments on commit 2f077d3

Please sign in to comment.