foamlib 0.3.15__tar.gz → 0.3.17__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.
- {foamlib-0.3.15 → foamlib-0.3.17}/PKG-INFO +1 -1
- {foamlib-0.3.15 → foamlib-0.3.17}/foamlib/__init__.py +8 -3
- {foamlib-0.3.15 → foamlib-0.3.17}/foamlib/_cases/__init__.py +3 -0
- {foamlib-0.3.15 → foamlib-0.3.17}/foamlib/_cases/_async.py +29 -2
- {foamlib-0.3.15 → foamlib-0.3.17}/foamlib/_cases/_base.py +19 -0
- {foamlib-0.3.15 → foamlib-0.3.17}/foamlib/_cases/_sync.py +23 -2
- foamlib-0.3.17/foamlib/_cases/_util.py +35 -0
- {foamlib-0.3.15 → foamlib-0.3.17}/foamlib/_files/_io.py +0 -1
- foamlib-0.3.17/foamlib/_util.py +18 -0
- {foamlib-0.3.15 → foamlib-0.3.17}/foamlib.egg-info/PKG-INFO +1 -1
- {foamlib-0.3.15 → foamlib-0.3.17}/foamlib.egg-info/SOURCES.txt +1 -0
- foamlib-0.3.15/foamlib/_util.py +0 -119
- {foamlib-0.3.15 → foamlib-0.3.17}/LICENSE.txt +0 -0
- {foamlib-0.3.15 → foamlib-0.3.17}/README.md +0 -0
- {foamlib-0.3.15 → foamlib-0.3.17}/foamlib/_files/__init__.py +0 -0
- {foamlib-0.3.15 → foamlib-0.3.17}/foamlib/_files/_base.py +0 -0
- {foamlib-0.3.15 → foamlib-0.3.17}/foamlib/_files/_files.py +0 -0
- {foamlib-0.3.15 → foamlib-0.3.17}/foamlib/_files/_parsing.py +0 -0
- {foamlib-0.3.15 → foamlib-0.3.17}/foamlib/_files/_serialization.py +0 -0
- {foamlib-0.3.15 → foamlib-0.3.17}/foamlib/py.typed +0 -0
- {foamlib-0.3.15 → foamlib-0.3.17}/foamlib.egg-info/dependency_links.txt +0 -0
- {foamlib-0.3.15 → foamlib-0.3.17}/foamlib.egg-info/requires.txt +0 -0
- {foamlib-0.3.15 → foamlib-0.3.17}/foamlib.egg-info/top_level.txt +0 -0
- {foamlib-0.3.15 → foamlib-0.3.17}/pyproject.toml +0 -0
- {foamlib-0.3.15 → foamlib-0.3.17}/setup.cfg +0 -0
@@ -1,10 +1,15 @@
|
|
1
1
|
"""A Python interface for interacting with OpenFOAM."""
|
2
2
|
|
3
|
-
__version__ = "0.3.
|
3
|
+
__version__ = "0.3.17"
|
4
4
|
|
5
|
-
from ._cases import
|
5
|
+
from ._cases import (
|
6
|
+
AsyncFoamCase,
|
7
|
+
CalledProcessError,
|
8
|
+
CalledProcessWarning,
|
9
|
+
FoamCase,
|
10
|
+
FoamCaseBase,
|
11
|
+
)
|
6
12
|
from ._files import FoamDict, FoamFieldFile, FoamFile
|
7
|
-
from ._util import CalledProcessError, CalledProcessWarning
|
8
13
|
|
9
14
|
__all__ = [
|
10
15
|
"FoamCase",
|
@@ -1,9 +1,12 @@
|
|
1
1
|
from ._async import AsyncFoamCase
|
2
2
|
from ._base import FoamCaseBase
|
3
3
|
from ._sync import FoamCase
|
4
|
+
from ._util import CalledProcessError, CalledProcessWarning
|
4
5
|
|
5
6
|
__all__ = [
|
6
7
|
"FoamCaseBase",
|
7
8
|
"FoamCase",
|
8
9
|
"AsyncFoamCase",
|
10
|
+
"CalledProcessError",
|
11
|
+
"CalledProcessWarning",
|
9
12
|
]
|
@@ -15,8 +15,9 @@ else:
|
|
15
15
|
|
16
16
|
import aioshutil
|
17
17
|
|
18
|
-
from .._util import
|
18
|
+
from .._util import is_sequence
|
19
19
|
from ._base import FoamCaseBase
|
20
|
+
from ._util import check_returncode
|
20
21
|
|
21
22
|
|
22
23
|
class AsyncFoamCase(FoamCaseBase):
|
@@ -89,7 +90,33 @@ class AsyncFoamCase(FoamCaseBase):
|
|
89
90
|
*,
|
90
91
|
check: bool = True,
|
91
92
|
) -> None:
|
92
|
-
|
93
|
+
if not is_sequence(cmd):
|
94
|
+
proc = await asyncio.create_subprocess_shell(
|
95
|
+
str(cmd),
|
96
|
+
cwd=self.path,
|
97
|
+
env=self._env(shell=True),
|
98
|
+
stdout=asyncio.subprocess.DEVNULL,
|
99
|
+
stderr=asyncio.subprocess.PIPE if check else asyncio.subprocess.DEVNULL,
|
100
|
+
)
|
101
|
+
|
102
|
+
else:
|
103
|
+
if sys.version_info < (3, 8):
|
104
|
+
cmd = (str(arg) for arg in cmd)
|
105
|
+
proc = await asyncio.create_subprocess_exec(
|
106
|
+
*cmd,
|
107
|
+
cwd=self.path,
|
108
|
+
env=self._env(shell=False),
|
109
|
+
stdout=asyncio.subprocess.DEVNULL,
|
110
|
+
stderr=asyncio.subprocess.PIPE if check else asyncio.subprocess.DEVNULL,
|
111
|
+
)
|
112
|
+
|
113
|
+
stdout, stderr = await proc.communicate()
|
114
|
+
|
115
|
+
assert stdout is None
|
116
|
+
assert proc.returncode is not None
|
117
|
+
|
118
|
+
if check:
|
119
|
+
check_returncode(proc.returncode, cmd, stderr.decode())
|
93
120
|
|
94
121
|
async def run(
|
95
122
|
self,
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import os
|
1
2
|
import sys
|
2
3
|
from pathlib import Path
|
3
4
|
from typing import (
|
@@ -227,6 +228,24 @@ class FoamCaseBase(Sequence["FoamCaseBase.TimeDirectory"]):
|
|
227
228
|
|
228
229
|
return script
|
229
230
|
|
231
|
+
def _env(self, *, shell: bool) -> Optional[Mapping[str, str]]:
|
232
|
+
sip_workaround = os.environ.get(
|
233
|
+
"FOAM_LD_LIBRARY_PATH", ""
|
234
|
+
) and not os.environ.get("DYLD_LIBRARY_PATH", "")
|
235
|
+
|
236
|
+
if not shell or sip_workaround:
|
237
|
+
env = os.environ.copy()
|
238
|
+
|
239
|
+
if not shell:
|
240
|
+
env["PWD"] = str(self.path)
|
241
|
+
|
242
|
+
if sip_workaround:
|
243
|
+
env["DYLD_LIBRARY_PATH"] = env["FOAM_LD_LIBRARY_PATH"]
|
244
|
+
|
245
|
+
return env
|
246
|
+
else:
|
247
|
+
return None
|
248
|
+
|
230
249
|
def _run_cmds(
|
231
250
|
self,
|
232
251
|
cmd: Optional[Union[Sequence[Union[str, Path]], str, Path]] = None,
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import shutil
|
2
|
+
import subprocess
|
2
3
|
import sys
|
3
4
|
from pathlib import Path
|
4
5
|
from typing import (
|
@@ -11,8 +12,9 @@ if sys.version_info >= (3, 9):
|
|
11
12
|
else:
|
12
13
|
from typing import Sequence
|
13
14
|
|
14
|
-
from .._util import
|
15
|
+
from .._util import is_sequence
|
15
16
|
from ._base import FoamCaseBase
|
17
|
+
from ._util import check_returncode
|
16
18
|
|
17
19
|
|
18
20
|
class FoamCase(FoamCaseBase):
|
@@ -55,7 +57,26 @@ class FoamCase(FoamCaseBase):
|
|
55
57
|
*,
|
56
58
|
check: bool = True,
|
57
59
|
) -> None:
|
58
|
-
|
60
|
+
shell = not is_sequence(cmd)
|
61
|
+
|
62
|
+
if sys.version_info < (3, 8):
|
63
|
+
if shell:
|
64
|
+
cmd = str(cmd)
|
65
|
+
else:
|
66
|
+
cmd = (str(arg) for arg in cmd)
|
67
|
+
|
68
|
+
proc = subprocess.run(
|
69
|
+
cmd,
|
70
|
+
cwd=self.path,
|
71
|
+
env=self._env(shell=shell),
|
72
|
+
stdout=subprocess.DEVNULL,
|
73
|
+
stderr=subprocess.PIPE if check else subprocess.DEVNULL,
|
74
|
+
text=True,
|
75
|
+
shell=shell,
|
76
|
+
)
|
77
|
+
|
78
|
+
if check:
|
79
|
+
check_returncode(proc.returncode, cmd, proc.stderr)
|
59
80
|
|
60
81
|
def run(
|
61
82
|
self,
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import subprocess
|
2
|
+
import sys
|
3
|
+
from pathlib import Path
|
4
|
+
from typing import Optional, Union
|
5
|
+
from warnings import warn
|
6
|
+
|
7
|
+
if sys.version_info >= (3, 9):
|
8
|
+
from collections.abc import Sequence
|
9
|
+
else:
|
10
|
+
from typing import Sequence
|
11
|
+
|
12
|
+
|
13
|
+
class CalledProcessError(subprocess.CalledProcessError):
|
14
|
+
"""Exception raised when a process fails and `check=True`."""
|
15
|
+
|
16
|
+
def __str__(self) -> str:
|
17
|
+
msg = super().__str__()
|
18
|
+
if self.stderr:
|
19
|
+
msg += f"\n{self.stderr}"
|
20
|
+
return msg
|
21
|
+
|
22
|
+
|
23
|
+
class CalledProcessWarning(Warning):
|
24
|
+
"""Warning raised when a process prints to stderr and `check=True`."""
|
25
|
+
|
26
|
+
|
27
|
+
def check_returncode(
|
28
|
+
retcode: int,
|
29
|
+
cmd: Union[Sequence[Union[str, Path]], str, Path],
|
30
|
+
stderr: Optional[str],
|
31
|
+
) -> None:
|
32
|
+
if retcode != 0:
|
33
|
+
raise CalledProcessError(retcode, cmd, None, stderr)
|
34
|
+
elif stderr:
|
35
|
+
warn(f"Command {cmd} printed to stderr.\n{stderr}", CalledProcessWarning)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import sys
|
2
|
+
from typing import Any
|
3
|
+
|
4
|
+
if sys.version_info >= (3, 9):
|
5
|
+
from collections.abc import Sequence
|
6
|
+
else:
|
7
|
+
from typing import Sequence
|
8
|
+
|
9
|
+
if sys.version_info >= (3, 10):
|
10
|
+
from typing import TypeGuard
|
11
|
+
else:
|
12
|
+
from typing_extensions import TypeGuard
|
13
|
+
|
14
|
+
|
15
|
+
def is_sequence(
|
16
|
+
value: Any,
|
17
|
+
) -> TypeGuard[Sequence[Any]]:
|
18
|
+
return isinstance(value, Sequence) and not isinstance(value, str)
|
foamlib-0.3.15/foamlib/_util.py
DELETED
@@ -1,119 +0,0 @@
|
|
1
|
-
import asyncio
|
2
|
-
import os
|
3
|
-
import subprocess
|
4
|
-
import sys
|
5
|
-
from pathlib import Path
|
6
|
-
from typing import Any, Optional, Union
|
7
|
-
from warnings import warn
|
8
|
-
|
9
|
-
if sys.version_info >= (3, 9):
|
10
|
-
from collections.abc import Mapping, Sequence
|
11
|
-
else:
|
12
|
-
from typing import Mapping, Sequence
|
13
|
-
|
14
|
-
if sys.version_info >= (3, 10):
|
15
|
-
from typing import TypeGuard
|
16
|
-
else:
|
17
|
-
from typing_extensions import TypeGuard
|
18
|
-
|
19
|
-
|
20
|
-
def is_sequence(
|
21
|
-
value: Any,
|
22
|
-
) -> TypeGuard[Sequence[Any]]:
|
23
|
-
return isinstance(value, Sequence) and not isinstance(value, str)
|
24
|
-
|
25
|
-
|
26
|
-
class CalledProcessError(subprocess.CalledProcessError):
|
27
|
-
"""Exception raised when a process fails and `check=True`."""
|
28
|
-
|
29
|
-
def __str__(self) -> str:
|
30
|
-
msg = super().__str__()
|
31
|
-
if self.stderr:
|
32
|
-
msg += f"\n{self.stderr}"
|
33
|
-
return msg
|
34
|
-
|
35
|
-
|
36
|
-
class CalledProcessWarning(Warning):
|
37
|
-
"""Warning raised when a process prints to stderr and `check=True`."""
|
38
|
-
|
39
|
-
|
40
|
-
def _check(
|
41
|
-
retcode: int,
|
42
|
-
cmd: Union[Sequence[Union[str, Path]], str, Path],
|
43
|
-
stderr: Optional[str],
|
44
|
-
) -> None:
|
45
|
-
if retcode != 0:
|
46
|
-
raise CalledProcessError(retcode, cmd, None, stderr)
|
47
|
-
elif stderr:
|
48
|
-
warn(f"Command {cmd} printed to stderr.\n{stderr}", CalledProcessWarning)
|
49
|
-
|
50
|
-
|
51
|
-
def _env(cwd: Optional[Union[str, Path]] = None) -> Optional[Mapping[str, str]]:
|
52
|
-
if cwd is not None:
|
53
|
-
env = os.environ.copy()
|
54
|
-
env["PWD"] = str(cwd)
|
55
|
-
return env
|
56
|
-
else:
|
57
|
-
return None
|
58
|
-
|
59
|
-
|
60
|
-
def run_process(
|
61
|
-
cmd: Union[Sequence[Union[str, Path]], str, Path],
|
62
|
-
*,
|
63
|
-
check: bool = True,
|
64
|
-
cwd: Union[None, str, Path] = None,
|
65
|
-
) -> None:
|
66
|
-
shell = not is_sequence(cmd)
|
67
|
-
|
68
|
-
if sys.version_info < (3, 8):
|
69
|
-
if shell:
|
70
|
-
cmd = str(cmd)
|
71
|
-
else:
|
72
|
-
cmd = (str(arg) for arg in cmd)
|
73
|
-
|
74
|
-
proc = subprocess.run(
|
75
|
-
cmd,
|
76
|
-
cwd=cwd,
|
77
|
-
env=_env(cwd) if not shell else None,
|
78
|
-
stdout=subprocess.DEVNULL,
|
79
|
-
stderr=subprocess.PIPE if check else subprocess.DEVNULL,
|
80
|
-
text=True,
|
81
|
-
shell=shell,
|
82
|
-
)
|
83
|
-
|
84
|
-
if check:
|
85
|
-
_check(proc.returncode, cmd, proc.stderr)
|
86
|
-
|
87
|
-
|
88
|
-
async def run_process_async(
|
89
|
-
cmd: Union[Sequence[Union[str, Path]], str, Path],
|
90
|
-
*,
|
91
|
-
check: bool = True,
|
92
|
-
cwd: Union[None, str, Path] = None,
|
93
|
-
) -> None:
|
94
|
-
if not is_sequence(cmd):
|
95
|
-
proc = await asyncio.create_subprocess_shell(
|
96
|
-
str(cmd),
|
97
|
-
cwd=cwd,
|
98
|
-
stdout=asyncio.subprocess.DEVNULL,
|
99
|
-
stderr=asyncio.subprocess.PIPE if check else asyncio.subprocess.DEVNULL,
|
100
|
-
)
|
101
|
-
|
102
|
-
else:
|
103
|
-
if sys.version_info < (3, 8):
|
104
|
-
cmd = (str(arg) for arg in cmd)
|
105
|
-
proc = await asyncio.create_subprocess_exec(
|
106
|
-
*cmd,
|
107
|
-
cwd=cwd,
|
108
|
-
env=_env(cwd),
|
109
|
-
stdout=asyncio.subprocess.DEVNULL,
|
110
|
-
stderr=asyncio.subprocess.PIPE if check else asyncio.subprocess.DEVNULL,
|
111
|
-
)
|
112
|
-
|
113
|
-
stdout, stderr = await proc.communicate()
|
114
|
-
|
115
|
-
assert stdout is None
|
116
|
-
assert proc.returncode is not None
|
117
|
-
|
118
|
-
if check:
|
119
|
-
_check(proc.returncode, cmd, stderr.decode())
|
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
|