From 45486ea1beb4547de05ef00a7221703708071952 Mon Sep 17 00:00:00 2001 From: Tomas Kral Date: Wed, 24 Sep 2025 12:52:59 +0000 Subject: [PATCH 1/4] Fix/suppress flake8 violations --- eccodes/highlevel/_bufr/__init__.py | 6 ++++++ eccodes/highlevel/_bufr/coder.py | 5 ++++- eccodes/highlevel/_bufr/common.py | 27 ++++++++++----------------- eccodes/highlevel/_bufr/data.py | 4 ++++ eccodes/highlevel/_bufr/header.py | 2 ++ eccodes/highlevel/_bufr/helpers.py | 2 ++ eccodes/highlevel/_bufr/message.py | 2 ++ eccodes/highlevel/_bufr/tables.py | 9 ++++----- eccodes/highlevel/_bufr/tree.py | 3 +++ eccodes/highlevel/_bufr/view.py | 2 +- eccodes/highlevel/message.py | 2 +- tox.ini | 11 +++++++++++ 12 files changed, 50 insertions(+), 25 deletions(-) diff --git a/eccodes/highlevel/_bufr/__init__.py b/eccodes/highlevel/_bufr/__init__.py index 32f4bda..7580562 100644 --- a/eccodes/highlevel/_bufr/__init__.py +++ b/eccodes/highlevel/_bufr/__init__.py @@ -5,3 +5,9 @@ from .common import change_behaviour, get_behaviour, set_behaviour from .helpers import missing_of from .message import BUFRMessage + +__all__ = [ + 'change_behaviour', 'get_behaviour', 'set_behaviour', + 'missing_of', + 'BUFRMessage', +] diff --git a/eccodes/highlevel/_bufr/coder.py b/eccodes/highlevel/_bufr/coder.py index e96a1ce..1c92017 100644 --- a/eccodes/highlevel/_bufr/coder.py +++ b/eccodes/highlevel/_bufr/coder.py @@ -8,10 +8,13 @@ import io import warnings +from functools import cached_property + +# flake8: noqa: F405 from .common import * from .helpers import ensure_array, missing_of -from .tables import Code, Element, Tables, Version +from .tables import Tables, Version TEMPLATE_KEYS = dict.fromkeys( [ diff --git a/eccodes/highlevel/_bufr/common.py b/eccodes/highlevel/_bufr/common.py index c336792..b3eb962 100644 --- a/eccodes/highlevel/_bufr/common.py +++ b/eccodes/highlevel/_bufr/common.py @@ -8,15 +8,12 @@ import datetime as dt import enum -import re -import sys -from collections import Counter, abc, defaultdict +from collections import Counter, abc, defaultdict # noqa +from contextlib import contextmanager from copy import deepcopy -from dataclasses import dataclass, field, fields +from dataclasses import dataclass, field, fields # noqa from enum import auto -from functools import cached_property -from pathlib import Path -from typing import ( +from typing import ( # noqa Any, BinaryIO, Callable, @@ -33,12 +30,11 @@ import numpy import numpy as np -from numpy.ma import MaskedArray -from numpy.typing import DTypeLike, NDArray +from numpy.ma import MaskedArray # noqa +from numpy.typing import DTypeLike, NDArray # noqa -import eccodes from eccodes.eccodes import KeyValueNotFoundError as NotFoundError -from eccodes.eccodes import * +from eccodes.eccodes import * # noqa from .tables import Element @@ -88,22 +84,19 @@ class Behaviour: def get_behaviour(): - global current_behaviour + global current_behaviour # noqa return deepcopy(current_behaviour) def set_behaviour(new_behaviour): - global current_behaviour + global current_behaviour # noqa for f in fields(new_behaviour): setattr(current_behaviour, f.name, getattr(new_behaviour, f.name)) -from contextlib import contextmanager - - @contextmanager def change_behaviour(): - global current_behaviour + global current_behaviour # noqa saved_behaviour = get_behaviour() try: yield current_behaviour diff --git a/eccodes/highlevel/_bufr/data.py b/eccodes/highlevel/_bufr/data.py index bedbcf2..cbc0dfd 100644 --- a/eccodes/highlevel/_bufr/data.py +++ b/eccodes/highlevel/_bufr/data.py @@ -6,6 +6,10 @@ # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. +from functools import cached_property + +# flake8: noqa: 405 + from .coder import Coder from .common import * from .helpers import ensure_masked_array, flatten, missing_of diff --git a/eccodes/highlevel/_bufr/header.py b/eccodes/highlevel/_bufr/header.py index 7cc8de9..55f3722 100644 --- a/eccodes/highlevel/_bufr/header.py +++ b/eccodes/highlevel/_bufr/header.py @@ -6,6 +6,8 @@ # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. +# flake8: noqa: 405 + from .coder import INPUT_TEMPLATE_KEYS, TEMPLATE_KEYS, Coder from .common import * from .helpers import get_date, get_datetime, get_time, set_date, set_datetime, set_time diff --git a/eccodes/highlevel/_bufr/helpers.py b/eccodes/highlevel/_bufr/helpers.py index 5d597c1..1fc00b4 100644 --- a/eccodes/highlevel/_bufr/helpers.py +++ b/eccodes/highlevel/_bufr/helpers.py @@ -6,6 +6,8 @@ # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. +# flake8: noqa: 405 + from .common import * diff --git a/eccodes/highlevel/_bufr/message.py b/eccodes/highlevel/_bufr/message.py index b428803..9f10180 100644 --- a/eccodes/highlevel/_bufr/message.py +++ b/eccodes/highlevel/_bufr/message.py @@ -8,6 +8,8 @@ import datetime as dt +# flake8: noqa: 405 + from .coder import Coder from .common import * from .data import Data diff --git a/eccodes/highlevel/_bufr/tables.py b/eccodes/highlevel/_bufr/tables.py index 348f253..31a2e2e 100644 --- a/eccodes/highlevel/_bufr/tables.py +++ b/eccodes/highlevel/_bufr/tables.py @@ -7,11 +7,13 @@ # nor does it submit to any jurisdiction. import csv +import ctypes +import os import re from collections import ChainMap, UserDict -from dataclasses import dataclass, field +from dataclasses import dataclass from pathlib import Path -from typing import Iterator, List, Optional, Tuple, Union +from typing import Iterator, List, Tuple, Union import eccodes import gribapi @@ -208,9 +210,6 @@ def expand_descriptors( yield Descriptor(code, name) -import ctypes -import os - libc = ctypes.CDLL(None, winmode=0) # automatically finds and loads the C standard library fseek = libc.fseek diff --git a/eccodes/highlevel/_bufr/tree.py b/eccodes/highlevel/_bufr/tree.py index 80edd6a..f1251cb 100644 --- a/eccodes/highlevel/_bufr/tree.py +++ b/eccodes/highlevel/_bufr/tree.py @@ -6,9 +6,12 @@ # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. +import re from copy import copy from itertools import repeat +# flake8: noqa: 405 + from .common import * from .helpers import RaggedArray, SingletonDict from .tables import Code, Element diff --git a/eccodes/highlevel/_bufr/view.py b/eccodes/highlevel/_bufr/view.py index 0bb9aef..7b7513d 100644 --- a/eccodes/highlevel/_bufr/view.py +++ b/eccodes/highlevel/_bufr/view.py @@ -6,7 +6,7 @@ # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. -import datetime as dt +# flake8: noqa: 405 from .common import * from .helpers import get_datetime, set_datetime diff --git a/eccodes/highlevel/message.py b/eccodes/highlevel/message.py index e20884c..8b5b7e5 100644 --- a/eccodes/highlevel/message.py +++ b/eccodes/highlevel/message.py @@ -5,7 +5,7 @@ import eccodes -from ._bufr import BUFRMessage +from ._bufr import BUFRMessage # noqa _TYPES_MAP = { "float": float, diff --git a/tox.ini b/tox.ini index 4e7403a..dfd892f 100644 --- a/tox.ini +++ b/tox.ini @@ -22,11 +22,22 @@ deps = commands = python setup.py test [flake8] +alias pip='pip --disable-pip-version-check' +; E221 = multiple spaces before operator +; E226 = missing whitespace around arithmetic operator +; E227 = missing whitespace around bitwise or shift operator +; E231 = missing whitespace after , +; E241 = multiple spaces after ',' +; E261 = at least two spaces before inline comment +; E272 = multiple spaces before keyword +; E302 = expected 2 blank lines, found ... +; E305 = expected 2 blank lines after class or function definition, found ... ; F401 = imported but unused ; F405 = may be undefined, or defined from star imports ; F403 = import * used; unable to detect undefined names ; W503 = line break before binary operator (set by 'black') ; ignore = F401,F405,F403,W503 +ignore = E221,E226,E227,E231,E241,E261,E272,E302,E305 max-line-length = 120 ; exclude = tests/* max-complexity = 12 From c78f44a6455bb0a2ba58819b5645aebd81621d01 Mon Sep 17 00:00:00 2001 From: Tomas Kral Date: Wed, 24 Sep 2025 13:01:07 +0000 Subject: [PATCH 2/4] Fix/suppress ruff violations --- eccodes/highlevel/_bufr/coder.py | 3 ++- eccodes/highlevel/_bufr/data.py | 6 +++--- eccodes/highlevel/_bufr/header.py | 3 ++- eccodes/highlevel/_bufr/helpers.py | 3 ++- eccodes/highlevel/_bufr/message.py | 3 ++- eccodes/highlevel/_bufr/tree.py | 5 +++-- eccodes/highlevel/_bufr/view.py | 3 ++- 7 files changed, 16 insertions(+), 10 deletions(-) diff --git a/eccodes/highlevel/_bufr/coder.py b/eccodes/highlevel/_bufr/coder.py index 1c92017..b08196d 100644 --- a/eccodes/highlevel/_bufr/coder.py +++ b/eccodes/highlevel/_bufr/coder.py @@ -11,6 +11,7 @@ from functools import cached_property # flake8: noqa: F405 +# ruff: noqa: F403 from .common import * from .helpers import ensure_array, missing_of @@ -709,7 +710,7 @@ def keys_of( for key in keys: if key == "unexpandedDescriptors": next_key = next(keys, None) - if next_key == None: + if next_key is None: if not header_only: raise RuntimeError(data_keys_unaccessible) else: diff --git a/eccodes/highlevel/_bufr/data.py b/eccodes/highlevel/_bufr/data.py index cbc0dfd..6101581 100644 --- a/eccodes/highlevel/_bufr/data.py +++ b/eccodes/highlevel/_bufr/data.py @@ -8,12 +8,12 @@ from functools import cached_property -# flake8: noqa: 405 +# flake8: noqa: F405 +# ruff: noqa: F403 from .coder import Coder from .common import * from .helpers import ensure_masked_array, flatten, missing_of -from .tables import Element from .tree import ( AssociationNode, LeafNode, @@ -484,7 +484,7 @@ def _get_slice(self, entry, key): rank_count = slice_.stop - slice_.start if key.rank > rank_count: message = ( - f"Rank %d is out of bounds; max. rank of '%s' in this view is %d" + "Rank %d is out of bounds; max. rank of '%s' in this view is %d" ) raise NotFoundError(message % (key.rank, entry.name, rank_count)) start = slice_.start + key.rank - 1 diff --git a/eccodes/highlevel/_bufr/header.py b/eccodes/highlevel/_bufr/header.py index 55f3722..090ff6e 100644 --- a/eccodes/highlevel/_bufr/header.py +++ b/eccodes/highlevel/_bufr/header.py @@ -6,7 +6,8 @@ # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. -# flake8: noqa: 405 +# flake8: noqa: F405 +# ruff: noqa: F403 from .coder import INPUT_TEMPLATE_KEYS, TEMPLATE_KEYS, Coder from .common import * diff --git a/eccodes/highlevel/_bufr/helpers.py b/eccodes/highlevel/_bufr/helpers.py index 1fc00b4..c944cf2 100644 --- a/eccodes/highlevel/_bufr/helpers.py +++ b/eccodes/highlevel/_bufr/helpers.py @@ -6,7 +6,8 @@ # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. -# flake8: noqa: 405 +# flake8: noqa: F405 +# ruff: noqa: F403 from .common import * diff --git a/eccodes/highlevel/_bufr/message.py b/eccodes/highlevel/_bufr/message.py index 9f10180..12f68b9 100644 --- a/eccodes/highlevel/_bufr/message.py +++ b/eccodes/highlevel/_bufr/message.py @@ -8,7 +8,8 @@ import datetime as dt -# flake8: noqa: 405 +# flake8: noqa: F405 +# ruff: noqa: F403 from .coder import Coder from .common import * diff --git a/eccodes/highlevel/_bufr/tree.py b/eccodes/highlevel/_bufr/tree.py index f1251cb..9d6c291 100644 --- a/eccodes/highlevel/_bufr/tree.py +++ b/eccodes/highlevel/_bufr/tree.py @@ -10,7 +10,8 @@ from copy import copy from itertools import repeat -# flake8: noqa: 405 +# flake8: noqa: F405 +# ruff: noqa: F403 from .common import * from .helpers import RaggedArray, SingletonDict @@ -384,7 +385,7 @@ def recurse(node): for key in node.keys: try: entry = entries[key.name] - except: + except KeyError: entry = DataEntry(key.name, flags=key.flags) if entry.name in current_behaviour.assumed_scalar_elements: entry.flags |= SCALAR diff --git a/eccodes/highlevel/_bufr/view.py b/eccodes/highlevel/_bufr/view.py index 7b7513d..018891c 100644 --- a/eccodes/highlevel/_bufr/view.py +++ b/eccodes/highlevel/_bufr/view.py @@ -6,7 +6,8 @@ # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. -# flake8: noqa: 405 +# flake8: noqa: F405 +# ruff: noqa: F403 from .common import * from .helpers import get_datetime, set_datetime From 6f8945daae0917e26ad51cc6f30678466bcc5035 Mon Sep 17 00:00:00 2001 From: Tomas Kral Date: Wed, 24 Sep 2025 13:10:27 +0000 Subject: [PATCH 3/4] Actually the flake8 ignore list is not needed; remove it --- tox.ini | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tox.ini b/tox.ini index dfd892f..e8a1b75 100644 --- a/tox.ini +++ b/tox.ini @@ -23,21 +23,11 @@ commands = python setup.py test [flake8] alias pip='pip --disable-pip-version-check' -; E221 = multiple spaces before operator -; E226 = missing whitespace around arithmetic operator -; E227 = missing whitespace around bitwise or shift operator -; E231 = missing whitespace after , -; E241 = multiple spaces after ',' -; E261 = at least two spaces before inline comment -; E272 = multiple spaces before keyword -; E302 = expected 2 blank lines, found ... -; E305 = expected 2 blank lines after class or function definition, found ... ; F401 = imported but unused ; F405 = may be undefined, or defined from star imports ; F403 = import * used; unable to detect undefined names ; W503 = line break before binary operator (set by 'black') ; ignore = F401,F405,F403,W503 -ignore = E221,E226,E227,E231,E241,E261,E272,E302,E305 max-line-length = 120 ; exclude = tests/* max-complexity = 12 From 418b8d2df777c2c022a9e6abdc625f32fef5429a Mon Sep 17 00:00:00 2001 From: Tomas Kral Date: Wed, 24 Sep 2025 14:20:10 +0000 Subject: [PATCH 4/4] Run the black tool to fix CI pipeline --- eccodes/highlevel/_bufr/__init__.py | 8 +++++--- eccodes/highlevel/_bufr/tables.py | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/eccodes/highlevel/_bufr/__init__.py b/eccodes/highlevel/_bufr/__init__.py index 7580562..385d512 100644 --- a/eccodes/highlevel/_bufr/__init__.py +++ b/eccodes/highlevel/_bufr/__init__.py @@ -7,7 +7,9 @@ from .message import BUFRMessage __all__ = [ - 'change_behaviour', 'get_behaviour', 'set_behaviour', - 'missing_of', - 'BUFRMessage', + "change_behaviour", + "get_behaviour", + "set_behaviour", + "missing_of", + "BUFRMessage", ] diff --git a/eccodes/highlevel/_bufr/tables.py b/eccodes/highlevel/_bufr/tables.py index 31a2e2e..a2ab847 100644 --- a/eccodes/highlevel/_bufr/tables.py +++ b/eccodes/highlevel/_bufr/tables.py @@ -210,7 +210,9 @@ def expand_descriptors( yield Descriptor(code, name) -libc = ctypes.CDLL(None, winmode=0) # automatically finds and loads the C standard library +libc = ctypes.CDLL( + None, winmode=0 +) # automatically finds and loads the C standard library fseek = libc.fseek fseek.argtypes = [ctypes.c_void_p, ctypes.c_long, ctypes.c_int]