foamlib 0.6.0__tar.gz → 0.6.2__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 (26) hide show
  1. {foamlib-0.6.0 → foamlib-0.6.2}/PKG-INFO +1 -1
  2. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib/__init__.py +1 -1
  3. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib/_cases/_run.py +6 -6
  4. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib/_cases/_subprocess.py +60 -7
  5. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib/_cases/_sync.py +4 -2
  6. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib.egg-info/PKG-INFO +1 -1
  7. {foamlib-0.6.0 → foamlib-0.6.2}/LICENSE.txt +0 -0
  8. {foamlib-0.6.0 → foamlib-0.6.2}/README.md +0 -0
  9. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib/_cases/__init__.py +0 -0
  10. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib/_cases/_async.py +0 -0
  11. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib/_cases/_base.py +0 -0
  12. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib/_cases/_util.py +0 -0
  13. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib/_files/__init__.py +0 -0
  14. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib/_files/_base.py +0 -0
  15. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib/_files/_files.py +0 -0
  16. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib/_files/_io.py +0 -0
  17. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib/_files/_parsing.py +0 -0
  18. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib/_files/_serialization.py +0 -0
  19. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib/_files/_util.py +0 -0
  20. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib/py.typed +0 -0
  21. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib.egg-info/SOURCES.txt +0 -0
  22. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib.egg-info/dependency_links.txt +0 -0
  23. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib.egg-info/requires.txt +0 -0
  24. {foamlib-0.6.0 → foamlib-0.6.2}/foamlib.egg-info/top_level.txt +0 -0
  25. {foamlib-0.6.0 → foamlib-0.6.2}/pyproject.toml +0 -0
  26. {foamlib-0.6.0 → foamlib-0.6.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: foamlib
3
- Version: 0.6.0
3
+ Version: 0.6.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,6 +1,6 @@
1
1
  """A Python interface for interacting with OpenFOAM."""
2
2
 
3
- __version__ = "0.6.0"
3
+ __version__ = "0.6.2"
4
4
 
5
5
  from ._cases import (
6
6
  AsyncFoamCase,
@@ -177,7 +177,7 @@ class FoamCaseRunBase(FoamCaseBase):
177
177
 
178
178
  return script
179
179
 
180
- def __run_script(self, *, parallel: Optional[bool] = None) -> Optional[Path]:
180
+ def __run_script(self, *, parallel: Optional[bool]) -> Optional[Path]:
181
181
  """Return the path to the (All)run script, or None if no run script is found."""
182
182
  run = self.path / "run"
183
183
  run_parallel = self.path / "run-parallel"
@@ -263,7 +263,7 @@ class FoamCaseRunBase(FoamCaseBase):
263
263
 
264
264
  return type(self)(dst)
265
265
 
266
- def _clean_calls(self, *, check: bool = False) -> Generator[Any, None, None]:
266
+ def _clean_calls(self, *, check: bool) -> Generator[Any, None, None]:
267
267
  script_path = self.__clean_script()
268
268
 
269
269
  if script_path is not None:
@@ -299,10 +299,10 @@ class FoamCaseRunBase(FoamCaseBase):
299
299
  self,
300
300
  cmd: Optional[Union[Sequence[Union[str, "os.PathLike[str]"]], str]] = None,
301
301
  *,
302
- parallel: Optional[bool] = None,
303
- cpus: Optional[int] = None,
304
- check: bool = True,
305
- log: bool = True,
302
+ parallel: Optional[bool],
303
+ cpus: Optional[int],
304
+ check: bool,
305
+ log: bool,
306
306
  ) -> Generator[Any, None, None]:
307
307
  if cmd is not None:
308
308
  if parallel:
@@ -9,9 +9,19 @@ if sys.version_info >= (3, 9):
9
9
  else:
10
10
  from typing import Mapping, Sequence
11
11
 
12
- CalledProcessError = subprocess.CalledProcessError
13
12
  CompletedProcess = subprocess.CompletedProcess
14
13
 
14
+
15
+ class CalledProcessError(subprocess.CalledProcessError):
16
+ def __str__(self) -> str:
17
+ if self.stderr:
18
+ if isinstance(self.stderr, bytes):
19
+ return super().__str__() + "\n" + self.stderr.decode()
20
+ elif isinstance(self.stderr, str):
21
+ return super().__str__() + "\n" + self.stderr
22
+ return super().__str__()
23
+
24
+
15
25
  DEVNULL = subprocess.DEVNULL
16
26
  PIPE = subprocess.PIPE
17
27
  STDOUT = subprocess.STDOUT
@@ -29,14 +39,43 @@ def run_sync(
29
39
  if not isinstance(cmd, str) and sys.version_info < (3, 8):
30
40
  cmd = [str(arg) for arg in cmd]
31
41
 
32
- return subprocess.run(
42
+ proc = subprocess.Popen(
33
43
  cmd,
34
44
  cwd=cwd,
35
45
  env=env,
36
46
  stdout=stdout,
37
- stderr=stderr,
47
+ stderr=PIPE,
38
48
  shell=isinstance(cmd, str),
39
- check=check,
49
+ )
50
+
51
+ error = b""
52
+
53
+ if stderr == STDOUT:
54
+ stderr = stdout
55
+ if stderr not in (PIPE, DEVNULL):
56
+ assert not isinstance(stderr, int)
57
+ if stderr is None:
58
+ stderr = sys.stderr.buffer
59
+
60
+ assert proc.stderr is not None
61
+ for line in proc.stderr:
62
+ error += line
63
+ stderr.write(line)
64
+
65
+ output, _ = proc.communicate()
66
+ assert not _
67
+ assert proc.returncode is not None
68
+
69
+ if check and proc.returncode != 0:
70
+ raise CalledProcessError(
71
+ returncode=proc.returncode,
72
+ cmd=cmd,
73
+ output=output,
74
+ stderr=error,
75
+ )
76
+
77
+ return CompletedProcess(
78
+ cmd, returncode=proc.returncode, stdout=output, stderr=error
40
79
  )
41
80
 
42
81
 
@@ -55,7 +94,7 @@ async def run_async(
55
94
  cwd=cwd,
56
95
  env=env,
57
96
  stdout=stdout,
58
- stderr=stderr,
97
+ stderr=PIPE,
59
98
  )
60
99
 
61
100
  else:
@@ -66,11 +105,25 @@ async def run_async(
66
105
  cwd=cwd,
67
106
  env=env,
68
107
  stdout=stdout,
69
- stderr=stderr,
108
+ stderr=PIPE,
70
109
  )
71
110
 
72
- output, error = await proc.communicate()
111
+ error = b""
112
+
113
+ if stderr == STDOUT:
114
+ stderr = stdout
115
+ if stderr not in (PIPE, DEVNULL):
116
+ assert not isinstance(stderr, int)
117
+ if stderr is None:
118
+ stderr = sys.stderr.buffer
119
+
120
+ assert proc.stderr is not None
121
+ async for line in proc.stderr:
122
+ error += line
123
+ stderr.write(line)
73
124
 
125
+ output, _ = await proc.communicate()
126
+ assert not _
74
127
  assert proc.returncode is not None
75
128
 
76
129
  if check and proc.returncode != 0:
@@ -67,7 +67,7 @@ class FoamCase(FoamCaseRunBase):
67
67
  ) -> None:
68
68
  shutil.copytree(src, dest, symlinks=symlinks, ignore=ignore)
69
69
 
70
- def __enter__(self) -> "FoamCase":
70
+ def __enter__(self) -> Self:
71
71
  return self
72
72
 
73
73
  def __exit__(
@@ -105,7 +105,9 @@ class FoamCase(FoamCaseRunBase):
105
105
  :param check: If True, raise a CalledProcessError if any command returns a non-zero exit code.
106
106
  :param log: If True, log the command output to a file.
107
107
  """
108
- for _ in self._run_calls(cmd=cmd, parallel=parallel, check=check):
108
+ for _ in self._run_calls(
109
+ cmd=cmd, parallel=parallel, cpus=cpus, check=check, log=log
110
+ ):
109
111
  pass
110
112
 
111
113
  def block_mesh(self, *, check: bool = True) -> None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: foamlib
3
- Version: 0.6.0
3
+ Version: 0.6.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
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