From 83f41e636a3b24226ce7d36acfe1ac4b371bf2b0 Mon Sep 17 00:00:00 2001 From: Vineet Bansal Date: Fri, 31 Oct 2025 12:03:39 -0400 Subject: [PATCH 1/3] packaging dbs with the wrapper --- CMakeLists.txt | 12 ++++++++++++ src/pyphreeqc/interface.py | 8 +++++++- tests/test_phreeqc.py | 16 +++++++++++----- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ee5b8d3..f936943 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,18 @@ add_subdirectory(${IPHREEQC_DIR} ${IPHREEQC_BUILD_DIR}) set_target_properties(IPhreeqc PROPERTIES POSITION_INDEPENDENT_CODE ON) # ------------------------------------------------------- +# ------------------------------------------------------- +# IPhreeqc databases +# ------------------------------------------------------- +# Till we find a way to extract artifacts from IPhreeqc's install folder +# through scikit-build-core, we define a COMPONENT that allows us to +# copy the database files. +set(IPHREEQC_DATABASE_DIR ${IPHREEQC_BASE}/database) +install(DIRECTORY + "${IPHREEQC_DATABASE_DIR}" + DESTINATION pyphreeqc COMPONENT iphreeqc_database) +# ------------------------------------------------------- + include_directories(${IPHREEQC_INCLUDE_DIRS}) pybind11_add_module(_bindings src/bindings.cpp) diff --git a/src/pyphreeqc/interface.py b/src/pyphreeqc/interface.py index 5a741f2..bec1286 100644 --- a/src/pyphreeqc/interface.py +++ b/src/pyphreeqc/interface.py @@ -1,4 +1,5 @@ from typing import Any +from pathlib import Path from pyphreeqc._bindings import PyVar, PY_VAR_TYPE, PY_VRESULT, PyIPhreeqc IPhreeqc = PyIPhreeqc @@ -52,8 +53,13 @@ def value(self, value) -> None: class Phreeqc: - def __init__(self): + def __init__(self, database: str = "phreeqc.dat", database_directory: Path | None = None): self._ext = PyIPhreeqc() + + if database_directory is None: + database_directory = Path(__file__).parent / "database" + self._ext.load_database(str(database_directory / database)) + # TODO: Is VAR the common denominator for most operations? # Here we create one and modify it in operations instead of having # the caller create new VARs per operation. diff --git a/tests/test_phreeqc.py b/tests/test_phreeqc.py index 0ab9ecd..057c61e 100644 --- a/tests/test_phreeqc.py +++ b/tests/test_phreeqc.py @@ -3,15 +3,21 @@ from pyphreeqc.interface import Phreeqc -def test_load_database(): - phreeqc = Phreeqc() - phreeqc.load_database(str(Path(__file__).parent / "phreeqc.dat")) +def test_load_database_internal(): + # `phreeqc.dat` is included with the package, so we don't need to specify + # `database_directory`. + phreeqc = Phreeqc(database="phreeqc.dat") + + +def test_load_database_external(): + # We can always load an external database by specifying + # `database_directory`. + phreeqc = Phreeqc(database="phreeqc.dat", database_directory=Path(__file__).parent) def test_run(): # TODO: Break this down into individual tests - phreeqc = Phreeqc() - phreeqc.load_database(str(Path(__file__).parent / "phreeqc.dat")) + phreeqc = Phreeqc("phreeqc.dat") phreeqc.run_string(""" TITLE Example 11.--Transport and ion exchange. From 0bc9a8274931dc03a7da1aaa97ef3753e013d1ca Mon Sep 17 00:00:00 2001 From: Vineet Bansal Date: Fri, 31 Oct 2025 12:04:28 -0400 Subject: [PATCH 2/3] installing in regular mode, not dev --- .github/workflows/test_unpinned_deps.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_unpinned_deps.yml b/.github/workflows/test_unpinned_deps.yml index 25f9c2a..4c212e6 100644 --- a/.github/workflows/test_unpinned_deps.yml +++ b/.github/workflows/test_unpinned_deps.yml @@ -30,7 +30,7 @@ jobs: - name: Install package with dev deps run: | - uv pip install -e .[dev] + uv pip install .[dev] uv pip freeze - name: Pytest From e06a21a31376b54d3eaa76771767f2c5a5b1aad3 Mon Sep 17 00:00:00 2001 From: Vineet Bansal Date: Fri, 31 Oct 2025 14:06:00 -0400 Subject: [PATCH 3/3] no-project for uv run --- .github/workflows/test_unpinned_deps.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_unpinned_deps.yml b/.github/workflows/test_unpinned_deps.yml index 4c212e6..4013efa 100644 --- a/.github/workflows/test_unpinned_deps.yml +++ b/.github/workflows/test_unpinned_deps.yml @@ -35,4 +35,4 @@ jobs: - name: Pytest run: | - uv run python -m pytest + uv run --no-project python -m pytest