Skip to content

Commit

Permalink
Update to Black 22.3.0 (#723)
Browse files Browse the repository at this point in the history
- A new version of Click broke Black. The new version of Black fixes the issue.
- New stable version of Black (22.1, 22.3) changes some of the code formatting.
- Targeting Python >=3.7 adds trailing comma after `**kwargs`.
- Strings prefixed by u are replaced by plain strings which are Unicode in Python 3.
- Changes applied to all files.
- Python 2 files are now ignored (to be fixed or removed in the future).
- CI workflow synced to core repo.
- See also OSGeo/grass#2212 for the update to stable Black in core repo.
- See also OSGeo/grass#2286 for the Click-related update.
  • Loading branch information
wenzeslaus committed Mar 30, 2022
1 parent 96671dc commit 25b0a99
Show file tree
Hide file tree
Showing 63 changed files with 473 additions and 434 deletions.
24 changes: 18 additions & 6 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
name: Python Black Formatting

on:
- push
- pull_request
push:
branches:
- grass*
pull_request:

jobs:
run-black:
name: Check
runs-on: ubuntu-20.04
name: Black ${{ matrix.black-version }}

# Using matrix just to get variables which are not environmental variables
# and also to sync with other workflows which use matrix.
strategy:
matrix:
include:
- os: ubuntu-20.04
python-version: "3.10"
black-version: "22.3.0"

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: ${{ matrix.python-version }}

- name: Install
run: |
python -m pip install --upgrade pip
pip install black==21.5b1
pip install black==${{ matrix.black-version }}
- name: Run Black
run: |
Expand Down
16 changes: 16 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[tool.black]
line-length = 88
target-version = ['py37', 'py38', 'py39', 'py310']
include = '\.pyi?$'
exclude = '''
(
Expand All @@ -17,5 +18,20 @@ exclude = '''
| bin\..*
| dist\..*
)/
| src/hadoop/hd/dependency.py
| src/hadoop/hd/hd.hive.select/hd.hive.select.py
| src/hadoop/hd/hdfsgrass/hdfs_grass_util.py
| src/hadoop/hd/hdfswrapper/webhdfs_hook.py
| src/gui/wxpython/wx.rdigit/rdigit/main.py
| src/gui/wxpython/wx.stream/gui_modules/ImageViewer.py
| src/gui/wxpython/wx.stream/gui_modules/rstream_panelOne.py
| src/gui/wxpython/wx.wms/parse.py
| src/gui/wxpython/wx.wms/wmsmenu.py
| src/gui/wxpython/wx.wms/LoadConfig.py
| src/gui/wxpython/newgui/wxgui.py
| src/gui/wxpython/newgui/render2.py
| src/gui/wxpython/newgui/mapwindow.py
| src/gui/wxpython/newgui/frame.py
| src/raster/r.agent/tests/test_grassland.py
)
'''
2 changes: 1 addition & 1 deletion src/display/d.vect.thematic2/d.vect.thematic2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ def main():
icon=icon,
size=ptsize,
quiet=True,
**kwargs
**kwargs,
)

if themetype != "graduated_lines":
Expand Down
2 changes: 1 addition & 1 deletion src/general/g.rename.many/g.rename.many.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def map_exists(name, type, mapset=None):
mapset=mapset,
stdout=PIPE,
stderr=PIPE,
**extra_params
**extra_params,
)
output, errors = process.communicate()
info = parse_key_val(output)
Expand Down
6 changes: 3 additions & 3 deletions src/gui/wxpython/newgui/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(
Map=Map(),
auimgr=None,
name=None,
**kwargs
**kwargs,
):
"""!
Expand All @@ -100,7 +100,7 @@ def __init__(
style=style,
auimgr=auimgr,
name=name,
**kwargs
**kwargs,
)

self.Map = Map # instance of render.Map
Expand Down Expand Up @@ -192,7 +192,7 @@ def __init__(
| CT.TR_ROW_LINES
| CT.TR_FULL_ROW_HIGHLIGHT
| CT.TR_MULTIPLE,
**kwargs
**kwargs,
):

wx.Panel.__init__(self, parent=parent, id=id, style=style)
Expand Down
84 changes: 48 additions & 36 deletions src/gui/wxpython/wx.mwprecip/mw3.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,21 +474,24 @@ def createWin(self):
def sumValues(self):
##summing values per (->user)timestep interval
self.viewDB = "computed_precip_sum"
sql = "CREATE %s %s.%s as \
sql = (
"CREATE %s %s.%s as \
SELECT %s ,round(avg(precip)::numeric,3) as %s, date_trunc('%s',time)as time \
FROM %s.%s \
GROUP BY %s, date_trunc('%s',time)\
ORDER BY time" % (
self.viewStatement,
self.schema,
self.viewDB,
self.typeID,
self.database.precipColName,
self.sumStep,
self.schema,
self.tbName,
self.typeID,
self.sumStep,
ORDER BY time"
% (
self.viewStatement,
self.schema,
self.viewDB,
self.typeID,
self.database.precipColName,
self.sumStep,
self.schema,
self.tbName,
self.typeID,
self.sumStep,
)
)
self.database.connection.executeSql(sql, False, True)

Expand Down Expand Up @@ -560,17 +563,20 @@ def removeLinksOthers(self):
sql = "DROP TABLE %s.linktmp " % self.schema
self.database.connection.executeSql(sql, False, True)

sql = "DELETE FROM %s.%s WHERE NOT EXISTS\
sql = (
"DELETE FROM %s.%s WHERE NOT EXISTS\
(SELECT %s FROM %s.linktmp \
WHERE %s.%s.%s=linksonly.%s)" % (
self.schema,
self.viewDB,
self.typeID,
self.schema,
self.schema,
self.viewDB,
self.typeID,
self.typeID,
WHERE %s.%s.%s=linksonly.%s)"
% (
self.schema,
self.viewDB,
self.typeID,
self.schema,
self.schema,
self.viewDB,
self.typeID,
self.typeID,
)
)
self.database.connection.executeSql(sql, False, True)

Expand Down Expand Up @@ -612,15 +618,18 @@ def crateTimeWin(self):
tgrass = view_name + "|" + str(cur_timestamp) + "\n"
tgrass_vector.append(tgrass)

sql = "CREATE TABLE %s.%s as\
sql = (
"CREATE TABLE %s.%s as\
SELECT * from %s.%s \
WHERE time=(timestamp'%s'+ %s * interval '1 second')" % (
self.schema,
view_name,
self.schema,
self.viewDB,
self.timestamp_min,
time_const,
WHERE time=(timestamp'%s'+ %s * interval '1 second')"
% (
self.schema,
view_name,
self.schema,
self.viewDB,
self.timestamp_min,
time_const,
)
)

data = self.database.connection.executeSql(sql, False, True)
Expand Down Expand Up @@ -1158,15 +1167,18 @@ def checkValidity(freq, polarization):
self.timeWin.timestamp_max)
resu = self.database.connection.executeSql(sql, True, True)
"""
sql = "CREATE TABLE %s.record AS (SELECT linkid,time,txpower-rxpower as a \
sql = (
"CREATE TABLE %s.record AS (SELECT linkid,time,txpower-rxpower as a \
FROM %s.record \
WHERE time >= '%s' AND\
time <= '%s' \
ORDER by recordid);" % (
self.database.schema,
self.database.dataSchema,
self.timeWin.timestamp_min,
self.timeWin.timestamp_max,
ORDER by recordid);"
% (
self.database.schema,
self.database.dataSchema,
self.timeWin.timestamp_min,
self.timeWin.timestamp_max,
)
)
self.database.connection.executeSql(sql, False, True)

Expand Down
2 changes: 1 addition & 1 deletion src/gui/wxpython/wx.rdigit/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(
toolbars=["digitMap", "rdigit"],
size=(875, 600),
name="RDigitWindow",
**kwargs
**kwargs,
):
"""!
@param parent (no parent is expected)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/wxpython/wx.rdigit/rdigit/dialogs_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(
disableAdd=False,
showType=False,
style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
*kwargs
*kwargs,
):
"""!Dialog for creating new vector map
Expand Down
4 changes: 2 additions & 2 deletions src/gui/wxpython/wx.rdigit/rdigit/mapwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(
tree=None,
lmgr=None,
style=wx.NO_FULL_REPAINT_ON_RESIZE,
**kwargs
**kwargs,
):
BufferedWindow.__init__(
self,
Expand All @@ -54,7 +54,7 @@ def __init__(
frame=frame,
tree=tree,
style=style,
**kwargs
**kwargs,
)
self.lmgr = lmgr
self.pdcVector = wx.PseudoDC()
Expand Down
4 changes: 2 additions & 2 deletions src/gui/wxpython/wx.stream/gui_modules/rstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(
id=wx.ID_ANY,
style=wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER,
title=_("GRASS GIS Hydrological Modelling Utility"),
**kwargs
**kwargs,
):
"""!Main window of r.stream's GUI
Expand All @@ -92,7 +92,7 @@ def __init__(
title=title,
name="RStream",
size=(600, 900),
**kwargs
**kwargs,
)
self.SetIcon(
wx.Icon(os.path.join(globalvar.ETCICONDIR, "grass.ico"), wx.BITMAP_TYPE_ICO)
Expand Down
4 changes: 2 additions & 2 deletions src/imagery/i.ann.maskrcnn/maskrcnnlib/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ def smooth_l1_loss(y_true, y_pred):
"""
diff = K.abs(y_true - y_pred)
less_than_one = K.cast(K.less(diff, 1.0), "float32")
loss = (less_than_one * 0.5 * diff ** 2) + (1 - less_than_one) * (diff - 0.5)
loss = (less_than_one * 0.5 * diff**2) + (1 - less_than_one) * (diff - 0.5)
return loss


Expand Down Expand Up @@ -2067,7 +2067,7 @@ def build(self, mode, config):

# Image size must be dividable by 2 multiple times
h, w = config.IMAGE_SHAPE[:2]
if h / 2 ** 6 != int(h / 2 ** 6) or w / 2 ** 6 != int(w / 2 ** 6):
if h / 2**6 != int(h / 2**6) or w / 2**6 != int(w / 2**6):
raise Exception(
"Image size must be dividable by 2 at least 6 times "
"to avoid fractions when downscaling and upscaling."
Expand Down
4 changes: 2 additions & 2 deletions src/imagery/i.cutlines/i.cutlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def main():
overlap=overlap,
processes=processes,
split=False,
**kwargs
**kwargs,
)
grd.run()
else:
Expand Down Expand Up @@ -299,7 +299,7 @@ def main():
processes=processes,
split=False,
flags="n",
**kwargs
**kwargs,
)
grd.run()
else:
Expand Down
4 changes: 2 additions & 2 deletions src/imagery/i.gabor/i.gabor.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def gabor2d(win_size, orientation=0, wavelength=5, aspect=0.5, offset=0, ntype="
xr = x * np.cos(orientation) + y * np.sin(orientation)
yr = -x * np.sin(orientation) + y * np.cos(orientation)

gaussian = np.exp(-((xr ** 2 + aspect ** 2 * yr ** 2) / (2 * stddev ** 2)))
gaussian = np.exp(-((xr**2 + aspect**2 * yr**2) / (2 * stddev**2)))
if ntype == "imag":
sf = np.sin(2 * np.pi * xr / wavelength + offset)
else:
Expand Down Expand Up @@ -162,7 +162,7 @@ def main():
if flags["q"]:
if not threshold:
grass.fatal(_("A percentile threshold is needed to quantify."))
q = [2 ** i for i in range(len(orientation))]
q = [2**i for i in range(len(orientation))]
else:
q = 0

Expand Down
2 changes: 1 addition & 1 deletion src/imagery/i.landsat8.swlst/randomness.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def random_digital_numbers(count=2):
digital_numbers = []

for dn in range(0, count):
digital_numbers.append(random.randint(1, 2 ** 12))
digital_numbers.append(random.randint(1, 2**12))

if count == 1:
return digital_numbers[0]
Expand Down
4 changes: 2 additions & 2 deletions src/imagery/i.landsat8.swlst/split_window_lst.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,10 @@ def compute_lst(self, t10, t11, coefficients):

# addends
a = b0
b1 = b1 + b2 * (1 - avg) / avg + b3 * delta / avg ** 2
b1 = b1 + b2 * (1 - avg) / avg + b3 * delta / avg**2
b2 = (t10 + t11) / 2
b = b1 * b2
c1 = b4 + b5 * (1 - avg) / avg + b6 * delta / avg ** 2
c1 = b4 + b5 * (1 - avg) / avg + b6 * delta / avg**2
c2 = (t10 - t11) / 2
c = c1 * c2
d = b7 * (t10 - t11) ** 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def calibrate(self, dn):
build a calibration equation for the requested satellite and year.
"""
if self.is_dn_valid(dn):
cdn = self.c0 + (self.c1 * dn) + (self.c2 * (dn ** 2))
cdn = self.c0 + (self.c1 * dn) + (self.c2 * (dn**2))
model = EQUATIONS[self.author].model # look in equations.py
self._model = model.format(dn=dn, cdn=cdn, c0=self.c0, c1=self.c1, c2=self.c2)
return cdn
Expand Down Expand Up @@ -289,7 +289,7 @@ def calibrate(self, dn):
build a calibration equation for the requested satellite and year.
"""
if self.is_dn_valid(dn):
cdn = self.c0 + (self.c1 * dn) + (self.c2 * (dn ** 2))
cdn = self.c0 + (self.c1 * dn) + (self.c2 * (dn**2))

# Update _model as well!
model = "{cdn} = ({c0}) + ({c1}) * {dn} + ({c2}) * {dn}^2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def calibrate_digital_number(dn, c0, c1, c2):
"The provided Digital Number value is out of the " "expected range [0, 63]"
)

return c0 + (c1 * dn) + (c2 * (dn ** 2))
return c0 + (c1 * dn) + (c2 * (dn**2))


def test_model(author):
Expand Down

0 comments on commit 25b0a99

Please sign in to comment.