Skip to content

Commit

Permalink
Merge commit '3212850763f535959cd009b767771d8d56da6c55'
Browse files Browse the repository at this point in the history
  • Loading branch information
Darth Vader committed Jul 30, 2024
2 parents 7c0d404 + 3212850 commit 2ff804e
Show file tree
Hide file tree
Showing 21 changed files with 342 additions and 174 deletions.
169 changes: 78 additions & 91 deletions src/phast/PhreeqcRM/.github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -1,114 +1,101 @@
name: wheels

on:
pull_request:
branches:
- master
push:
branches:
- master
workflow_dispatch:
release:
types:
- published

env:
FORCE_COLOR: 3
YAML_CPP_REF: b8882652fcbeba4c00dec019a39da91e702e474e
USE_LIB_CMAKE_YAML_CPP: ${{ true }}
on: [push, pull_request]

jobs:
build:
name: ${{ matrix.os }} (python ${{ matrix.python-version }})

build_wheels:
name: ${{ matrix.python[0] }}(${{ matrix.buildplat[2] }}) on ${{ matrix.buildplat[0] }}
runs-on: ${{ matrix.buildplat[0] }}
strategy:
fail-fast: false
matrix:
os: [macos-12, macos-13, ubuntu-20.04, ubuntu-22.04, windows-2019, windows-2022]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

runs-on: ${{ matrix.os }}
buildplat:
- [macos-13, macosx_x86_64, x86_64]
- [macos-14, macosx_arm64, arm64]
- [ubuntu-20.04, manylinux_x86_64, x86_64]
- [ubuntu-20.04, manylinux_i686, i686]
- [windows-2019, win_amd64, x64]
- [windows-2019, win32, Win32]
python:
- [cp38, v141]
- [cp39, v141]
- [cp310, v141]
- [cp311, v141]
- [cp312, v142]
- [cp313, v142]
exclude:
- buildplat: [windows-2019, win_amd64, x64]
python: [cp313, v142]
- buildplat: [windows-2019, win32, Win32]
python: [cp313, v142]

steps:
- uses: actions/checkout@v4
with:
path: phreeqcrm-source

- uses: actions/checkout@v4
# Used to host cibuildwheel
- uses: actions/setup-python@v5
with:
repository: jbeder/yaml-cpp
ref: ${{ env.YAML_CPP_REF }}
path: yaml-cpp-source

- name: Install ninja (Linux)
if: ${{ runner.os == 'Linux' }}
run: sudo apt-get -y install ninja-build
python-version: "3.x"

- name: Install ninja (macOS)
if: ${{ runner.os == 'macOS' }}
run: brew install ninja

- name: Set up Visual Studio shell (Windows)
if: runner.os == 'Windows'
uses: egor-tensin/vs-shell@v2
with:
arch: x64

- name: Cache yaml-cpp
id: cache-yaml-cpp
uses: actions/cache@v4
- name: Build wheels
if: ${{ runner.os != 'Windows' }}
uses: pypa/cibuildwheel@7e5a838a63ac8128d71ab2dfd99e4634dd1bca09 # v2.19.2
env:
CIBW_PRERELEASE_PYTHONS: True
CIBW_BUILD: ${{ matrix.python[0] }}-${{ matrix.buildplat[1] }}
CIBW_BUILD_VERBOSITY: 1
CIBW_TEST_REQUIRES: pytest
# CIBW_BEFORE_TEST: pwd && ls -Ral && ls -Ral {project}/swig/python
CIBW_TEST_COMMAND: "pytest {project}/swig/python"

- name: Build wheels (Windows)
if: ${{ runner.os == 'Windows' }}
uses: pypa/cibuildwheel@7e5a838a63ac8128d71ab2dfd99e4634dd1bca09 # v2.19.2
env:
CIBW_PRERELEASE_PYTHONS: True
CIBW_BUILD: ${{ matrix.python[0] }}-${{ matrix.buildplat[1] }}
CIBW_BUILD_VERBOSITY: 1
CIBW_TEST_REQUIRES: pytest
# CIBW_BEFORE_TEST: pwd && ls -Ral && ls -Ral {project}/swig/python
CIBW_TEST_COMMAND: "pytest {project}/swig/python"
CMAKE_GENERATOR: Visual Studio 16 2019
CMAKE_GENERATOR_TOOLSET: ${{ matrix.python[1] }}
CMAKE_GENERATOR_PLATFORM: ${{ matrix.buildplat[2] }}

- uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
with:
path: ${{ github.workspace }}/yaml-cpp-install
key: ${{ matrix.os }}-yaml-cpp-${{ env.YAML_CPP_REF }}
name: dist-${{ matrix.python[0] }}-${{ matrix.buildplat[1] }}
path: ./wheelhouse/*.whl

- name: Configure yaml-cpp
if: steps.cache-yaml-cpp.outputs.cache-hit != 'true'
run: cmake -G "Ninja Multi-Config" -B yaml-cpp-build -S yaml-cpp-source -DYAML_CPP_BUILD_TOOLS:BOOL=OFF -DCMAKE_INSTALL_PREFIX:PATH=$(pwd)/yaml-cpp-install -DCMAKE_POSITION_INDEPENDENT_CODE=ON

- name: Build yaml-cpp
if: steps.cache-yaml-cpp.outputs.cache-hit != 'true'
run: cmake --build yaml-cpp-build --config Release

- name: Test yaml-cpp
if: steps.cache-yaml-cpp.outputs.cache-hit != 'true'
run: ctest --test-dir yaml-cpp-build

- name: Install yaml-cpp
if: steps.cache-yaml-cpp.outputs.cache-hit != 'true'
run: cmake --install yaml-cpp-build
build_sdist:
name: Build sdist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1
with:
python-version: ${{ matrix.python-version }}

- name: Install Python ${{ matrix.python-version }} dependencies
# Build sdist on lowest supported Python
python-version: "3.8"
- name: Build sdist
run: |
python --version
python -m pip install --upgrade pip
pip install pipx
python -m pip install -U pip build
python -m build --sdist
- name: Build package (using share/cmake/yaml-cpp)
if: ${{ !env.USE_LIB_CMAKE_YAML_CPP }}
env:
yaml-cpp_DIR: ${{ github.workspace }}/yaml-cpp-install/share/cmake/yaml-cpp
working-directory: phreeqcrm-source
run: pipx run build

- name: Build package (using lib/cmake/yaml-cpp)
if: ${{ env.USE_LIB_CMAKE_YAML_CPP }}
env:
yaml-cpp_DIR: ${{ github.workspace }}/yaml-cpp-install/lib/cmake/yaml-cpp
working-directory: phreeqcrm-source
run: pipx run build

- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4
with:
name: wheels-${{ matrix.os }}-python-${{ matrix.python-version }}
path: phreeqcrm-source/dist/*.whl
name: dist-sdist
path: ./dist/*

- uses: actions/upload-artifact@v4
if: ${{ matrix.python-version == '3.10' && matrix.os == 'ubuntu-22.04' }}

merge_wheels:
name: Merge wheels into a combined artifact
runs-on: ubuntu-latest
needs: [build_wheels, build_sdist]
steps:
- name: Merge Artifacts
uses: actions/upload-artifact/merge@v4
with:
name: source
path: phreeqcrm-source/dist/*.tar.gz
name: dist
pattern: dist-*
38 changes: 36 additions & 2 deletions src/phast/PhreeqcRM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ project(
LANGUAGES CXX C
)

if(DEFINED SKBUILD)
include(CheckPIESupported)
check_pie_supported()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

# check if this is the root project
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(STANDALONE_BUILD 1)
Expand All @@ -33,11 +39,29 @@ if(PHREEQCRM_FORTRAN_TESTING)
enable_language(Fortran)
endif()

if(DEFINED SKBUILD)
# SKBUILD is defined when scikit-build-core is used to build python wheels (see pyproject.toml)

# Include FetchContent module
include(FetchContent)

# Fetch yaml-cpp
FetchContent_Declare(
yaml-cpp
GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
GIT_TAG yaml-cpp-0.7.0
)

# Make yaml-cpp available
FetchContent_MakeAvailable(yaml-cpp)
endif()

option(PHREEQCRM_WITH_YAML_CPP "Build with yaml-cpp support" OFF)
if(DEFINED SKBUILD)
# SKBUILD is defined when scikit-build-core is used to build python wheels (see pyproject.toml)
set(PHREEQCRM_WITH_YAML_CPP ON)
endif()
if(PHREEQCRM_WITH_YAML_CPP)
if(PHREEQCRM_WITH_YAML_CPP AND NOT DEFINED SKBUILD)
find_package(yaml-cpp REQUIRED)
if(yaml-cpp_FOUND)
message(STATUS "Found yaml-cpp: TRUE (found version \"${yaml-cpp_VERSION}\")")
Expand All @@ -60,14 +84,16 @@ endif()

option(PHREEQCRM_BUILD_PYTHON "Build python wrapper using SWIG" OFF)
if(DEFINED SKBUILD)
# SKBUILD is defined when scikit-build-core is used to build python wheels (see pyproject.toml)
set(PHREEQCRM_BUILD_PYTHON ON)
endif()
if(PHREEQCRM_BUILD_PYTHON)
if(NOT PHREEQCRM_WITH_YAML_CPP)
message(FATAL_ERROR "Building python wrapper requires PHREEQCRM_WITH_YAML_CPP.")
endif()
find_package(SWIG REQUIRED)
find_package(Python 3.8 REQUIRED COMPONENTS Interpreter Development Development.Module NumPy)
###find_package(Python 3.8 REQUIRED COMPONENTS Interpreter Development Development.Module NumPy)
find_package(Python COMPONENTS Interpreter Development.Module NumPy REQUIRED)
# Set Python_ROOT_DIR to specify which python to use
# ie -DPython_ROOT_DIR=C:/Python38-x64
endif()
Expand Down Expand Up @@ -318,6 +344,11 @@ if(PHREEQCRM_WITH_YAML_CPP AND yaml-cpp_FOUND)
# set(phreeqcrm_requires "yaml-cpp")
set(useyaml_define "-DUSE_YAML")
endif()
if(DEFINED SKBUILD)
# SKBUILD is defined when scikit-build-core is used to build python wheels (see pyproject.toml)
target_compile_definitions(PhreeqcRM PUBLIC USE_YAML)
target_link_libraries(PhreeqcRM PUBLIC yaml-cpp)
endif()

# check for zlib
if(NOT ZLIB_ROOT)
Expand Down Expand Up @@ -455,6 +486,7 @@ configure_file(phreeqcrm.cmake.in phreeqcrm.pc @ONLY)

# install
if(STANDALONE_BUILD EQUAL 1 AND NOT DEFINED SKBUILD)
# SKBUILD is defined when scikit-build-core is used to build python wheels (see pyproject.toml)

include(CMakePackageConfigHelpers)

Expand Down Expand Up @@ -546,6 +578,7 @@ if(STANDALONE_BUILD EQUAL 1)

# subdirs
if(NOT DEFINED SKBUILD)
# SKBUILD is defined when scikit-build-core is used to build python wheels (see pyproject.toml)
add_subdirectory(database)
add_subdirectory(doc)
add_subdirectory(Doxygen)
Expand All @@ -563,6 +596,7 @@ if(MSVC)
endif()

if(DEFINED SKBUILD)
# SKBUILD is defined when scikit-build-core is used to build python wheels (see pyproject.toml)
message(STATUS "SKBUILD IS defined")
#set_target_properties(PhreeqcRM TestRM TestBMIdtor TestRMdtor PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1)
set_target_properties(PhreeqcRM PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1)
Expand Down
2 changes: 2 additions & 0 deletions src/phast/PhreeqcRM/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ PHREEQCRM_EXTRA_DIST=\
swig/python/AdvectBMI_py.py\
swig/python/BMIPhreeqcRM_docstrings.swg\
swig/python/CMakeLists.txt\
swig/python/conftest.py\
swig/python/constants.py\
swig/python/PhreeqcRM_docstrings.swg\
swig/python/SimpleAdvect.py\
swig/python/test_basic.py\
Expand Down
19 changes: 19 additions & 0 deletions src/phast/PhreeqcRM/pybind/tests/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# constants.py
class Constants:
def __init__(self):
file_directory = os.path.dirname(__file__)
self._yaml = os.path.join(file_directory, 'AdvectBMI_py.yaml')
self._database = os.path.join(file_directory, 'phreeqc.dat')
self._pqi = os.path.join(file_directory, 'advect_pqi')

@property
def yaml(self):
return self._yaml

@property
def database(self):
return self._database

@property
def pqi(self):
return self._pqi
Loading

0 comments on commit 2ff804e

Please sign in to comment.