foamlib 0.8.3__tar.gz → 0.8.4__tar.gz

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.
Files changed (51) hide show
  1. {foamlib-0.8.3 → foamlib-0.8.4}/PKG-INFO +1 -1
  2. {foamlib-0.8.3 → foamlib-0.8.4}/foamlib/__init__.py +1 -1
  3. {foamlib-0.8.3 → foamlib-0.8.4}/foamlib/_files/_files.py +3 -3
  4. {foamlib-0.8.3 → foamlib-0.8.4}/foamlib/_files/_parsing.py +21 -5
  5. {foamlib-0.8.3 → foamlib-0.8.4}/foamlib/_files/_serialization.py +4 -1
  6. {foamlib-0.8.3 → foamlib-0.8.4}/tests/test_files/test_parsing.py +8 -0
  7. {foamlib-0.8.3 → foamlib-0.8.4}/.devcontainer.json +0 -0
  8. {foamlib-0.8.3 → foamlib-0.8.4}/.dockerignore +0 -0
  9. {foamlib-0.8.3 → foamlib-0.8.4}/.git-blame-ignore-revs +0 -0
  10. {foamlib-0.8.3 → foamlib-0.8.4}/.github/dependabot.yml +0 -0
  11. {foamlib-0.8.3 → foamlib-0.8.4}/.github/workflows/ci.yml +0 -0
  12. {foamlib-0.8.3 → foamlib-0.8.4}/.github/workflows/docker.yml +0 -0
  13. {foamlib-0.8.3 → foamlib-0.8.4}/.github/workflows/dockerhub-description.yml +0 -0
  14. {foamlib-0.8.3 → foamlib-0.8.4}/.github/workflows/pypi-publish.yml +0 -0
  15. {foamlib-0.8.3 → foamlib-0.8.4}/.gitignore +0 -0
  16. {foamlib-0.8.3 → foamlib-0.8.4}/.readthedocs.yaml +0 -0
  17. {foamlib-0.8.3 → foamlib-0.8.4}/Dockerfile +0 -0
  18. {foamlib-0.8.3 → foamlib-0.8.4}/LICENSE.txt +0 -0
  19. {foamlib-0.8.3 → foamlib-0.8.4}/README.md +0 -0
  20. {foamlib-0.8.3 → foamlib-0.8.4}/benchmark.png +0 -0
  21. {foamlib-0.8.3 → foamlib-0.8.4}/docs/Makefile +0 -0
  22. {foamlib-0.8.3 → foamlib-0.8.4}/docs/cases.rst +0 -0
  23. {foamlib-0.8.3 → foamlib-0.8.4}/docs/conf.py +0 -0
  24. {foamlib-0.8.3 → foamlib-0.8.4}/docs/files.rst +0 -0
  25. {foamlib-0.8.3 → foamlib-0.8.4}/docs/index.rst +0 -0
  26. {foamlib-0.8.3 → foamlib-0.8.4}/docs/make.bat +0 -0
  27. {foamlib-0.8.3 → foamlib-0.8.4}/docs/ruff.toml +0 -0
  28. {foamlib-0.8.3 → foamlib-0.8.4}/foamlib/_cases/__init__.py +0 -0
  29. {foamlib-0.8.3 → foamlib-0.8.4}/foamlib/_cases/_async.py +0 -0
  30. {foamlib-0.8.3 → foamlib-0.8.4}/foamlib/_cases/_base.py +0 -0
  31. {foamlib-0.8.3 → foamlib-0.8.4}/foamlib/_cases/_run.py +0 -0
  32. {foamlib-0.8.3 → foamlib-0.8.4}/foamlib/_cases/_slurm.py +0 -0
  33. {foamlib-0.8.3 → foamlib-0.8.4}/foamlib/_cases/_subprocess.py +0 -0
  34. {foamlib-0.8.3 → foamlib-0.8.4}/foamlib/_cases/_sync.py +0 -0
  35. {foamlib-0.8.3 → foamlib-0.8.4}/foamlib/_cases/_util.py +0 -0
  36. {foamlib-0.8.3 → foamlib-0.8.4}/foamlib/_files/__init__.py +0 -0
  37. {foamlib-0.8.3 → foamlib-0.8.4}/foamlib/_files/_io.py +0 -0
  38. {foamlib-0.8.3 → foamlib-0.8.4}/foamlib/_files/_types.py +0 -0
  39. {foamlib-0.8.3 → foamlib-0.8.4}/foamlib/py.typed +0 -0
  40. {foamlib-0.8.3 → foamlib-0.8.4}/logo.png +0 -0
  41. {foamlib-0.8.3 → foamlib-0.8.4}/pyproject.toml +0 -0
  42. {foamlib-0.8.3 → foamlib-0.8.4}/tests/__init__.py +0 -0
  43. {foamlib-0.8.3 → foamlib-0.8.4}/tests/ruff.toml +0 -0
  44. {foamlib-0.8.3 → foamlib-0.8.4}/tests/test_cases/__init__.py +0 -0
  45. {foamlib-0.8.3 → foamlib-0.8.4}/tests/test_cases/test_cavity.py +0 -0
  46. {foamlib-0.8.3 → foamlib-0.8.4}/tests/test_cases/test_cavity_async.py +0 -0
  47. {foamlib-0.8.3 → foamlib-0.8.4}/tests/test_cases/test_flange.py +0 -0
  48. {foamlib-0.8.3 → foamlib-0.8.4}/tests/test_cases/test_flange_async.py +0 -0
  49. {foamlib-0.8.3 → foamlib-0.8.4}/tests/test_files/__init__.py +0 -0
  50. {foamlib-0.8.3 → foamlib-0.8.4}/tests/test_files/test_dumps.py +0 -0
  51. {foamlib-0.8.3 → foamlib-0.8.4}/tests/test_files/test_files.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: foamlib
3
- Version: 0.8.3
3
+ Version: 0.8.4
4
4
  Summary: A Python interface for interacting with OpenFOAM
5
5
  Project-URL: Homepage, https://github.com/gerlero/foamlib
6
6
  Project-URL: Repository, https://github.com/gerlero/foamlib
@@ -1,6 +1,6 @@
1
1
  """A Python interface for interacting with OpenFOAM."""
2
2
 
3
- __version__ = "0.8.3"
3
+ __version__ = "0.8.4"
4
4
 
5
5
  from ._cases import (
6
6
  AsyncFoamCase,
@@ -308,15 +308,15 @@ class FoamFile(
308
308
  self[(*keywords, k)] = v
309
309
 
310
310
  elif keywords:
311
+ val = dumps(data, kind=kind)
311
312
  parsed.put(
312
313
  keywords,
313
314
  normalize(data, kind=kind),
314
315
  before
315
316
  + indentation
316
317
  + dumps(keywords[-1])
317
- + b" "
318
- + dumps(data, kind=kind)
319
- + b";"
318
+ + ((b" " + val) if val else b"")
319
+ + (b";" if not keywords[-1].startswith("#") else b"")
320
320
  + after,
321
321
  )
322
322
 
@@ -153,12 +153,19 @@ def _tensor_list(
153
153
 
154
154
 
155
155
  def _dict_of(
156
- keyword: ParserElement, data: ParserElement, *, located: bool = False
156
+ keyword: ParserElement,
157
+ data: ParserElement,
158
+ *,
159
+ directive: ParserElement | None = None,
160
+ located: bool = False,
157
161
  ) -> ParserElement:
158
162
  dict_ = Forward()
159
163
 
160
164
  keyword_entry = keyword + (dict_ | (data + Literal(";").suppress()))
161
165
 
166
+ if directive is not None:
167
+ keyword_entry |= directive + data + LineEnd().suppress() # type: ignore [no-untyped-call]
168
+
162
169
  if located:
163
170
  keyword_entry = Located(keyword_entry)
164
171
 
@@ -175,12 +182,17 @@ def _keyword_entry_of(
175
182
  keyword: ParserElement,
176
183
  data: ParserElement,
177
184
  *,
185
+ directive: ParserElement | None = None,
178
186
  located: bool = False,
179
187
  ) -> ParserElement:
180
188
  keyword_entry = keyword + (
181
- _dict_of(keyword, data, located=located) | (data + Literal(";").suppress())
189
+ _dict_of(keyword, data, directive=directive, located=located)
190
+ | (data + Literal(";").suppress())
182
191
  )
183
192
 
193
+ if directive is not None:
194
+ keyword_entry |= directive + data + LineEnd().suppress() # type: ignore [no-untyped-call]
195
+
184
196
  if located:
185
197
  keyword_entry = Located(keyword_entry)
186
198
  else:
@@ -240,7 +252,8 @@ _FIELD = (Keyword("uniform", _IDENTBODYCHARS).suppress() + _TENSOR) | (
240
252
  | _tensor_list(TensorKind.TENSOR, ignore=_COMMENT)
241
253
  )
242
254
  )
243
- _TOKEN = dbl_quoted_string | _IDENTIFIER
255
+ _DIRECTIVE = Word("#", _IDENTBODYCHARS)
256
+ _TOKEN = dbl_quoted_string | _IDENTIFIER | _DIRECTIVE
244
257
  _DATA = Forward()
245
258
  _KEYWORD_ENTRY = _keyword_entry_of(_TOKEN | _list_of(_IDENTIFIER), _DATA)
246
259
  _DICT = _dict_of(_TOKEN, _DATA)
@@ -259,18 +272,21 @@ _DATA <<= (
259
272
 
260
273
 
261
274
  def parse_data(s: str) -> Data:
275
+ if not s.strip():
276
+ return ""
262
277
  return cast(Data, _DATA.parse_string(s, parse_all=True)[0])
263
278
 
264
279
 
265
280
  _LOCATED_DICTIONARY = Group(
266
- _keyword_entry_of(_TOKEN, Opt(_DATA, default=""), located=True)
281
+ _keyword_entry_of(
282
+ _TOKEN, Opt(_DATA, default=""), directive=_DIRECTIVE, located=True
283
+ )
267
284
  )[...]
268
285
  _LOCATED_DATA = Group(Located(_DATA.copy().add_parse_action(lambda tks: ["", tks[0]])))
269
286
 
270
287
  _FILE = (
271
288
  Dict(_LOCATED_DICTIONARY + Opt(_LOCATED_DATA) + _LOCATED_DICTIONARY)
272
289
  .ignore(_COMMENT)
273
- .ignore(Literal("#include") + ... + LineEnd()) # type: ignore [no-untyped-call]
274
290
  .parse_with_tabs()
275
291
  )
276
292
 
@@ -111,7 +111,10 @@ def dumps(
111
111
 
112
112
  if isinstance(data, tuple) and kind == Kind.SINGLE_ENTRY and len(data) == 2:
113
113
  k, v = data
114
- ret = dumps(k) + b" " + dumps(v)
114
+ ret = dumps(k)
115
+ val = dumps(v)
116
+ if val:
117
+ ret += b" " + val
115
118
  if not isinstance(v, Mapping):
116
119
  ret += b";"
117
120
  return ret
@@ -98,3 +98,11 @@ def test_parse_value() -> None:
98
98
  ]
99
99
  assert Parsed(b"[]")[()] == FoamFile.DimensionSet()
100
100
  assert Parsed(b"object f.1;")[("object",)] == "f.1"
101
+
102
+
103
+ def test_parse_directive() -> None:
104
+ assert Parsed(b'#include "filename"')[("#include",)] == '"filename"'
105
+ assert (
106
+ Parsed(b"functions\n{\n#includeFunc funcName\n}")[("functions", "#includeFunc")]
107
+ == "funcName"
108
+ )
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes