Skip to content

Commit 6b43a7e

Browse files
committed
Trying metadata version
1 parent 1b3800d commit 6b43a7e

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

dapi/__init__.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,22 @@
7878
)
7979

8080

81-
from pathlib import Path
82-
83-
8481
def _get_version():
85-
"""Read version from pyproject.toml, falling back for older Python."""
82+
"""Get package version using importlib.metadata."""
8683
try:
87-
# For Python 3.11+
88-
import tomllib
89-
except ModuleNotFoundError:
90-
# For Python < 3.11
91-
import tomli as tomllib # Use tomli and alias it as tomllib
84+
# For Python 3.8+
85+
from importlib.metadata import version
9286

93-
try:
94-
pyproject_path = Path(__file__).parent.parent / "pyproject.toml"
95-
with open(pyproject_path, "rb") as f: # tomllib expects bytes
96-
data = tomllib.load(f)
97-
return data["tool"]["poetry"]["version"]
98-
except (FileNotFoundError, KeyError, ImportError, tomllib.TOMLDecodeError):
99-
# Fallback version if pyproject.toml can't be read or parsed
87+
return version("dapi")
88+
except ImportError:
89+
# For Python < 3.8, use pkg_resources
90+
try:
91+
from pkg_resources import get_distribution
92+
93+
return get_distribution("dapi").version
94+
except Exception:
95+
return "unknown"
96+
except Exception:
10097
return "unknown"
10198

10299

examples/openfoam/openfoam-minimal.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,11 @@
655655
"# plt.plot(data.iloc[100:, 0].values, data.iloc[100:, 2].values)\n",
656656
"\n",
657657
"plt.xlabel(\"Time\")\n",
658-
"plt.ylabel(\"$C_d$\") # Using LaTeX for C_d\n",
658+
"plt.ylabel(\"$C_d$\") # Using LaTeX for C_d\n",
659659
"plt.title(\"Drag Coefficient vs Time\")\n",
660-
"plt.grid(False) # As per your original code, grid is off. Set to True if you want a grid.\n",
660+
"plt.grid(\n",
661+
" False\n",
662+
") # As per your original code, grid is off. Set to True if you want a grid.\n",
661663
"plt.show()"
662664
]
663665
},

examples/openfoam/openfoam.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,9 +1116,11 @@
11161116
"# plt.plot(data.iloc[100:, 0].values, data.iloc[100:, 2].values)\n",
11171117
"\n",
11181118
"plt.xlabel(\"Time\")\n",
1119-
"plt.ylabel(\"$C_d$\") # Using LaTeX for C_d\n",
1119+
"plt.ylabel(\"$C_d$\") # Using LaTeX for C_d\n",
11201120
"plt.title(\"Drag Coefficient vs Time\")\n",
1121-
"plt.grid(False) # As per your original code, grid is off. Set to True if you want a grid.\n",
1121+
"plt.grid(\n",
1122+
" False\n",
1123+
") # As per your original code, grid is off. Set to True if you want a grid.\n",
11221124
"plt.show()"
11231125
]
11241126
},

0 commit comments

Comments
 (0)