foamlib 0.6.11__py3-none-any.whl → 0.6.12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- foamlib/__init__.py +1 -1
- foamlib/_cases/_async.py +23 -23
- foamlib/_cases/_base.py +25 -26
- foamlib/_cases/_run.py +52 -58
- foamlib/_cases/_slurm.py +7 -5
- foamlib/_cases/_subprocess.py +15 -13
- foamlib/_cases/_sync.py +25 -27
- foamlib/_cases/_util.py +13 -10
- foamlib/_files/_base.py +5 -3
- foamlib/_files/_files.py +116 -101
- foamlib/_files/_io.py +9 -10
- foamlib/_files/_parsing.py +21 -25
- foamlib/_files/_serialization.py +19 -11
- foamlib/_files/_util.py +8 -3
- {foamlib-0.6.11.dist-info → foamlib-0.6.12.dist-info}/METADATA +1 -1
- foamlib-0.6.12.dist-info/RECORD +22 -0
- foamlib-0.6.11.dist-info/RECORD +0 -22
- {foamlib-0.6.11.dist-info → foamlib-0.6.12.dist-info}/LICENSE.txt +0 -0
- {foamlib-0.6.11.dist-info → foamlib-0.6.12.dist-info}/WHEEL +0 -0
- {foamlib-0.6.11.dist-info → foamlib-0.6.12.dist-info}/top_level.txt +0 -0
foamlib/_files/_parsing.py
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
1
3
|
import array
|
2
4
|
import sys
|
3
5
|
from typing import Tuple, Union, cast
|
@@ -80,19 +82,19 @@ def _keyword_entry_of(
|
|
80
82
|
|
81
83
|
def _unpack_binary_field(
|
82
84
|
tks: ParseResults,
|
83
|
-
) -> Sequence[
|
85
|
+
) -> Sequence[Sequence[float] | Sequence[Sequence[float]]]:
|
84
86
|
elsize = len(tks[0]) // 8
|
85
87
|
|
86
88
|
arr = array.array("d", "".join(tks).encode("latin-1"))
|
87
89
|
|
88
|
-
|
90
|
+
values: Sequence[float] | Sequence[Sequence[float]]
|
89
91
|
|
90
92
|
if elsize != 1:
|
91
|
-
|
93
|
+
values = [arr[i : i + elsize].tolist() for i in range(0, len(arr), elsize)]
|
92
94
|
else:
|
93
|
-
|
95
|
+
values = arr.tolist()
|
94
96
|
|
95
|
-
return [
|
97
|
+
return [values]
|
96
98
|
|
97
99
|
|
98
100
|
_IDENTCHARS = identchars + "$"
|
@@ -210,8 +212,8 @@ _FILE = (
|
|
210
212
|
class Parsed(Mapping[Tuple[str, ...], Union[FoamFileBase._DataEntry, EllipsisType]]):
|
211
213
|
def __init__(self, contents: bytes) -> None:
|
212
214
|
self._parsed: MutableMapping[
|
213
|
-
|
214
|
-
|
215
|
+
tuple[str, ...],
|
216
|
+
tuple[int, FoamFileBase._DataEntry | EllipsisType, int],
|
215
217
|
] = {}
|
216
218
|
for parse_result in _FILE.parse_string(
|
217
219
|
contents.decode("latin-1"), parse_all=True
|
@@ -223,13 +225,13 @@ class Parsed(Mapping[Tuple[str, ...], Union[FoamFileBase._DataEntry, EllipsisTyp
|
|
223
225
|
|
224
226
|
@staticmethod
|
225
227
|
def _flatten_result(
|
226
|
-
parse_result: ParseResults, *, _keywords:
|
228
|
+
parse_result: ParseResults, *, _keywords: tuple[str, ...] = ()
|
227
229
|
) -> Mapping[
|
228
|
-
|
230
|
+
tuple[str, ...], tuple[int, FoamFileBase._DataEntry | EllipsisType, int]
|
229
231
|
]:
|
230
232
|
ret: MutableMapping[
|
231
|
-
|
232
|
-
|
233
|
+
tuple[str, ...],
|
234
|
+
tuple[int, FoamFileBase._DataEntry | EllipsisType, int],
|
233
235
|
] = {}
|
234
236
|
start = parse_result.locn_start
|
235
237
|
assert isinstance(start, int)
|
@@ -256,18 +258,15 @@ class Parsed(Mapping[Tuple[str, ...], Union[FoamFileBase._DataEntry, EllipsisTyp
|
|
256
258
|
return ret
|
257
259
|
|
258
260
|
def __getitem__(
|
259
|
-
self, keywords:
|
260
|
-
) ->
|
261
|
-
if isinstance(keywords, str):
|
262
|
-
keywords = (keywords,)
|
263
|
-
|
261
|
+
self, keywords: tuple[str, ...]
|
262
|
+
) -> FoamFileBase._DataEntry | EllipsisType:
|
264
263
|
_, data, _ = self._parsed[keywords]
|
265
264
|
return data
|
266
265
|
|
267
266
|
def put(
|
268
267
|
self,
|
269
|
-
keywords:
|
270
|
-
data:
|
268
|
+
keywords: tuple[str, ...],
|
269
|
+
data: FoamFileBase._DataEntry | EllipsisType,
|
271
270
|
content: bytes,
|
272
271
|
) -> None:
|
273
272
|
start, end = self.entry_location(keywords, missing_ok=True)
|
@@ -288,10 +287,7 @@ class Parsed(Mapping[Tuple[str, ...], Union[FoamFileBase._DataEntry, EllipsisTyp
|
|
288
287
|
if keywords != k and keywords == k[: len(keywords)]:
|
289
288
|
del self._parsed[k]
|
290
289
|
|
291
|
-
def __delitem__(self, keywords:
|
292
|
-
if isinstance(keywords, str):
|
293
|
-
keywords = (keywords,)
|
294
|
-
|
290
|
+
def __delitem__(self, keywords: tuple[str, ...]) -> None:
|
295
291
|
start, end = self.entry_location(keywords)
|
296
292
|
del self._parsed[keywords]
|
297
293
|
|
@@ -312,15 +308,15 @@ class Parsed(Mapping[Tuple[str, ...], Union[FoamFileBase._DataEntry, EllipsisTyp
|
|
312
308
|
def __contains__(self, keywords: object) -> bool:
|
313
309
|
return keywords in self._parsed
|
314
310
|
|
315
|
-
def __iter__(self) -> Iterator[
|
311
|
+
def __iter__(self) -> Iterator[tuple[str, ...]]:
|
316
312
|
return iter(self._parsed)
|
317
313
|
|
318
314
|
def __len__(self) -> int:
|
319
315
|
return len(self._parsed)
|
320
316
|
|
321
317
|
def entry_location(
|
322
|
-
self, keywords:
|
323
|
-
) ->
|
318
|
+
self, keywords: tuple[str, ...], *, missing_ok: bool = False
|
319
|
+
) -> tuple[int, int]:
|
324
320
|
try:
|
325
321
|
start, _, end = self._parsed[keywords]
|
326
322
|
except KeyError:
|
foamlib/_files/_serialization.py
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
1
3
|
import array
|
2
4
|
import itertools
|
3
5
|
import sys
|
4
6
|
from enum import Enum, auto
|
7
|
+
from typing import cast
|
5
8
|
|
6
9
|
if sys.version_info >= (3, 9):
|
7
|
-
from collections.abc import Mapping
|
10
|
+
from collections.abc import Mapping, Sequence
|
8
11
|
else:
|
9
|
-
from typing import Mapping
|
12
|
+
from typing import Mapping, Sequence
|
10
13
|
|
11
14
|
from ._base import FoamFileBase
|
12
15
|
from ._util import is_sequence
|
@@ -53,7 +56,7 @@ def dumps(
|
|
53
56
|
):
|
54
57
|
return b"[" + b" ".join(dumps(v) for v in data) + b"]"
|
55
58
|
|
56
|
-
if
|
59
|
+
if kind in (Kind.FIELD, Kind.BINARY_FIELD) and (
|
57
60
|
isinstance(data, (int, float))
|
58
61
|
or is_sequence(data)
|
59
62
|
and data
|
@@ -62,22 +65,27 @@ def dumps(
|
|
62
65
|
):
|
63
66
|
return b"uniform " + dumps(data, kind=Kind.SINGLE_ENTRY)
|
64
67
|
|
65
|
-
if
|
66
|
-
if isinstance(data[0], (int, float)):
|
68
|
+
if kind in (Kind.FIELD, Kind.BINARY_FIELD) and is_sequence(data):
|
69
|
+
if data and isinstance(data[0], (int, float)):
|
67
70
|
tensor_kind = b"scalar"
|
68
|
-
elif
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
elif is_sequence(data[0]) and data[0] and isinstance(data[0][0], (int, float)):
|
72
|
+
if len(data[0]) == 3:
|
73
|
+
tensor_kind = b"vector"
|
74
|
+
elif len(data[0]) == 6:
|
75
|
+
tensor_kind = b"symmTensor"
|
76
|
+
elif len(data[0]) == 9:
|
77
|
+
tensor_kind = b"tensor"
|
78
|
+
else:
|
79
|
+
return dumps(data)
|
74
80
|
else:
|
75
81
|
return dumps(data)
|
76
82
|
|
77
83
|
if kind == Kind.BINARY_FIELD:
|
78
84
|
if tensor_kind == b"scalar":
|
85
|
+
data = cast(Sequence[float], data)
|
79
86
|
contents = b"(" + array.array("d", data).tobytes() + b")"
|
80
87
|
else:
|
88
|
+
data = cast(Sequence[Sequence[float]], data)
|
81
89
|
contents = (
|
82
90
|
b"("
|
83
91
|
+ array.array("d", itertools.chain.from_iterable(data)).tobytes()
|
foamlib/_files/_util.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
1
3
|
import sys
|
2
|
-
from typing import
|
4
|
+
from typing import TYPE_CHECKING
|
3
5
|
|
4
6
|
if sys.version_info >= (3, 9):
|
5
7
|
from collections.abc import Sequence
|
@@ -11,8 +13,11 @@ if sys.version_info >= (3, 10):
|
|
11
13
|
else:
|
12
14
|
from typing_extensions import TypeGuard
|
13
15
|
|
16
|
+
if TYPE_CHECKING:
|
17
|
+
from ._base import FoamFileBase
|
18
|
+
|
14
19
|
|
15
20
|
def is_sequence(
|
16
|
-
value:
|
17
|
-
) -> TypeGuard[Sequence[
|
21
|
+
value: FoamFileBase.Data,
|
22
|
+
) -> TypeGuard[Sequence[FoamFileBase.Data]]:
|
18
23
|
return isinstance(value, Sequence) and not isinstance(value, str)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
foamlib/__init__.py,sha256=fzKDNF8_CX5rU1KVBoVQZHdjJ_nEiRbLv_sfj6-CHAY,487
|
2
|
+
foamlib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
+
foamlib/_cases/__init__.py,sha256=wTUHcUgU1CBgpu0cUMtksQ5VKG6B8CFu9xc3dWwsQuo,358
|
4
|
+
foamlib/_cases/_async.py,sha256=i6g4EBHqvI-1PkdrxsRto2ynW7sxsOga2bSYk1XVG1U,7795
|
5
|
+
foamlib/_cases/_base.py,sha256=FKfZxP7HspWfSswQ6yZ5bGJRdZUlupQxj2tDqngXPmc,6785
|
6
|
+
foamlib/_cases/_run.py,sha256=lveqKZium_qK_eTxYE8jOjwx0eiIoolCBbi56-zLw1o,14420
|
7
|
+
foamlib/_cases/_slurm.py,sha256=kj4wqgr3foMyAoUkoHOZODRBmVqH1B9KqAIEEjM8ZBg,2328
|
8
|
+
foamlib/_cases/_subprocess.py,sha256=6BlBRxknj2-BFcGkx7oVcuL63_utSaY1Axmsc1qV9j8,3887
|
9
|
+
foamlib/_cases/_sync.py,sha256=2BJXB7Nzldb4OgPukqupgYqdceUGkI2mYhhtGPWEBrc,5901
|
10
|
+
foamlib/_cases/_util.py,sha256=lhVca3ERY0zwYjDam6W2QMROt0yX5vAF-9_DS5RuMbM,1547
|
11
|
+
foamlib/_files/__init__.py,sha256=-UqB9YTH6mrJfXCX00kPTAAY20XG64u1MGPw_1ewLVs,148
|
12
|
+
foamlib/_files/_base.py,sha256=ZY_6Zxr3LZHVzJEex6SUTi9Pgo7Oi7i3Jo-wre9G3yE,1968
|
13
|
+
foamlib/_files/_files.py,sha256=WF_FWiDhnkA4dtZ6zR1A0iGrv76eI3SetlQu6Zl6HY8,14949
|
14
|
+
foamlib/_files/_io.py,sha256=IQLqoqnA1TpHf21NbUho2wsYWevyqC6MKo-wfpaObUU,2226
|
15
|
+
foamlib/_files/_parsing.py,sha256=qLZx_VZMNEoyfmrkC_r85QBuABa26-6Y0fHnxCq74Q8,10880
|
16
|
+
foamlib/_files/_serialization.py,sha256=HN9XCDbZ0I-b_UdpEYgDVNX6U4tPd6u-uYBKOoX3uqg,3681
|
17
|
+
foamlib/_files/_util.py,sha256=VXUTD0B3NbnlaE_KCqWzrFcWvBz_2JfnIWpNp3snX3Y,526
|
18
|
+
foamlib-0.6.12.dist-info/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
|
19
|
+
foamlib-0.6.12.dist-info/METADATA,sha256=fN1pEtQzMHd-yuzMkugYgTtpVwZwV-U0CPxU6rRTnzA,7742
|
20
|
+
foamlib-0.6.12.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
21
|
+
foamlib-0.6.12.dist-info/top_level.txt,sha256=ZdVYtetXGwPwyfL-WhlhbTFQGAwKX5P_gXxtH9JYFPI,8
|
22
|
+
foamlib-0.6.12.dist-info/RECORD,,
|
foamlib-0.6.11.dist-info/RECORD
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
foamlib/__init__.py,sha256=tS4b8eyl8WWPCCt7EmgXM2lcx8V1Zead47kwB3zJlNY,487
|
2
|
-
foamlib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
|
-
foamlib/_cases/__init__.py,sha256=wTUHcUgU1CBgpu0cUMtksQ5VKG6B8CFu9xc3dWwsQuo,358
|
4
|
-
foamlib/_cases/_async.py,sha256=oQ2XnD9sansJLJDuUl3_vHaUM4L9hq2G97IcRjQAOPY,7920
|
5
|
-
foamlib/_cases/_base.py,sha256=HV7ifv60pAhgZdC3s5IxvdrDQ2vvlhzPwyB-80QQLe8,6733
|
6
|
-
foamlib/_cases/_run.py,sha256=XFDBr5G1hJo0402RcZClLL_rv0d5jVgq2be25FgZcyQ,14725
|
7
|
-
foamlib/_cases/_slurm.py,sha256=pUXcFSrwOK5URsoooiUOJg61X0WLLNHyv7bhUxIb7Bs,2346
|
8
|
-
foamlib/_cases/_subprocess.py,sha256=tzsBGe44EnQw3GWqRW1ktEZ4sNQ1sSHdJ_89zIfF5L0,3952
|
9
|
-
foamlib/_cases/_sync.py,sha256=ENvn8zseRh6YOjAgqXHzmKhKFYXdzGIW5NoMHS_NKPY,6049
|
10
|
-
foamlib/_cases/_util.py,sha256=GNndpqw3Jg_S-Hxzl5vwRgD0czcTNb9NYHMhcfBoMBg,1493
|
11
|
-
foamlib/_files/__init__.py,sha256=-UqB9YTH6mrJfXCX00kPTAAY20XG64u1MGPw_1ewLVs,148
|
12
|
-
foamlib/_files/_base.py,sha256=A8084rU92w9Hh2BZAEIdE31qvm15fto1qOyQJhrP5DI,1945
|
13
|
-
foamlib/_files/_files.py,sha256=rvhb9mZFg1z6JSpb02E_8B2YD7Zmt5hh2v7rq19qC_c,14712
|
14
|
-
foamlib/_files/_io.py,sha256=07gaGhoJuXDB9i4AxvnIT_Np71RAU2ut2G5Lcyx8TaU,2244
|
15
|
-
foamlib/_files/_parsing.py,sha256=pqwWzlZwCTe7PxncYywO3OWd9Ppl9Oq8JYVpofxKJsY,11046
|
16
|
-
foamlib/_files/_serialization.py,sha256=Gy9v3iZGD-RF3pS7rauft7fpT33UIzRuOm0XH4rFHvA,3337
|
17
|
-
foamlib/_files/_util.py,sha256=UMzXmTFgvbp46w6k3oEZJoYC98pFgEK6LN5uLOwrlCg,397
|
18
|
-
foamlib-0.6.11.dist-info/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
|
19
|
-
foamlib-0.6.11.dist-info/METADATA,sha256=VGwnlinUiBszBq9RzNnRWvWx0hkO9ziOY4jaKNmoJwc,7742
|
20
|
-
foamlib-0.6.11.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
21
|
-
foamlib-0.6.11.dist-info/top_level.txt,sha256=ZdVYtetXGwPwyfL-WhlhbTFQGAwKX5P_gXxtH9JYFPI,8
|
22
|
-
foamlib-0.6.11.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|