Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test_unpinned_deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ jobs:

- name: Install package with dev deps
run: |
uv pip install -e .[dev]
uv pip install .[dev]
uv pip freeze

- name: Pytest
run: |
uv run python -m pytest
uv run --no-project python -m pytest
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion src/pyphreeqc/interface.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 11 additions & 5 deletions tests/test_phreeqc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading