foamlib 0.4.0__py3-none-any.whl → 0.4.2__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 CHANGED
@@ -1,6 +1,6 @@
1
1
  """A Python interface for interacting with OpenFOAM."""
2
2
 
3
- __version__ = "0.4.0"
3
+ __version__ = "0.4.2"
4
4
 
5
5
  from ._cases import (
6
6
  AsyncFoamCase,
foamlib/_files/_base.py CHANGED
@@ -51,6 +51,7 @@ class FoamFileBase:
51
51
  """
52
52
 
53
53
  _Dict = Dict[str, Union["Data", "_Dict"]]
54
+ _File = Dict[Optional[str], Union["Data", "_Dict"]]
54
55
 
55
56
  _SetData = Union[
56
57
  str,
foamlib/_files/_files.py CHANGED
@@ -97,9 +97,9 @@ class FoamFile(
97
97
  assert isinstance(ret, dict)
98
98
  v = ret[k]
99
99
  assert isinstance(v, dict)
100
- ret = v
100
+ ret = cast(FoamFileBase._File, v)
101
101
 
102
- return ret
102
+ return cast(FoamFileBase._Dict, ret)
103
103
 
104
104
  def create(self, *, exist_ok: bool = False, parents: bool = False) -> Self:
105
105
  """
@@ -356,7 +356,7 @@ class FoamFile(
356
356
  def __fspath__(self) -> str:
357
357
  return str(self.path)
358
358
 
359
- def as_dict(self) -> FoamFileBase._Dict:
359
+ def as_dict(self) -> FoamFileBase._File:
360
360
  """Return a nested dict representation of the file."""
361
361
  _, parsed = self._read()
362
362
  d = parsed.as_dict()
@@ -1,6 +1,6 @@
1
1
  import array
2
2
  import sys
3
- from typing import Tuple, Union
3
+ from typing import Tuple, Union, cast
4
4
 
5
5
  if sys.version_info >= (3, 9):
6
6
  from collections.abc import Iterator, Mapping, MutableMapping, Sequence
@@ -14,6 +14,7 @@ else:
14
14
 
15
15
  from pyparsing import (
16
16
  CharsNotIn,
17
+ Combine,
17
18
  Dict,
18
19
  Forward,
19
20
  Group,
@@ -134,7 +135,10 @@ _DIMENSIONS = (
134
135
  Literal("[").suppress() + common.number * 7 + Literal("]").suppress()
135
136
  ).set_parse_action(lambda tks: FoamFileBase.DimensionSet(*tks))
136
137
  _TENSOR = _list_of(common.number) | common.number
137
- _IDENTIFIER = Word(identchars + "$", printables, exclude_chars="{;}")
138
+ _IDENTIFIER = Combine(
139
+ Word(identchars + "$", printables, exclude_chars="{(;)}")
140
+ + Opt(Literal("(") + Word(printables, exclude_chars="{(;)}") + Literal(")"))
141
+ )
138
142
  _DIMENSIONED = (Opt(_IDENTIFIER) + _DIMENSIONS + _TENSOR).set_parse_action(
139
143
  lambda tks: FoamFileBase.Dimensioned(*reversed(tks.as_list()))
140
144
  )
@@ -262,17 +266,20 @@ class Parsed(Mapping[Tuple[str, ...], Union[FoamFileBase.Data, EllipsisType]]):
262
266
 
263
267
  return start, end
264
268
 
265
- def as_dict(self) -> FoamFileBase._Dict:
266
- ret: FoamFileBase._Dict = {}
269
+ def as_dict(self) -> FoamFileBase._File:
270
+ ret: FoamFileBase._File = {}
267
271
  for keywords, (_, data, _) in self._parsed.items():
268
272
  r = ret
269
273
  for k in keywords[:-1]:
270
- assert isinstance(r, dict)
271
274
  v = r[k]
272
275
  assert isinstance(v, dict)
273
- r = v
276
+ r = cast(FoamFileBase._File, v)
274
277
 
275
278
  assert isinstance(r, dict)
276
- r[keywords[-1]] = {} if data is ... else data
279
+ if keywords:
280
+ r[keywords[-1]] = {} if data is ... else data
281
+ else:
282
+ assert data is not ...
283
+ r[None] = data
277
284
 
278
285
  return ret
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: foamlib
3
- Version: 0.4.0
3
+ Version: 0.4.2
4
4
  Summary: A Python interface for interacting with OpenFOAM
5
5
  Author-email: "Gabriel S. Gerlero" <ggerlero@cimec.unl.edu.ar>
6
6
  Project-URL: Homepage, https://github.com/gerlero/foamlib
@@ -1,4 +1,4 @@
1
- foamlib/__init__.py,sha256=ZL6X6uzZgGj8D5Thi9ZuZyr1Mpo6f78yT_Rf4sBU12I,446
1
+ foamlib/__init__.py,sha256=jybejTK1oM5i5b-9ymupfu5dfoxg_2daivPQ94THPII,446
2
2
  foamlib/_util.py,sha256=UMzXmTFgvbp46w6k3oEZJoYC98pFgEK6LN5uLOwrlCg,397
3
3
  foamlib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  foamlib/_cases/__init__.py,sha256=xnQpR64EvFtCh07qnSz7kjQ1IhJXjRDwaZWwQGZhGv4,280
@@ -7,13 +7,13 @@ foamlib/_cases/_base.py,sha256=JrYJplmXV84qwgerdVSCHz2rCI-KWB4IvTBPMkYpecw,12657
7
7
  foamlib/_cases/_sync.py,sha256=CloQgd-93jxfSXIt7J5NxcAu3N_iF3eXMKO-NfNOgi4,4522
8
8
  foamlib/_cases/_util.py,sha256=v6sHxHCEgagsVuup0S1xJW-x9py5xj3bUye8PiFfb3o,925
9
9
  foamlib/_files/__init__.py,sha256=-UqB9YTH6mrJfXCX00kPTAAY20XG64u1MGPw_1ewLVs,148
10
- foamlib/_files/_base.py,sha256=sy1RP08pdv079KD_UBy7xUYEnXyNK35AiKVcCalYmPU,1873
11
- foamlib/_files/_files.py,sha256=2bvl2YZ0bqHpbQV35vzYO7wWNOo_2WDF9LbyLagIvBE,16193
10
+ foamlib/_files/_base.py,sha256=zaFDjLE6jB7WtGWk8hfKusjLtlGu6CZV16AHJpRUibs,1929
11
+ foamlib/_files/_files.py,sha256=-3mDRIsaQaxHF74q0Zfzlrhfieb7w_EPOFScSx8wRPE,16245
12
12
  foamlib/_files/_io.py,sha256=f_tYI7AqaFsQ8mtK__fEoIUqpYb3YmrI8X5D8updmNM,2084
13
- foamlib/_files/_parsing.py,sha256=bOJkqNUMUiXZJQXXEnIAb0bcdj_AgDmDhrr19oyY_Sw,8078
13
+ foamlib/_files/_parsing.py,sha256=MDz5AzoI6wJw_uIbVPlD1Naxm8AzA6iOrKkhCbaJLxg,8295
14
14
  foamlib/_files/_serialization.py,sha256=3yb9fgjCpDoRfZoLsbZaIFrkZ3vGBzleFRw6IbaZuuY,3408
15
- foamlib-0.4.0.dist-info/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
16
- foamlib-0.4.0.dist-info/METADATA,sha256=3DObrf-prhkIgLQ2crezzAVkKW4ZIuNrXEsbqT3ilUc,5457
17
- foamlib-0.4.0.dist-info/WHEEL,sha256=uCRv0ZEik_232NlR4YDw4Pv3Ajt5bKvMH13NUU7hFuI,91
18
- foamlib-0.4.0.dist-info/top_level.txt,sha256=ZdVYtetXGwPwyfL-WhlhbTFQGAwKX5P_gXxtH9JYFPI,8
19
- foamlib-0.4.0.dist-info/RECORD,,
15
+ foamlib-0.4.2.dist-info/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
16
+ foamlib-0.4.2.dist-info/METADATA,sha256=pF9f6WuWV5YAkN7X4yGujILaBXzATeysOuftxBO41cc,5457
17
+ foamlib-0.4.2.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
18
+ foamlib-0.4.2.dist-info/top_level.txt,sha256=ZdVYtetXGwPwyfL-WhlhbTFQGAwKX5P_gXxtH9JYFPI,8
19
+ foamlib-0.4.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (74.1.1)
2
+ Generator: setuptools (74.1.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5