Skip to content

Commit

Permalink
Use RavenHydroFramework from official GitHub source (#24)
Browse files Browse the repository at this point in the history
### What kind of change does this PR introduce?

* Points the `RavenHydroFramework` source files to the official GitHub project
* Updates the version of Raven to 3.8
* Updates the CMake configuration to use git-based clones
* Both the version number and the description are now dynamic (using `hatch-fancy-pypi-readme` and `setuptools_scm`).
* Support has been extended to Python3.12
* Now uses `scikit-build-core`>=0.8.0

### Does this PR introduce a breaking change?

Yes. The copied source files have been removed. There is more integration with the actual project source files.
  • Loading branch information
Zeitsperre authored Mar 5, 2024
2 parents aadcbea + a6ae9f4 commit ff59414
Show file tree
Hide file tree
Showing 194 changed files with 196 additions and 82,141 deletions.
46 changes: 31 additions & 15 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,21 @@ on:
- main
pull_request:

concurrency:
# For a given workflow, if we push to the same branch, cancel all previous builds on that branch except on main.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
black:
name: Code linting
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
steps:
- name: Cancel previous runs
uses: styfle/cancel-workflow-action@0.11.0
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Install pre-commit
run: |
pip install pre-commit
- name: Run linting suite
run: |
pre-commit run --all-files
python-version: "3.x"
- uses: pre-commit/action@v3.0.1

build:
name: Python${{ matrix.python-version }} (${{ matrix.os }}, conda=${{ matrix.conda }}, args=${{ matrix.install_args }})
Expand All @@ -36,7 +29,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: ["ubuntu-latest", "macos-latest"]
conda: [false]
install_args: [""]
Expand All @@ -60,11 +53,17 @@ jobs:
os: ubuntu-latest
conda: false
install_args: "-Ccmake.define.USE_NETCDF=false"
- python-version: "3.12"
os: ubuntu-latest
conda: true
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: true
- name: Set up Python${{ matrix.python-version }}
if: ${{ !matrix.conda }}
id: pyinstalled
Expand Down Expand Up @@ -101,18 +100,35 @@ jobs:
if: ${{ !matrix.conda }}
run: |
${{ steps.pyinstalled.outputs.python-path }} -m pip install --editable . ${{ matrix.install_args }}
- name: Check versions
if: ${{ !matrix.conda }}
run: |
${{ steps.pyinstalled.outputs.python-path }} -m pip list
${{ steps.pyinstalled.outputs.python-path }} -m pip check || true
- name: Test raven-hydro
if: ${{ !matrix.conda }}
run: |
${{ steps.pyinstalled.outputs.python-path }} -c "import raven_hydro; print(f'Description: {raven_hydro.__doc__}')"
${{ steps.pyinstalled.outputs.python-path }} -c "import raven_hydro; print(f'Built with netcdf: {raven_hydro.__netcdf__}')"
${{ steps.pyinstalled.outputs.python-path }} -c "import raven_hydro; print(f'RavenHydroFramework version: {raven_hydro.__raven_version__}')"
${{ steps.pyinstalled.outputs.python-path }} -c "import raven_hydro; print(f'raven_hydro version: {raven_hydro.__version__}')"
- name: Install raven-hydro (conda)
if: ${{ matrix.conda }}
run: |
python -m pip install --editable . ${{ matrix.install_args }}
- name: Check versions
if: ${{ matrix.conda }}
run: |
micromamba list
python -m pip list
python -m pip check || true
- name: Test raven-hydro (conda)
if: ${{ matrix.conda }}
run: |
python -c "import raven_hydro; print(f'Description: {raven_hydro.__doc__}')"
python -c "import raven_hydro; print(f'Built with netcdf: {raven_hydro.__netcdf__}')"
python -c "import raven_hydro; print(f'RavenHydroFramework version: {raven_hydro.__raven_version__}')"
python -c "import raven_hydro; print(f'raven_hydro version: {raven_hydro.__version__}')"
- name: Test raven
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
shell: bash -l {0}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python3
if: ${{ matrix.os != 'windows-latest' }}
id: pyinstalled
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tag-testpypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
shell: bash -l {0}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python3
if: ${{ matrix.os != 'windows-latest' }}
id: pyinstalled
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# raven-hydro-specific
src/raven_hydro/_version.py

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -157,4 +160,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "RavenHydroFramework"]
path = RavenHydroFramework
url = https://github.com/CSHS-CWRA/RavenHydroFramework
26 changes: 15 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,34 @@ repos:
rev: v4.5.0
hooks:
- id: trailing-whitespace
exclude: 'build/_deps/raven-src'
exclude: 'RavenHydroFramework'
- id: end-of-file-fixer
exclude: 'build/_deps/raven-src'
exclude: 'RavenHydroFramework'
- id: check-toml
- repo: https://github.com/pappasam/toml-sort
rev: v0.23.1
hooks:
- id: toml-sort-fix
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.33.0
rev: v1.35.1
hooks:
- id: yamllint
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.1.1
rev: 24.2.0
hooks:
- id: black
- repo: https://github.com/Takishima/cmake-pre-commit-hooks
rev: v1.9.5
# - repo: https://github.com/Takishima/cmake-pre-commit-hooks
# rev: v1.9.5
# hooks:
# - id: clang-format
# args: [ '-i' ]
# exclude: 'RavenHydroFramework'
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.2
hooks:
- id: clang-format
args: [ '-i' ]
exclude: 'build/_deps/raven-src'
- id: gitleaks
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.4
rev: 0.28.0
hooks:
- id: check-github-workflows
- repo: meta
Expand All @@ -45,6 +49,6 @@ ci:
autofix_prs: true
autoupdate_branch: ''
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
autoupdate_schedule: monthly
autoupdate_schedule: quarterly
skip: [ ]
submodules: false
13 changes: 13 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changes

## 0.3.0 (2024--soon)

* Updated the `RavenHydroFramework` to v3.8.
* `raven-hydro` now builds `RavenHydroFramework` directly from the GitHub official source code base.
* Additionally, the `raven-hydro` package now includes the `RavenHydroFramework` source code in the source distribution.
* `raven-hydro` now supports Python 3.12.
* `raven-hydro` now requires:
* `cmake` >=3.26.0
* `hatch-fancy-pypi-readme`
* `hatchling`
* `scikit-build-core` >=v0.8.0
* `setuptools_scm` >=8.0.0

## 0.2.4 (2023-08-25)

* Raven-hydro now supports `cmake` v2.37 and follows better Python discovery conventions.
Expand Down
110 changes: 66 additions & 44 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,26 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
cmake_minimum_required(VERSION 3.24...3.27)
cmake_minimum_required(VERSION 3.26)

# Set default compile options
option(COMPILE_LIB "If ON, will create a dynamic lib file (default: OFF)" OFF)
option(COMPILE_EXE "If ON, will create a executable file (default: ON)" ON)
option(PYTHON, "If ON, will create a share library for python (default: OFF)" ON)

# Add CMake module path
LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

# Set C++ standard explicitly
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Setup Raven Project
PROJECT(${SKBUILD_PROJECT_NAME} LANGUAGES CXX VERSION ${SKBUILD_PROJECT_VERSION})

SET(raven_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/_deps/raven-src)
# Set the RavenHydroFramework source code directory
SET(raven_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/RavenHydroFramework/src)

# Remove deprecation warnings for GCC
IF(CMAKE_COMPILER_IS_GNUCXX)
Expand All @@ -36,15 +50,16 @@ IF(NOT EXISTS ${raven_SOURCE_DIR} OR ${ALWAYS_DOWNLOAD})
# Define source library location
FetchContent_Declare(
raven
URL ${RAVEN_URL}
URL_HASH SHA256=${RAVEN_SHA256}
GIT_REPOSITORY ${RAVEN_GIT_REPO}
GIT_TAG ${RAVEN_GIT_TAG}
)
# Fetch remote source files without building them
FetchContent_Populate(raven)
ELSE()
message(STATUS "Sources found: ${raven_SOURCE_DIR}")
ENDIF()

# Add NetCDF support
IF(USE_NETCDF)
# Add NetCDF support flag
add_compile_options(-Dnetcdf)
Expand All @@ -55,62 +70,69 @@ IF(USE_NETCDF)
find_package(NetCDF REQUIRED)

# Find ZLib library
find_package(ZLIB REQUIRED)
find_package(ZLIB)
ENDIF()

# Add Python files
SET(PYBIND11_NEWPYTHON ON)
find_package(Python COMPONENTS REQUIRED Interpreter Development)
find_package(pybind11 CONFIG REQUIRED)
pybind11_add_module(_core MODULE src/main.cpp)
target_compile_definitions(_core PRIVATE RAVEN_VERSION_INFO=${RAVEN_VERSION} REQUIRED)
target_compile_definitions(_core PRIVATE VERSION_INFO=${PROJECT_VERSION})

# Find header & source
include_directories(${raven_SOURCE_DIR})
FILE(GLOB HEADER "${raven_SOURCE_DIR}/*.h")
FILE(GLOB SOURCE "${raven_SOURCE_DIR}/*.cpp")

# Add source files to build
add_executable(raven
${SOURCE}
${HEADER}
)
# Add Python files
if (PYTHON)
SET(PYBIND11_NEWPYTHON ON)
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
find_package(pybind11 CONFIG REQUIRED)
pybind11_add_module(libraven MODULE ${raven_SOURCE_DIR}/py/libraven.cpp)
target_include_directories(libraven PUBLIC ${raven_SOURCE_DIR})
target_compile_features(libraven PUBLIC cxx_std_11)
target_compile_definitions(libraven PUBLIC BMI_LIBRARY)
endif()

# Create executable; File extension is OS dependent (Linux: none, Windows: .exe)
IF(COMPILE_EXE)
add_executable(raven
${HEADER}
${SOURCE}
)
target_include_directories(raven PUBLIC ${raven_SOURCE_DIR})

# FIXME: The issue is that one of these flags determines which files are included in the build, See RavenMain.cpp
# Add flag to indicate which version of ExitGracefully to use (set in RavenMain.cpp)
target_compile_definitions(raven PUBLIC STANDALONE)
# target_compile_definitions(raven PUBLIC BMI_LIBRARY)
set_target_properties(raven PROPERTIES LINKER_LANGUAGE CXX)
ENDIF()

# Add source files
source_group("Header Files" FILES ${HEADER})
source_group("Source Files" FILES ${SOURCE})

# Link Anaconda environment libraries if available, otherwise use system libraries
# if(NOT "${CONDA_LIBRARY_PATH}" STREQUAL "")
# include_directories(${CONDA_LIBRARY_PATH})
# else()
# include_directories(${NetCDF_INCLUDE_DIRS})
# endif()

IF(USE_NETCDF)
# Link relevant NetCDF libraries to build
include_directories(${NetCDF_INCLUDE_DIRS})
target_link_libraries(raven PUBLIC ${NetCDF_LIBRARIES})
IF(PYTHON)
target_link_libraries(libraven PUBLIC ${NetCDF_LIBRARIES})
ENDIF()
IF(COMPILE_EXE)
target_link_libraries(raven PUBLIC ${NetCDF_LIBRARIES})
ENDIF()
ENDIF()

target_compile_features(raven PUBLIC cxx_std_11)
set_target_properties(raven PROPERTIES LINKER_LANGUAGE CXX)

# Install library to environment Python /lib
INSTALL(TARGETS _core LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME})
INSTALL(TARGETS libraven LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME})

# Install binary to environment /bin
IF(WIN32)
install(TARGETS raven DESTINATION ${SKBUILD_SCRIPTS_DIR})
ELSE()
add_custom_command(
TARGET raven POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_BINARY_DIR}/raven
${SKBUILD_SCRIPTS_DIR}/raven)
IF(COMPILE_EXE)
IF(WIN32)
INSTALL(TARGETS raven DESTINATION ${SKBUILD_SCRIPTS_DIR})
ELSE()
add_custom_command(
TARGET raven POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/raven ${SKBUILD_SCRIPTS_DIR}/raven)
ENDIF()
ENDIF()

# Add License for Raven after building library
add_custom_command(
TARGET raven POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${raven_SOURCE_DIR}/LICENSE
${SKBUILD_SCRIPTS_DIR}/raven_COPYING)
# Unset CMake variables to avoid polluting the cache
unset(COMPILE_LIB CACHE)
unset(COMPILE_EXE CACHE)
1 change: 1 addition & 0 deletions RavenHydroFramework
Submodule RavenHydroFramework added at 932fec
Loading

0 comments on commit ff59414

Please sign in to comment.