foamlib 0.2.4__py3-none-any.whl → 0.2.5__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,4 +1,4 @@
1
- __version__ = "0.2.4"
1
+ __version__ = "0.2.5"
2
2
 
3
3
  from ._cases import FoamCase, AsyncFoamCase, FoamCaseBase
4
4
  from ._dictionaries import FoamFile, FoamFieldFile, FoamDictionaryBase
foamlib/_cases.py CHANGED
@@ -1,3 +1,4 @@
1
+ import sys
1
2
  import os
2
3
  import asyncio
3
4
  import multiprocessing
@@ -8,19 +9,26 @@ from contextlib import asynccontextmanager
8
9
  from typing import (
9
10
  Optional,
10
11
  Union,
11
- Collection,
12
- Mapping,
13
- Set,
14
- Sequence,
15
- AsyncGenerator,
16
- Callable,
17
- Iterator,
18
12
  overload,
19
13
  )
20
14
 
15
+ if sys.version_info >= (3, 9):
16
+ from collections.abc import (
17
+ Collection,
18
+ Mapping,
19
+ Set,
20
+ Sequence,
21
+ AsyncGenerator,
22
+ Callable,
23
+ Iterator,
24
+ )
25
+ else:
26
+ from typing import Collection, Mapping, Sequence, AsyncGenerator, Callable, Iterator
27
+ from typing import AbstractSet as Set
28
+
21
29
  import aioshutil
22
30
 
23
- from ._subprocesses import run_process, run_process_async, CalledProcessError
31
+ from ._util import is_sequence, run_process, run_process_async, CalledProcessError
24
32
  from ._dictionaries import FoamFile, FoamFieldFile
25
33
 
26
34
 
@@ -132,7 +140,7 @@ class FoamCaseBase(Sequence["FoamCaseBase.TimeDirectory"]):
132
140
  has_decompose_par_dict = (self.path / "system" / "decomposeParDict").is_file()
133
141
  has_block_mesh_dict = (self.path / "system" / "blockMeshDict").is_file()
134
142
 
135
- paths: Set[Path] = set()
143
+ paths = set()
136
144
 
137
145
  for p in self.path.iterdir():
138
146
  if p.is_dir():
@@ -215,7 +223,7 @@ class FoamCaseBase(Sequence["FoamCaseBase.TimeDirectory"]):
215
223
  def _parallel_cmd(
216
224
  self, cmd: Union[Sequence[Union[str, Path]], str, Path]
217
225
  ) -> Union[Sequence[Union[str, Path]], str]:
218
- if isinstance(cmd, str) or not isinstance(cmd, Sequence):
226
+ if not is_sequence(cmd):
219
227
  return f"mpiexec -np {self._nprocessors} {cmd} -parallel"
220
228
  else:
221
229
  return [
@@ -1,6 +1,13 @@
1
+ import sys
2
+
1
3
  from abc import abstractmethod
2
4
  from dataclasses import dataclass
3
- from typing import Dict, NamedTuple, Optional, Sequence, Union
5
+ from typing import Dict, NamedTuple, Optional, Union
6
+
7
+ if sys.version_info >= (3, 9):
8
+ from collections.abc import Sequence
9
+ else:
10
+ from typing import Sequence
4
11
 
5
12
 
6
13
  class FoamDictionaryBase:
@@ -1,21 +1,23 @@
1
+ import sys
2
+
1
3
  from pathlib import Path
2
4
  from typing import (
3
5
  Any,
4
- Iterator,
5
- Mapping,
6
- MutableMapping,
7
6
  Optional,
8
- Sequence,
9
7
  Tuple,
10
8
  Union,
11
9
  cast,
12
10
  )
13
11
 
14
- from typing_extensions import Self
12
+ if sys.version_info >= (3, 9):
13
+ from collections.abc import Iterator, Mapping, MutableMapping, Sequence
14
+ else:
15
+ from typing import Iterator, Mapping, MutableMapping, Sequence
15
16
 
16
- from ._base import FoamDictionaryBase
17
- from ._parsing import Parsed, as_dict, get_entry_locn, get_value, parse
18
- from ._serialization import serialize_entry
17
+ if sys.version_info >= (3, 11):
18
+ from typing import Self
19
+ else:
20
+ from typing_extensions import Self
19
21
 
20
22
  try:
21
23
  import numpy as np
@@ -23,6 +25,10 @@ try:
23
25
  except ModuleNotFoundError:
24
26
  pass
25
27
 
28
+ from ._base import FoamDictionaryBase
29
+ from ._parsing import Parsed, as_dict, get_entry_locn, get_value, parse
30
+ from ._serialization import serialize_entry
31
+
26
32
 
27
33
  class _FoamFileBase:
28
34
  def __init__(self, path: Union[str, Path]) -> None:
@@ -1,4 +1,11 @@
1
- from typing import Mapping, MutableMapping, Optional, Sequence, Tuple
1
+ import sys
2
+
3
+ from typing import Optional, Tuple
4
+
5
+ if sys.version_info >= (3, 9):
6
+ from collections.abc import Mapping, MutableMapping, Sequence
7
+ else:
8
+ from typing import Mapping, MutableMapping, Sequence
2
9
 
3
10
  from pyparsing import (
4
11
  Dict,
@@ -163,7 +170,6 @@ def as_dict(parsed: Parsed) -> FoamDictionaryBase._Dict:
163
170
  """
164
171
  ret: FoamDictionaryBase._Dict = {}
165
172
  for keywords, (_, value, _) in parsed.items():
166
-
167
173
  r = ret
168
174
  for k in keywords[:-1]:
169
175
  assert isinstance(r, dict)
@@ -1,23 +1,15 @@
1
- from contextlib import suppress
2
- from typing import Any, Mapping, Sequence
1
+ import sys
3
2
 
4
- from ._base import FoamDictionaryBase
3
+ from contextlib import suppress
4
+ from typing import Any
5
5
 
6
- try:
7
- import numpy as np
8
- except ModuleNotFoundError:
9
- numpy = False
6
+ if sys.version_info >= (3, 9):
7
+ from collections.abc import Mapping
10
8
  else:
11
- numpy = True
9
+ from typing import Mapping
12
10
 
13
-
14
- def _is_sequence(value: Any) -> bool:
15
- return (
16
- isinstance(value, Sequence)
17
- and not isinstance(value, str)
18
- or numpy
19
- and isinstance(value, np.ndarray)
20
- )
11
+ from ._base import FoamDictionaryBase
12
+ from .._util import is_sequence
21
13
 
22
14
 
23
15
  def _serialize_bool(value: Any) -> str:
@@ -30,14 +22,14 @@ def _serialize_bool(value: Any) -> str:
30
22
 
31
23
 
32
24
  def _serialize_list(value: Any) -> str:
33
- if _is_sequence(value):
25
+ if is_sequence(value):
34
26
  return f"({' '.join(_serialize_value(v) for v in value)})"
35
27
  else:
36
28
  raise TypeError(f"Not a valid sequence: {type(value)}")
37
29
 
38
30
 
39
31
  def _serialize_field(value: Any) -> str:
40
- if _is_sequence(value):
32
+ if is_sequence(value):
41
33
  try:
42
34
  s = _serialize_list(value)
43
35
  except TypeError:
@@ -64,7 +56,7 @@ def _serialize_field(value: Any) -> str:
64
56
 
65
57
 
66
58
  def _serialize_dimensions(value: Any) -> str:
67
- if _is_sequence(value) and len(value) == 7:
59
+ if is_sequence(value) and len(value) == 7:
68
60
  return f"[{' '.join(str(v) for v in value)}]"
69
61
  else:
70
62
  raise TypeError(f"Not a valid dimension set: {type(value)}")
@@ -1,12 +1,40 @@
1
1
  import asyncio
2
2
  import sys
3
+ import subprocess
3
4
 
4
5
  from pathlib import Path
5
- from typing import Union, Sequence, Mapping
6
- import subprocess
7
- from subprocess import CalledProcessError
6
+ from typing import Any, Union
7
+
8
+ if sys.version_info >= (3, 9):
9
+ from collections.abc import Mapping, Sequence
10
+ else:
11
+ from typing import Mapping, Sequence
12
+
13
+ if sys.version_info >= (3, 10):
14
+ from typing import TypeGuard
15
+ else:
16
+ from typing_extensions import TypeGuard
17
+
18
+ try:
19
+ import numpy as np
20
+ except ModuleNotFoundError:
21
+ numpy = False
22
+ else:
23
+ numpy = True
24
+
25
+
26
+ def is_sequence(
27
+ value: Any,
28
+ ) -> TypeGuard[Union["Sequence[Any]", "np.ndarray[Any, Any]"]]:
29
+ return (
30
+ isinstance(value, Sequence)
31
+ and not isinstance(value, str)
32
+ or numpy
33
+ and isinstance(value, np.ndarray)
34
+ )
35
+
8
36
 
9
- __all__ = ["run_process", "run_process_async", "CalledProcessError"]
37
+ CalledProcessError = subprocess.CalledProcessError
10
38
 
11
39
 
12
40
  def run_process(
@@ -16,7 +44,7 @@ def run_process(
16
44
  cwd: Union[None, str, Path] = None,
17
45
  env: Union[None, Mapping[str, str]] = None,
18
46
  ) -> "subprocess.CompletedProcess[bytes]":
19
- shell = isinstance(cmd, str) or not isinstance(cmd, Sequence)
47
+ shell = not is_sequence(cmd)
20
48
 
21
49
  if sys.version_info < (3, 8):
22
50
  if shell:
@@ -28,8 +56,7 @@ def run_process(
28
56
  cmd,
29
57
  cwd=cwd,
30
58
  env=env,
31
- stdout=subprocess.PIPE,
32
- stderr=subprocess.PIPE,
59
+ capture_output=True,
33
60
  shell=shell,
34
61
  check=check,
35
62
  )
@@ -44,7 +71,7 @@ async def run_process_async(
44
71
  cwd: Union[None, str, Path] = None,
45
72
  env: Union[None, Mapping[str, str]] = None,
46
73
  ) -> "subprocess.CompletedProcess[bytes]":
47
- if isinstance(cmd, str) or not isinstance(cmd, Sequence):
74
+ if not is_sequence(cmd):
48
75
  proc = await asyncio.create_subprocess_shell(
49
76
  str(cmd),
50
77
  cwd=cwd,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: foamlib
3
- Version: 0.2.4
3
+ Version: 0.2.5
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
@@ -27,24 +27,23 @@ Description-Content-Type: text/markdown
27
27
  License-File: LICENSE.txt
28
28
  Requires-Dist: aioshutil <2,>=1
29
29
  Requires-Dist: pyparsing <4,>=3
30
- Requires-Dist: typing-extensions <5,>=4
30
+ Requires-Dist: typing-extensions <5,>=4 ; python_version < "3.11"
31
31
  Provides-Extra: docs
32
32
  Requires-Dist: sphinx <8,>=7 ; extra == 'docs'
33
33
  Requires-Dist: sphinx-rtd-theme ; extra == 'docs'
34
34
  Requires-Dist: numpy <2,>=1 ; extra == 'docs'
35
35
  Provides-Extra: lint
36
- Requires-Dist: mypy <2,>=1 ; extra == 'lint'
37
- Requires-Dist: pytest <9,>=7 ; extra == 'lint'
38
- Requires-Dist: pytest-asyncio <0.24,>=0.21 ; extra == 'lint'
39
- Requires-Dist: numpy <2,>=1 ; extra == 'lint'
40
- Requires-Dist: black ; extra == 'lint'
41
- Requires-Dist: flake8 ; extra == 'lint'
42
- Requires-Dist: Flake8-pyproject ; extra == 'lint'
36
+ Requires-Dist: ruff ; extra == 'lint'
43
37
  Provides-Extra: test
44
38
  Requires-Dist: pytest <9,>=7 ; extra == 'test'
45
39
  Requires-Dist: pytest-asyncio <0.24,>=0.21 ; extra == 'test'
46
40
  Requires-Dist: pytest-cov ; extra == 'test'
47
41
  Requires-Dist: numpy <2,>=1 ; extra == 'test'
42
+ Provides-Extra: typing
43
+ Requires-Dist: mypy <2,>=1 ; extra == 'typing'
44
+ Requires-Dist: pytest <9,>=7 ; extra == 'typing'
45
+ Requires-Dist: pytest-asyncio <0.24,>=0.21 ; extra == 'typing'
46
+ Requires-Dist: numpy <2,>=1 ; extra == 'typing'
48
47
 
49
48
  # foamlib
50
49
 
@@ -52,7 +51,7 @@ Requires-Dist: numpy <2,>=1 ; extra == 'test'
52
51
  [![CI](https://github.com/gerlero/foamlib/actions/workflows/ci.yml/badge.svg)](https://github.com/gerlero/foamlib/actions/workflows/ci.yml)
53
52
  [![Codecov](https://codecov.io/gh/gerlero/foamlib/branch/main/graph/badge.svg)](https://codecov.io/gh/gerlero/foamlib)
54
53
  [![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
55
- [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
54
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
56
55
  [![PyPI](https://img.shields.io/pypi/v/foamlib)](https://pypi.org/project/foamlib/)
57
56
  [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/foamlib)](https://pypi.org/project/foamlib/)
58
57
  [![Docker image](https://img.shields.io/badge/docker%20image-gerlero%2Ffoamlib-informational)](https://hub.docker.com/r/gerlero/foamlib/)
@@ -0,0 +1,14 @@
1
+ foamlib/__init__.py,sha256=ncl1G6iN85s3zP7aVBqzekY5wHCoOn8dpJxXW2e36vI,287
2
+ foamlib/_cases.py,sha256=SbMaaKdhYbgmgdxWZNB7j47P04QxZ3VVq4sP9HbTLpA,21422
3
+ foamlib/_util.py,sha256=ICs_Bc2jXpxzOUos6Cnl0blUwz1P6r1f1swP8k9Bex0,2347
4
+ foamlib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ foamlib/_dictionaries/__init__.py,sha256=6UWBGe1t7cq-d6WWQrVm0Xpi7Whpkr-mkTWgAM4NwcE,160
6
+ foamlib/_dictionaries/_base.py,sha256=0Qic347JzJBMgBc0gHfuAGmQMWYGEn7IfJ9vKd4pm_I,1606
7
+ foamlib/_dictionaries/_files.py,sha256=Qyw04I5hqGRkHR7KWGmMdX6LyVtat1zKf50bo7CRIoU,12626
8
+ foamlib/_dictionaries/_parsing.py,sha256=w7AOyoPPghsG06WK_1fXU-udU_F8J_zuvV9eIf07P8M,4905
9
+ foamlib/_dictionaries/_serialization.py,sha256=8YInaQ0HnlDe4RnwocvTlJJkVFR7XDqGsuN4ABAyUCE,3452
10
+ foamlib-0.2.5.dist-info/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
11
+ foamlib-0.2.5.dist-info/METADATA,sha256=PuzWIZKasSyaUKpO0H_g67r6wqLyswQyOzzelaiHLpQ,4650
12
+ foamlib-0.2.5.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
13
+ foamlib-0.2.5.dist-info/top_level.txt,sha256=ZdVYtetXGwPwyfL-WhlhbTFQGAwKX5P_gXxtH9JYFPI,8
14
+ foamlib-0.2.5.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- foamlib/__init__.py,sha256=BPC3la1UvhtGOS7utfBE5tccqz8mxqzd7Fn0zFC5yz0,287
2
- foamlib/_cases.py,sha256=4f3c5BXnsHPhFvgXNjUcGGHyu7I0WZT6zxlvGhb9kMY,21213
3
- foamlib/_subprocesses.py,sha256=5vqdQvpN_2v4GgDqxi-s88NGhZ6doFxkh0XY89ZWuHA,1926
4
- foamlib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- foamlib/_dictionaries/__init__.py,sha256=6UWBGe1t7cq-d6WWQrVm0Xpi7Whpkr-mkTWgAM4NwcE,160
6
- foamlib/_dictionaries/_base.py,sha256=H8XfiaX1LD6OWwZ9m61SaKgI-_szF1udyEfiLurrCB8,1493
7
- foamlib/_dictionaries/_files.py,sha256=1Ve1FG2VVKLyj6yZGe4Vy8EhEOtyORQtJMUK-cbPNt4,12424
8
- foamlib/_dictionaries/_parsing.py,sha256=65kwMU6b4WmMngOR5ED8IBvMa59FQqTRmd9o0xPnWJM,4768
9
- foamlib/_dictionaries/_serialization.py,sha256=viHpQKggSBfxq9V6veVcCCLNq7wdJ-2g5maecaN2beU,3612
10
- foamlib-0.2.4.dist-info/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
11
- foamlib-0.2.4.dist-info/METADATA,sha256=Z5aFcGYwPssHy9DTrQqZ4Lsw6cJ1QjW9UFiqe0Uuf58,4640
12
- foamlib-0.2.4.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
13
- foamlib-0.2.4.dist-info/top_level.txt,sha256=ZdVYtetXGwPwyfL-WhlhbTFQGAwKX5P_gXxtH9JYFPI,8
14
- foamlib-0.2.4.dist-info/RECORD,,