diff --git a/eccodes/highlevel/_bufr/__init__.py b/eccodes/highlevel/_bufr/__init__.py index 32f4bda..385d512 100644 --- a/eccodes/highlevel/_bufr/__init__.py +++ b/eccodes/highlevel/_bufr/__init__.py @@ -5,3 +5,11 @@ 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..b08196d 100644 --- a/eccodes/highlevel/_bufr/coder.py +++ b/eccodes/highlevel/_bufr/coder.py @@ -8,10 +8,14 @@ import io import warnings +from functools import cached_property + +# flake8: noqa: F405 +# ruff: noqa: F403 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( [ @@ -706,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/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..6101581 100644 --- a/eccodes/highlevel/_bufr/data.py +++ b/eccodes/highlevel/_bufr/data.py @@ -6,10 +6,14 @@ # 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: 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, @@ -480,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 7cc8de9..090ff6e 100644 --- a/eccodes/highlevel/_bufr/header.py +++ b/eccodes/highlevel/_bufr/header.py @@ -6,6 +6,9 @@ # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. +# flake8: noqa: F405 +# ruff: noqa: F403 + 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..c944cf2 100644 --- a/eccodes/highlevel/_bufr/helpers.py +++ b/eccodes/highlevel/_bufr/helpers.py @@ -6,6 +6,9 @@ # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. +# flake8: noqa: F405 +# ruff: noqa: F403 + from .common import * diff --git a/eccodes/highlevel/_bufr/message.py b/eccodes/highlevel/_bufr/message.py index b428803..12f68b9 100644 --- a/eccodes/highlevel/_bufr/message.py +++ b/eccodes/highlevel/_bufr/message.py @@ -8,6 +8,9 @@ import datetime as dt +# flake8: noqa: F405 +# ruff: noqa: F403 + 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..a2ab847 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,10 +210,9 @@ 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 +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] diff --git a/eccodes/highlevel/_bufr/tree.py b/eccodes/highlevel/_bufr/tree.py index 80edd6a..9d6c291 100644 --- a/eccodes/highlevel/_bufr/tree.py +++ b/eccodes/highlevel/_bufr/tree.py @@ -6,9 +6,13 @@ # 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: F405 +# ruff: noqa: F403 + from .common import * from .helpers import RaggedArray, SingletonDict from .tables import Code, Element @@ -381,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 0bb9aef..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. -import datetime as dt +# flake8: noqa: F405 +# ruff: noqa: F403 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..e8a1b75 100644 --- a/tox.ini +++ b/tox.ini @@ -22,6 +22,7 @@ deps = commands = python setup.py test [flake8] +alias pip='pip --disable-pip-version-check' ; F401 = imported but unused ; F405 = may be undefined, or defined from star imports ; F403 = import * used; unable to detect undefined names