foamlib 0.6.4__py3-none-any.whl → 0.6.6__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.6.4"
3
+ __version__ = "0.6.6"
4
4
 
5
5
  from ._cases import (
6
6
  AsyncFoamCase,
@@ -2,6 +2,7 @@ import asyncio
2
2
  import os
3
3
  import subprocess
4
4
  import sys
5
+ from io import BytesIO
5
6
  from typing import IO, Optional, Union
6
7
 
7
8
  if sys.version_info >= (3, 9):
@@ -48,22 +49,26 @@ def run_sync(
48
49
  shell=isinstance(cmd, str),
49
50
  )
50
51
 
51
- error = b""
52
-
53
52
  if stderr == STDOUT:
54
53
  stderr = stdout
55
54
  if stderr not in (PIPE, DEVNULL):
55
+ stderr_copy = BytesIO()
56
+
56
57
  assert not isinstance(stderr, int)
57
58
  if stderr is None:
58
59
  stderr = sys.stderr.buffer
59
60
 
60
61
  assert proc.stderr is not None
61
62
  for line in proc.stderr:
62
- error += line
63
63
  stderr.write(line)
64
+ stderr_copy.write(line)
65
+
66
+ output, _ = proc.communicate()
67
+ assert not _
68
+ error = stderr_copy.getvalue()
69
+ else:
70
+ output, error = proc.communicate()
64
71
 
65
- output, _ = proc.communicate()
66
- assert not _
67
72
  assert proc.returncode is not None
68
73
 
69
74
  if check and proc.returncode != 0:
@@ -108,22 +113,26 @@ async def run_async(
108
113
  stderr=PIPE,
109
114
  )
110
115
 
111
- error = b""
112
-
113
116
  if stderr == STDOUT:
114
117
  stderr = stdout
115
118
  if stderr not in (PIPE, DEVNULL):
119
+ stderr_copy = BytesIO()
120
+
116
121
  assert not isinstance(stderr, int)
117
122
  if stderr is None:
118
123
  stderr = sys.stderr.buffer
119
124
 
120
125
  assert proc.stderr is not None
121
126
  async for line in proc.stderr:
122
- error += line
123
127
  stderr.write(line)
128
+ stderr_copy.write(line)
129
+
130
+ output, _ = await proc.communicate()
131
+ assert not _
132
+ error = stderr_copy.getvalue()
133
+ else:
134
+ output, error = await proc.communicate()
124
135
 
125
- output, _ = await proc.communicate()
126
- assert not _
127
136
  assert proc.returncode is not None
128
137
 
129
138
  if check and proc.returncode != 0:
foamlib/_cases/_sync.py CHANGED
@@ -1,7 +1,6 @@
1
1
  import os
2
2
  import shutil
3
3
  import sys
4
- from pathlib import Path
5
4
  from types import TracebackType
6
5
  from typing import Any, Callable, Optional, Type, Union, overload
7
6
 
@@ -49,9 +48,6 @@ class FoamCase(FoamCaseRunBase):
49
48
 
50
49
  return calls.value
51
50
 
52
- def __init__(self, path: Union["os.PathLike[str]", str] = Path()):
53
- super().__init__(path)
54
-
55
51
  @staticmethod
56
52
  def _run(
57
53
  cmd: Union[Sequence[Union[str, "os.PathLike[str]"]], str],
foamlib/_files/_files.py CHANGED
@@ -186,12 +186,10 @@ class FoamFile(
186
186
 
187
187
  try:
188
188
  write_header = (
189
- not self
190
- and "FoamFile" not in self
191
- and (not keywords or keywords[0] != "FoamFile")
189
+ not self and "FoamFile" not in self and keywords != ("FoamFile",)
192
190
  )
193
191
  except FileNotFoundError:
194
- write_header = not keywords or keywords[0] != "FoamFile"
192
+ write_header = keywords != ("FoamFile",)
195
193
 
196
194
  if write_header:
197
195
  self["FoamFile"] = {}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: foamlib
3
- Version: 0.6.4
3
+ Version: 0.6.6
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
@@ -68,9 +68,10 @@ Requires-Dist: mypy <2,>=1 ; extra == 'typing'
68
68
 
69
69
  It offers the following classes:
70
70
 
71
- * [`FoamFile`](https://foamlib.readthedocs.io/en/stable/files.html#foamlib.FoamFile) (and [`FoamFieldFile`](https://foamlib.readthedocs.io/en/stable/files.html#foamlib.FoamFieldFile)): read-write access to OpenFOAM configuration and field files as if they were Python `dict`s, using `foamlib`'s own parser. Supports both ASCII and binary field formats.
71
+ * [`FoamFile`](https://foamlib.readthedocs.io/en/stable/files.html#foamlib.FoamFile) (and [`FoamFieldFile`](https://foamlib.readthedocs.io/en/stable/files.html#foamlib.FoamFieldFile)): read-write access to OpenFOAM configuration and field files as if they were Python `dict`s, using `foamlib`'s own parser. Supports ASCII and binary field formats (with or without compression).
72
72
  * [`FoamCase`](https://foamlib.readthedocs.io/en/stable/cases.html#foamlib.FoamCase): a class for configuring, running, and accessing the results of OpenFOAM cases.
73
73
  * [`AsyncFoamCase`](https://foamlib.readthedocs.io/en/stable/cases.html#foamlib.AsyncFoamCase): variant of `FoamCase` with asynchronous methods for running multiple cases at once.
74
+ * [`AsyncSlurmFoamCase`](https://foamlib.readthedocs.io/en/stable/cases.html#foamlib.AsyncSlurmFoamCase): subclass of `AsyncFoamCase` used for running cases on a Slurm cluster.
74
75
 
75
76
  ## Get started
76
77
 
@@ -164,6 +165,7 @@ from foamlib import AsyncFoamCase
164
165
  from scipy.optimize import differential_evolution
165
166
 
166
167
  base = AsyncFoamCase(Path(os.environ["FOAM_TUTORIALS"]) / "incompressible/simpleFoam/pitzDaily")
168
+ # Replace with `AsyncSlurmFoamCase` if on a cluster and you want cases to be run as Slurm jobs
167
169
 
168
170
  async def cost(x):
169
171
  async with base.clone() as clone:
@@ -1,22 +1,22 @@
1
- foamlib/__init__.py,sha256=bmL3_3H-rn3OrCYQZeUZkDBGgYygbgZJ2pd8dAoAvig,486
1
+ foamlib/__init__.py,sha256=qC9o7n8gVSCw0x-I6eWgOoqp8Fszi4QrL6Ub4ZozWvI,486
2
2
  foamlib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  foamlib/_cases/__init__.py,sha256=wTUHcUgU1CBgpu0cUMtksQ5VKG6B8CFu9xc3dWwsQuo,358
4
4
  foamlib/_cases/_async.py,sha256=PYODgIkRLHArMf3wtf34jMx7gBGi-K6hoLEhjYK9bOw,7753
5
5
  foamlib/_cases/_base.py,sha256=4VWsu22VockyKgU_5tnSMeNrAkMgBKwZo2KGkV65rRQ,6739
6
6
  foamlib/_cases/_run.py,sha256=SjA-Qux5NhnhcLz7qiph2DcGYpElAAl_PlTGk6kGeuU,13972
7
7
  foamlib/_cases/_slurm.py,sha256=rhGSFJ-3g72TnAYlhECGfs7P7IkeaHL3ysjXfXLdCCc,2308
8
- foamlib/_cases/_subprocess.py,sha256=GTmHWy1LRD9ujpXJfSTXU2bf87GncpIA0VOR1rQW2fg,3633
9
- foamlib/_cases/_sync.py,sha256=L1Em9_32zd01RnMvksZ1GU-4okxhcwZgpLQf1c15uAs,6038
8
+ foamlib/_cases/_subprocess.py,sha256=Z6GHZ44fIQcOiDO-c7Oqp8pqE8NG7WFP9Mdbf_6WtIU,3916
9
+ foamlib/_cases/_sync.py,sha256=5lVMGuesCC--1GX8CL82bXg2o0K7OsZoff2zSOEs5d0,5910
10
10
  foamlib/_cases/_util.py,sha256=GNndpqw3Jg_S-Hxzl5vwRgD0czcTNb9NYHMhcfBoMBg,1493
11
11
  foamlib/_files/__init__.py,sha256=-UqB9YTH6mrJfXCX00kPTAAY20XG64u1MGPw_1ewLVs,148
12
12
  foamlib/_files/_base.py,sha256=zaFDjLE6jB7WtGWk8hfKusjLtlGu6CZV16AHJpRUibs,1929
13
- foamlib/_files/_files.py,sha256=DxM5JmXv19PJrqlKNwuP6SsB0nye6aN1hiPwble7fFM,15657
13
+ foamlib/_files/_files.py,sha256=1jV52dZqr-g6P0X0lA80OQcr2yMt4O-mAgERcaU4440,15583
14
14
  foamlib/_files/_io.py,sha256=T8vTEmJDidL03qeX1PUJFND-_vaF0AuC_0lE_zxLz7Q,2447
15
15
  foamlib/_files/_parsing.py,sha256=DzgJ53QnohRQyLXn2zOs52RIQ7bJ_fS_S2Z7rmRyVK4,9023
16
16
  foamlib/_files/_serialization.py,sha256=pb8_cIVgRhGS_ZV2p3x8p5_lK1SS6xzQHscAYYuOgFY,3407
17
17
  foamlib/_files/_util.py,sha256=UMzXmTFgvbp46w6k3oEZJoYC98pFgEK6LN5uLOwrlCg,397
18
- foamlib-0.6.4.dist-info/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
19
- foamlib-0.6.4.dist-info/METADATA,sha256=VeyVZAbFPEiSVnWDZ4XNzGYOHuz04fhmNkiGvYQp8KY,6569
20
- foamlib-0.6.4.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
21
- foamlib-0.6.4.dist-info/top_level.txt,sha256=ZdVYtetXGwPwyfL-WhlhbTFQGAwKX5P_gXxtH9JYFPI,8
22
- foamlib-0.6.4.dist-info/RECORD,,
18
+ foamlib-0.6.6.dist-info/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
19
+ foamlib-0.6.6.dist-info/METADATA,sha256=qvNj5spqcgV48wAZ14CAUUK6_X5pInV_vIjNJyMOaRY,6866
20
+ foamlib-0.6.6.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
21
+ foamlib-0.6.6.dist-info/top_level.txt,sha256=ZdVYtetXGwPwyfL-WhlhbTFQGAwKX5P_gXxtH9JYFPI,8
22
+ foamlib-0.6.6.dist-info/RECORD,,