Skip to content

Commit

Permalink
Update to Black 22.1.0 (#2212)
Browse files Browse the repository at this point in the history
Black is no longer a beta and has a (more strict) stability policy in place.
Changes are expected to happen over years and with updating Python versions (removing the old ones to be exact).

The changes in formatting are specialized no-spaces style for simple operands of power operator and better formatting of a complex if statement.

Python 3.10 is now among target versions. File which had to be ignored by Black due to a, now fixed, bug in Black is not ignored anymore.

In CI, matrix is used to define variables for versions (as in Pylint workflow and workflows with actual matrix). Workflow's on now specifies branches and tags for push.
  • Loading branch information
wenzeslaus committed Feb 16, 2022
1 parent bba41c0 commit e171096
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 33 deletions.
27 changes: 21 additions & 6 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
name: Python Black Formatting

on:
- push
- pull_request
push:
branches:
- main
- releasebranch_*
tags:
- "*.*.*"
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.1.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
1 change: 0 additions & 1 deletion gui/wxpython/dbmgr/vinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def GetUnicodeValue(value):
else:
return str(value)


else:

def GetUnicodeValue(value):
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/gcp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,7 @@ def RMSError(self, xygroup, order):
# SD
if GCPcount > 0:
self.rmsmean = sum_fwd_err / GCPcount
self.rmssd = (sumsq_fwd_err - self.rmsmean ** 2) ** 0.5
self.rmssd = (sumsq_fwd_err - self.rmsmean**2) ** 0.5
self.rmsthresh = self.rmsmean + sdfactor * self.rmssd
else:
self.rmsthresh = 0
Expand Down
1 change: 0 additions & 1 deletion gui/wxpython/gui_core/wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ def __init__(self):
self.EnableCheckBoxes(True)
self.AssignImageList(wx.ImageList(16, 16), wx.IMAGE_LIST_SMALL)


else:
import wx.lib.mixins.listctrl as listmix

Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/image2target/ii2t_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2052,7 +2052,7 @@ def RMSError(self, xygroup, order):
# SD
if GCPcount > 0:
self.rmsmean = sum_fwd_err / GCPcount
self.rmssd = (sumsq_fwd_err - self.rmsmean ** 2) ** 0.5
self.rmssd = (sumsq_fwd_err - self.rmsmean**2) ** 0.5
self.rmsthresh = self.rmsmean + sdfactor * self.rmssd
else:
self.rmsthresh = 0
Expand Down
14 changes: 5 additions & 9 deletions gui/wxpython/lmgr/layertree.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,15 +515,11 @@ def OnLayerContextMenu(self, event):
wx.EVT_MENU, self.OnPopupProperties, id=self.popupID["properties"]
)

if (
ltype
in (
"raster",
"vector",
"raster_3d",
)
and self.mapdisplay.IsPaneShown("3d")
):
if ltype in (
"raster",
"vector",
"raster_3d",
) and self.mapdisplay.IsPaneShown("3d"):
self.popupMenu.Append(self.popupID["nviz"], _("3D view properties"))
self.Bind(
wx.EVT_MENU, self.OnNvizProperties, id=self.popupID["nviz"]
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/photo2image/ip2i_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ def RMSError(self, xygroup, order):
# SD
if GCPcount > 0:
self.rmsmean = sum_fwd_err / GCPcount
self.rmssd = (sumsq_fwd_err - self.rmsmean ** 2) ** 0.5
self.rmssd = (sumsq_fwd_err - self.rmsmean**2) ** 0.5
self.rmsthresh = self.rmsmean + sdfactor * self.rmssd
else:
self.rmsthresh = 0
Expand Down
7 changes: 1 addition & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.black]
line-length = 88
target-version = ['py36', 'py37', 'py38', 'py39']
target-version = ['py36', 'py37', 'py38', 'py39', 'py310']
include = '\.pyi?$'
exclude = '''
(
Expand All @@ -19,11 +19,6 @@ exclude = '''
| dist\..*
)/
| python/libgrass_interface_generator/
# Bug in Black related to r-string prefix capitalization reformats
# a line in this file unnecessarily. File is however fully Black-formatted
# at the time of writing.
# https://github.com/psf/black/issues/1244
| python/grass/pygrass/utils.py
)
'''

Expand Down
2 changes: 1 addition & 1 deletion python/grass/gunittest/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def check_text_ellipsis_doctest(reference, actual):


# optimal size depends on file system and maybe on hasher.block_size
_BUFFER_SIZE = 2 ** 16
_BUFFER_SIZE = 2**16


# TODO: accept also open file object
Expand Down
2 changes: 1 addition & 1 deletion python/grass/imaging/images2gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def getAppExt(self, loops=float("inf")):
"""

if loops == 0 or loops == float("inf"):
loops = 2 ** 16 - 1
loops = 2**16 - 1
# bb = ""
# application extension should not be used
# (the extension interprets zero loops
Expand Down
2 changes: 1 addition & 1 deletion python/grass/imaging/images2swf.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def floatsToBits(arr):
i1 = int(i)
i2 = i - i1
bits += intToBits(i1, 15)
bits += intToBits(i2 * 2 ** 16, 16)
bits += intToBits(i2 * 2**16, 16)
return bits


Expand Down
4 changes: 2 additions & 2 deletions python/grass/script/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def mapcalc(
"""

if seed == "auto":
seed = hash((os.getpid(), time.time())) % (2 ** 32)
seed = hash((os.getpid(), time.time())) % (2**32)

t = string.Template(exp)
e = t.substitute(**kwargs)
Expand Down Expand Up @@ -177,7 +177,7 @@ def mapcalc_start(
"""

if seed == "auto":
seed = hash((os.getpid(), time.time())) % (2 ** 32)
seed = hash((os.getpid(), time.time())) % (2**32)

t = string.Template(exp)
e = t.substitute(**kwargs)
Expand Down
2 changes: 1 addition & 1 deletion python/grass/script/raster3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def mapcalc3d(
"""

if seed == "auto":
seed = hash((os.getpid(), time.time())) % (2 ** 32)
seed = hash((os.getpid(), time.time())) % (2**32)

t = string.Template(exp)
e = t.substitute(**kwargs)
Expand Down
2 changes: 1 addition & 1 deletion python/grass/script/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def float_or_dms(s):
"""
if s[-1] in ["E", "W", "N", "S"]:
s = s[:-1]
return sum(float(x) / 60 ** n for (n, x) in enumerate(s.split(":")))
return sum(float(x) / 60**n for (n, x) in enumerate(s.split(":")))


def separator(sep):
Expand Down

0 comments on commit e171096

Please sign in to comment.