Skip to content

Commit

Permalink
python: Update black to 24.3.0 (#1046)
Browse files Browse the repository at this point in the history
* CI(black): Bump black to 24.3.0

* CI(black): Also format Jupyter notebooks

* pre-commit: Update black version in .pre-commit-config.yaml with support for Jupyter notebooks

* Format files with new black version
  • Loading branch information
echoix committed Mar 27, 2024
1 parent aebcdc8 commit 3b09b1d
Show file tree
Hide file tree
Showing 41 changed files with 227 additions and 198 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ jobs:
include:
- os: ubuntu-22.04
python-version: "3.10"
black-version: 22.3.0
black-version: 24.3.0

runs-on: ${{ matrix.os }}
env:
TOOL_NAME: black

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
Expand All @@ -42,7 +39,7 @@ jobs:
- name: Install
run: |
python -m pip install --upgrade pip
pip install black==${{ matrix.black-version }}
pip install black[jupyter]==${{ matrix.black-version }}
- name: Run Black
run: |
Expand Down
12 changes: 9 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ repos:
rev: v0.33.0
hooks:
- id: markdownlint
- repo: https://github.com/psf/black
rev: 22.3.0
# Using this mirror lets us use mypyc-compiled black, which is about 2x faster
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.3.0
hooks:
- id: black
- id: black-jupyter
# It is recommended to specify the latest version of Python
# supported by your project here, or alternatively use
# pre-commit's default_language_version, see
# https://pre-commit.com/#top_level-default_language_version
language_version: python3.11
- repo: https://github.com/pycqa/flake8
rev: 3.9.2
hooks:
Expand Down
1 change: 1 addition & 0 deletions src/display/d.frame/d.frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
warning,
)


# check if monitor is running
def check_monitor():
return read_command("d.mon", flags="p", quiet=True).strip()
Expand Down
1 change: 1 addition & 0 deletions src/general/g.download.location/g.download.location.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class DownloadError(Exception):
# startup screen Download button
# all should go to "grass.scripts.tools"


# copy from g.extension
def move_extracted_files(extract_dir, target_dir, files):
"""Fix state of extracted file by moving them to different diretcory
Expand Down
6 changes: 0 additions & 6 deletions src/gui/wxpython/wx.metadata/mdlib/mdeditorfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@


class MdFileWork:

"""initializer of metadata in OWSLib and export OWSLib object to xml by jinja template system"""

def __init__(self, pathToXml=None):
Expand Down Expand Up @@ -190,7 +189,6 @@ def saveToXML(


class MdBox(wx.Panel):

"""widget(static box) which include metadata items (MdItem)"""

def __init__(self, parent, label="label"):
Expand Down Expand Up @@ -327,7 +325,6 @@ def removeKeywordItem(self, item):


class MdWxDuplicator:

"""duplicator of MdBox and MdItem object"""

def __init__(self, mdItems, parent, boxlabel=None, mdItemOld=None, template=None):
Expand Down Expand Up @@ -391,7 +388,6 @@ def __init__(self, mdItems, parent, boxlabel=None, mdItemOld=None, template=None
# METADATA ITEM (label+ctrlText+button(optional)+chckbox(template)
# =========================================================================
class MdItem(wx.BoxSizer):

"""main building blocks of generated GUI of editor"""

def __init__(
Expand Down Expand Up @@ -902,7 +898,6 @@ def layout(self):


class MdNotebookPage(scrolled.ScrolledPanel):

"""
every notebook page is initialized by jinjainfo::MdDescription.group (label)
"""
Expand Down Expand Up @@ -1163,7 +1158,6 @@ def layout(self):
# MAIN FRAME
# =========================================================================
class MdMainEditor(wx.Panel):

"""
main functions : self.generateGUI(): generating GUI from: editor:MdItem,MdBox,MdNotebookPage
self.createNewMD(): filling OWSLib.iso.MD_Metadata by values from generated GUI
Expand Down
1 change: 0 additions & 1 deletion src/gui/wxpython/wx.metadata/mdlib/mdgrass.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@


class GrassMD:

"""
@var self.map: name of choosen map by user
@var self.type: typ of map representation(cell, vector, r3)
Expand Down
2 changes: 0 additions & 2 deletions src/gui/wxpython/wx.metadata/mdlib/mdjinjaparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


class MdDescription:

"""Object which is initialzed by jinja template in '{# #}'"""

def __init__(
Expand Down Expand Up @@ -120,7 +119,6 @@ def addStatements1(self, stat):


class JinjaTemplateParser:

"""Parser of OWSLib tag and init. values of jinjainfo::MdDescription from jinja template."""

def __init__(self, template):
Expand Down
4 changes: 2 additions & 2 deletions src/gui/wxpython/wx.metadata/mdlib/mdpdftheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def add(self, style, alias=None):
def list(self):
styles = sorted(self.byName.items())
alii = {}
for (alias, style) in list(self.byAlias.items()):
for alias, style in list(self.byAlias.items()):
alii[style] = alias
for (name, style) in styles:
for name, style in styles:
alias = alii.get(style, None)
style.listAttrs(" ")

Expand Down
1 change: 1 addition & 0 deletions src/gui/wxpython/wx.rdigit/rdigit/toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@author Mohammed Rashad <rashadkm gmail.com>
"""

import wx
from grass.script import core as grass
from gui_core.toolbars import BaseToolbar, BaseIcons
Expand Down
1 change: 1 addition & 0 deletions src/gui/wxpython/wx.wms/ServerInfoAPIs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@author: Maris Nartiss (maris.nartiss gmail.com)
@author Sudeep Singh Walia (Indian Institute of Technology, Kharagpur , sudeep495@gmail.com)
"""

from BeautifulSoup import BeautifulSoup, Tag, BeautifulStoneSoup
import os.path

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
from datetime import *
import grass.script as gs


# bbox - get region in ll
def get_bb(vector=None):
args = {}
Expand Down
1 change: 1 addition & 0 deletions src/imagery/i.landsat8.swlst/csv_to_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import random
import functools


# helper functions
def set_csvfile():
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
# any constants? -------------------------------------------------------------
MODELS = {"elvidge": Elvidge, "liu2012": Liu2012, "wu2013": Wu2013}


# helper functions ----------------------------------------------------------
def cleanup():
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from intercalibration_coefficients import COEFFICIENTS
from intercalibration_models import Elvidge, Liu2012, Wu2013


# helper functions
def random_digital_numbers(count=3):
"""
Expand Down
14 changes: 8 additions & 6 deletions src/imagery/i.segment.uspo/i.segment.uspo.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,13 +739,15 @@ def create_optimization_list(variancelist, autocorlist, opt_function, alpha, dir
optlist = [normvariance[x] + normautocor[x] for x in range(len(normvariance))]
if opt_function == "f":
optlist = [
(1 + alpha**2)
* (
(normvariance[x] * normautocor[x])
/ float(alpha**2 * normautocor[x] + normvariance[x])
(
(1 + alpha**2)
* (
(normvariance[x] * normautocor[x])
/ float(alpha**2 * normautocor[x] + normvariance[x])
)
if (normautocor[x] + normvariance[x]) > 0
else 0
)
if (normautocor[x] + normvariance[x]) > 0
else 0
for x in range(len(normvariance))
]
return optlist
Expand Down
12 changes: 6 additions & 6 deletions src/imagery/i.sentinel/i.sentinel.import/i.sentinel.import.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,9 @@ def filter_cloud_masks(files, pattern):
if reproject:
self._args["resample"] = "nearest"
if self._projection_units_meters is True:
self._args[
"resolution_value"
] = self._raster_resolution(shadow_file[0])
self._args["resolution_value"] = (
self._raster_resolution(shadow_file[0])
)
gs.run_command(
"r.import",
input=shadow_file,
Expand Down Expand Up @@ -895,9 +895,9 @@ def _parse_mtd_file(mtd_file):
dtype=float,
)
)
meta[
"MEAN_SUN_AZIMUTH_GRID_ANGLE"
] = mean_azimuth
meta["MEAN_SUN_AZIMUTH_GRID_ANGLE"] = (
mean_azimuth
)
sa_mean = tile_angles.find("Mean_Sun_Angle")
if sa_mean is not None:
for it in list(sa_mean):
Expand Down
16 changes: 10 additions & 6 deletions src/misc/m.crawl.thredds/m.crawl.thredds.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,17 @@ def main():
dataset_urls = [
"".join(
[
service.get("service").lower() + options["separator"]
if "service" in options["print"]
else "",
(
service.get("service").lower() + options["separator"]
if "service" in options["print"]
else ""
),
service.get("url"),
options["separator"] + str(dataset.size)
if "data_size" in options["print"]
else "",
(
options["separator"] + str(dataset.size)
if "data_size" in options["print"]
else ""
),
]
)
for dataset in catalog.datasets
Expand Down
2 changes: 1 addition & 1 deletion src/misc/m.printws/m.printws.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ def main():
)

textmacros = {}
#%nam% macros are kept for backward compatibility
# %nam% macros are kept for backward compatibility
textmacros["%TIME24%"] = time.strftime("%H:%M:%S")
textmacros["%DATEYMD%"] = time.strftime("%Y.%m.%d")
textmacros["%DATEMDY%"] = time.strftime("%m/%d/%Y")
Expand Down
1 change: 1 addition & 0 deletions src/raster/r.agent/libagent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
License (>=v2). Read the file COPYING that comes with GRASS
for details.
"""

# from random import choice, randint
from random import randint

Expand Down
1 change: 1 addition & 0 deletions src/raster/r.basin/r.basin.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@

gettext.install("grassmods", os.path.join(os.getenv("GISBASE"), "locale"))


# check requirements
def check_progs():
found_missing = False
Expand Down
1 change: 1 addition & 0 deletions src/raster/r.centroids/testsuite/test_r_centroids.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from grass.gunittest.case import TestCase
from grass.gunittest.main import test


# Tests
class TestCentroids(TestCase):
# Setup variables to be used for outputs
Expand Down
4 changes: 2 additions & 2 deletions src/raster/r.forcircular/r.forcircular.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,14 +601,14 @@ def main(opts, flgs):
c_hf_noslope = {
"forwarder": 1,
"skidder": 0.8,
"tractor": 0.65
"tractor": 0.65,
# ,"other": 0.5
}

c_c_noslope = {
"forwarder": 1.2,
"skidder": 1,
"tractor": 0.85
"tractor": 0.85,
# ,"other": 0.7
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,7 @@ def add_columns(vector, cols):
def diam_pen(discharge, length, gross_head, percentage, epsilon=0.015):
def diam(x, *args):
q, l, h, p, e = args
return sqrt(
(100 * 8 * l * q**2) / (p * h * pi**2 * 9.81 * x**5)
) + 2 * log10(
return sqrt((100 * 8 * l * q**2) / (p * h * pi**2 * 9.81 * x**5)) + 2 * log10(
(e * 0.001) / (3.71 * x)
+ (2.51 * 0.000001 * pi)
/ (4 * q * l)
Expand Down Expand Up @@ -339,9 +337,7 @@ def coeff_f(x, *args):

out = fsolve(coeff_f, 0, args=(discharge, diameter, epsilon))
f = 1 / out**2
h_colebrooke = (f[0] * 8 * length * discharge**2) / (
pi**2 * diameter**5 * 9.81
)
h_colebrooke = (f[0] * 8 * length * discharge**2) / (pi**2 * diameter**5 * 9.81)
return h_colebrooke


Expand Down
6 changes: 3 additions & 3 deletions src/raster/r.in.wcs/r.in.wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,9 @@ def main():
"""Main function"""
flag_c = flags["c"]

options[
"version"
] = "1.0.0" # right now only supported version, therefore not in GUI
options["version"] = (
"1.0.0" # right now only supported version, therefore not in GUI
)

grass.debug("Using GDAL WCS driver")
wcs = WCSGdalDrv() # only supported driver
Expand Down
1 change: 1 addition & 0 deletions src/raster/r.landscape.evol.old/r.landscape.evol.old.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@
sys.path.append(grass_install_tree + os.sep + "etc" + os.sep + "python")
import grass.script as grass


# Now define "main", our main block of code, here defined because of the way g.parser needs to be called with python codes for grass (see below)
# m = last iteration number, o = iteration number, p = prefx, q = statsout, r = resolution of input elev map, s = master list of lists of climate data
def main(m, o, p, q, r, s):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@


def load_data(file_path, labeled=False, skip_header=1, scale=True):

"""
Load the data from a csv file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import sys
import grass.script as gscript


# check requirements
def check_progs():
found_missing = False
Expand Down

0 comments on commit 3b09b1d

Please sign in to comment.