Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions eccodes/highlevel/_bufr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
8 changes: 6 additions & 2 deletions eccodes/highlevel/_bufr/coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand Down Expand Up @@ -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:
Expand Down
27 changes: 10 additions & 17 deletions eccodes/highlevel/_bufr/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions eccodes/highlevel/_bufr/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions eccodes/highlevel/_bufr/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions eccodes/highlevel/_bufr/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *


Expand Down
3 changes: 3 additions & 0 deletions eccodes/highlevel/_bufr/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions eccodes/highlevel/_bufr/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
6 changes: 5 additions & 1 deletion eccodes/highlevel/_bufr/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion eccodes/highlevel/_bufr/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion eccodes/highlevel/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import eccodes

from ._bufr import BUFRMessage
from ._bufr import BUFRMessage # noqa

_TYPES_MAP = {
"float": float,
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading