foamlib 0.3.8__py3-none-any.whl → 0.3.10__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.3.8"
3
+ __version__ = "0.3.10"
4
4
 
5
5
  from ._cases import AsyncFoamCase, FoamCase, FoamCaseBase
6
6
  from ._files import FoamDict, FoamFieldFile, FoamFile
foamlib/_cases.py CHANGED
@@ -56,23 +56,29 @@ class FoamCaseBase(Sequence["FoamCaseBase.TimeDirectory"]):
56
56
  return self.path.name
57
57
 
58
58
  def __getitem__(self, key: str) -> FoamFieldFile:
59
- try:
59
+ if (self.path / key).is_file():
60
60
  return FoamFieldFile(self.path / key)
61
- except FileNotFoundError as e:
62
- raise KeyError(key) from e
61
+ elif (self.path / f"{key}.gz").is_file():
62
+ return FoamFieldFile(self.path / f"{key}.gz")
63
+ else:
64
+ raise KeyError(key)
63
65
 
64
66
  def __contains__(self, obj: object) -> bool:
65
67
  if isinstance(obj, FoamFieldFile):
66
68
  return obj.path.parent == self.path
67
69
  elif isinstance(obj, str):
68
- return (self.path / obj).is_file()
70
+ return (self.path / obj).is_file() or (
71
+ self.path / f"{obj}.gz"
72
+ ).is_file()
69
73
  else:
70
74
  return False
71
75
 
72
76
  def __iter__(self) -> Iterator[FoamFieldFile]:
73
77
  for p in self.path.iterdir():
74
- if p.is_file():
75
- yield FoamFieldFile(p.name)
78
+ if p.is_file() and (
79
+ p.suffix != ".gz" or not p.with_suffix("").is_file()
80
+ ):
81
+ yield FoamFieldFile(p)
76
82
 
77
83
  def __len__(self) -> int:
78
84
  return len(list(iter(self)))
@@ -114,7 +120,7 @@ class FoamCaseBase(Sequence["FoamCaseBase.TimeDirectory"]):
114
120
  self, index: Union[int, slice, float, str]
115
121
  ) -> Union["FoamCaseBase.TimeDirectory", Sequence["FoamCaseBase.TimeDirectory"]]:
116
122
  if isinstance(index, str):
117
- return FoamCaseBase.TimeDirectory(self.path / str(index))
123
+ return FoamCaseBase.TimeDirectory(self.path / index)
118
124
  elif isinstance(index, float):
119
125
  for time in self._times:
120
126
  if time.time == index:
foamlib/_files/_io.py CHANGED
@@ -1,3 +1,4 @@
1
+ import gzip
1
2
  import sys
2
3
  from copy import deepcopy
3
4
  from pathlib import Path
@@ -47,6 +48,10 @@ class FoamFileIO:
47
48
  def _read(self) -> Tuple[bytes, Parsed]:
48
49
  if not self.__defer_io:
49
50
  contents = self.path.read_bytes()
51
+
52
+ if self.path.suffix == ".gz":
53
+ contents = gzip.decompress(contents)
54
+
50
55
  if contents != self.__contents:
51
56
  self.__contents = contents
52
57
  self.__parsed = None
@@ -63,6 +68,9 @@ class FoamFileIO:
63
68
  self.__contents = contents
64
69
  self.__parsed = None
65
70
  if not self.__defer_io:
71
+ if self.path.suffix == ".gz":
72
+ contents = gzip.compress(contents)
73
+
66
74
  self.path.write_bytes(contents)
67
75
  self.__dirty = False
68
76
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: foamlib
3
- Version: 0.3.8
3
+ Version: 0.3.10
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
@@ -28,22 +28,28 @@ License-File: LICENSE.txt
28
28
  Requires-Dist: aioshutil <2,>=1
29
29
  Requires-Dist: pyparsing <4,>=3
30
30
  Requires-Dist: typing-extensions <5,>=4 ; python_version < "3.11"
31
+ Provides-Extra: dev
32
+ Requires-Dist: foamlib[numpy] ; extra == 'dev'
33
+ Requires-Dist: foamlib[lint] ; extra == 'dev'
34
+ Requires-Dist: foamlib[test] ; extra == 'dev'
35
+ Requires-Dist: foamlib[typing] ; extra == 'dev'
36
+ Requires-Dist: foamlib[docs] ; extra == 'dev'
31
37
  Provides-Extra: docs
38
+ Requires-Dist: foamlib[numpy] ; extra == 'docs'
32
39
  Requires-Dist: sphinx <8,>=7 ; extra == 'docs'
33
40
  Requires-Dist: sphinx-rtd-theme ; extra == 'docs'
34
- Requires-Dist: numpy <2,>=1 ; extra == 'docs'
35
41
  Provides-Extra: lint
36
42
  Requires-Dist: ruff ; extra == 'lint'
43
+ Provides-Extra: numpy
44
+ Requires-Dist: numpy <2,>=1 ; extra == 'numpy'
37
45
  Provides-Extra: test
46
+ Requires-Dist: foamlib[numpy] ; extra == 'test'
38
47
  Requires-Dist: pytest <9,>=7 ; extra == 'test'
39
48
  Requires-Dist: pytest-asyncio <0.24,>=0.21 ; extra == 'test'
40
49
  Requires-Dist: pytest-cov ; extra == 'test'
41
- Requires-Dist: numpy <2,>=1 ; extra == 'test'
42
50
  Provides-Extra: typing
51
+ Requires-Dist: foamlib[test] ; extra == 'typing'
43
52
  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'
47
53
 
48
54
  [<img alt="foamlib" src="https://github.com/gerlero/foamlib/raw/main/logo.png" height="50">](https://github.com/gerlero/foamlib)
49
55
 
@@ -0,0 +1,15 @@
1
+ foamlib/__init__.py,sha256=OJLrmY7uGGxH91O7KRnS7BR1s254VtAqPYaVzI2CikA,432
2
+ foamlib/_cases.py,sha256=4b9CCDAuKi5Dp8DUksIbaMsp0Yi0xv5QeZLVAUrKRh8,21417
3
+ foamlib/_util.py,sha256=vL03aAzpWdZyYIhe2WTxHiz9b4lnttVnRuzqUmZvXXk,3047
4
+ foamlib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ foamlib/_files/__init__.py,sha256=vDkPj8u8bX_I_m2YfeKvXBgwg8D1ufyFCfHGHKN3JPQ,140
6
+ foamlib/_files/_base.py,sha256=YA5a-i5HZuA3JslCD6r-DwZzpSA8r42dqSXef286Ako,2050
7
+ foamlib/_files/_files.py,sha256=4rZb3HMJADmJBGmRpChiujJNX1UIxhgHI5YPEmEOWvE,10784
8
+ foamlib/_files/_io.py,sha256=pGYMoLI5Dz2Y90EB1CtklZiffpDTGuQbbbkyqRe0JAo,2115
9
+ foamlib/_files/_parsing.py,sha256=sWUeF9xiM6AriQjljl3jEpvoFRMmaS1h3bT3b0oor3U,7279
10
+ foamlib/_files/_serialization.py,sha256=rmZW42Pyn1DIJbGMZqFG_lZ5DcLhPmfUgH24qsu2rIk,3400
11
+ foamlib-0.3.10.dist-info/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
12
+ foamlib-0.3.10.dist-info/METADATA,sha256=tmwwFbw9VKAIMBeJ-W8nP6iEfKXFxIRYmW57yDVvyLc,5458
13
+ foamlib-0.3.10.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
14
+ foamlib-0.3.10.dist-info/top_level.txt,sha256=ZdVYtetXGwPwyfL-WhlhbTFQGAwKX5P_gXxtH9JYFPI,8
15
+ foamlib-0.3.10.dist-info/RECORD,,
@@ -1,15 +0,0 @@
1
- foamlib/__init__.py,sha256=4Iybtfu_RUem_6XkwHEYhTShzrq7Zb2IiBhP-Vv7FeA,431
2
- foamlib/_cases.py,sha256=vq30uymy0lcYvkdEj_v94YuRMqUhgnw_mGxSCgNbdFU,21142
3
- foamlib/_util.py,sha256=vL03aAzpWdZyYIhe2WTxHiz9b4lnttVnRuzqUmZvXXk,3047
4
- foamlib/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- foamlib/_files/__init__.py,sha256=vDkPj8u8bX_I_m2YfeKvXBgwg8D1ufyFCfHGHKN3JPQ,140
6
- foamlib/_files/_base.py,sha256=YA5a-i5HZuA3JslCD6r-DwZzpSA8r42dqSXef286Ako,2050
7
- foamlib/_files/_files.py,sha256=4rZb3HMJADmJBGmRpChiujJNX1UIxhgHI5YPEmEOWvE,10784
8
- foamlib/_files/_io.py,sha256=1GO9jKXoJc45_GfrneCNlR1nSnT8HqYDY4VsRFdHwEQ,1912
9
- foamlib/_files/_parsing.py,sha256=sWUeF9xiM6AriQjljl3jEpvoFRMmaS1h3bT3b0oor3U,7279
10
- foamlib/_files/_serialization.py,sha256=rmZW42Pyn1DIJbGMZqFG_lZ5DcLhPmfUgH24qsu2rIk,3400
11
- foamlib-0.3.8.dist-info/LICENSE.txt,sha256=5Dte9TUnLZzPRs4NQzl-Jc2-Ljd-t_v0ZR5Ng5r0UsY,35131
12
- foamlib-0.3.8.dist-info/METADATA,sha256=m-CbGI_cHcps-ZkkyspgchzDnv3Zk9ML9hANZN2coIY,5242
13
- foamlib-0.3.8.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
14
- foamlib-0.3.8.dist-info/top_level.txt,sha256=ZdVYtetXGwPwyfL-WhlhbTFQGAwKX5P_gXxtH9JYFPI,8
15
- foamlib-0.3.8.dist-info/RECORD,,