diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index e81d732..795b641 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -33,3 +33,81 @@ jobs: uses: NWChemEx/.github/.github/workflows/test_nwx_library.yaml@master with: compilers: '["gcc-14", "clang-18"]' + + test_python: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install clang-18 + run: | + sudo apt-get update -y + sudo apt-get install -y clang-18 + echo "CC=clang-18" >> $GITHUB_ENV + echo "CXX=clang++-18" >> $GITHUB_ENV + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Editable install (dev) + run: pip install -e ".[dev]" + + - name: Run C++ tests + run: cd build && ctest --output-on-failure + + - name: Run Python tests + run: pytest tests/python/ + + deploy_to_testpypi: + needs: test_python + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + cibw_build: cp312-manylinux_x86_64 + - os: macos-14 + cibw_build: cp312-macosx_arm64 + runs-on: ${{ matrix.os }} + permissions: + id-token: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set pretend version for TestPyPI (unique per workflow run) + run: | + python3 -m pip install --upgrade pip + python3 -m pip install "setuptools-scm>=8" + python3 <<'PY' + import os + + from setuptools_scm import get_version + + gh_env = os.environ.get("GITHUB_ENV") + if not gh_env: + raise SystemExit("GITHUB_ENV is not set") + + base = get_version(local_scheme="no-local-version") + rid = os.environ["GITHUB_RUN_ID"] + pretend = f"{base}.post{rid}" + with open(gh_env, "a", encoding="utf-8") as f: + f.write(f"SETUPTOOLS_SCM_PRETEND_VERSION={pretend}\n") + print(f"SETUPTOOLS_SCM_PRETEND_VERSION={pretend}") + PY + + - name: Build wheels + uses: pypa/cibuildwheel@v2.22.0 + env: + CIBW_BUILD: ${{ matrix.cibw_build }} + + - name: Publish to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: wheelhouse/ + repository-url: https://test.pypi.org/legacy/ diff --git a/.gitignore b/.gitignore index ada45bd..a4d3afe 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,8 @@ # limitations under the License. venv/ +.cache/ +.venv/ +build/ +__pycache__/ +.pytest_cache/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 80737ee..1ad90f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,47 +13,50 @@ # limitations under the License. cmake_minimum_required(VERSION 3.14) + +# Version from scikit-build-core when building wheels/sdists; plain CMake keeps 1.0.0. +# project(VERSION) accepts only numeric major.minor.patch[.tweak]; strip any PEP440 suffix. +if(DEFINED SKBUILD_PROJECT_VERSION AND NOT SKBUILD_PROJECT_VERSION STREQUAL "") + set(_wtf_version_source "${SKBUILD_PROJECT_VERSION}") +else() + set(_wtf_version_source "1.0.0") +endif() +if(_wtf_version_source MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)") + set(_wtf_cmake_version "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}") +else() + set(_wtf_cmake_version "1.0.0") +endif() + # Downloads common CMake modules used throughout NWChemEx +project(wtf VERSION "${_wtf_cmake_version}" LANGUAGES CXX) + include(cmake/get_nwx_cmake.cmake) -project(wtf VERSION "1.0.0" LANGUAGES CXX) -include(cmake/disable_in_source_builds.cmake) +include(disable_in_source_builds) set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_SCAN_FOR_MODULES OFF) # TODO: Make these into proper options set(BUILD_TESTING TRUE) set(CMAKE_BUILD_SHARED_LIBS ON) - -include(cmake/get_dependencies.cmake) +option(BUILD_PYBIND11_BINDINGS "Build Python bindings via pybind11" ON) # Define the documentation target include(nwx_cxx_api_docs) -nwx_cxx_api_docs("include" "src") +nwx_cxx_api_docs("cxx/include" "cxx/src") # Build the Library -file(GLOB_RECURSE WTF_HEADER_FILES CONFIGURE_DEPENDS include/wtf/*.hpp) -file(GLOB_RECURSE WTF_SOURCE_FILES CONFIGURE_DEPENDS src/wtf/*.cpp) -add_library(${PROJECT_NAME} ${WTF_SOURCE_FILES}) -target_link_libraries(${PROJECT_NAME}) -target_include_directories(${PROJECT_NAME} - PUBLIC - $ - $ -) - -if(${BUILD_TESTING}) - include(CTest) - get_dependencies(catch2) - include(cmake/catch2_tests_from_dir.cmake) - catch2_tests_from_dir( - "unit_test_${PROJECT_NAME}" - tests/unit_tests/wtf - ${PROJECT_NAME} - ) -endif() - -include(cmake/install_target.cmake) -install_library( +include(nwx_library) +nwx_library(${PROJECT_NAME} "cxx/include" "cxx/src") + +# Register the C++ tests +include(catch2_tests_from_dir) +catch2_tests_from_dir( + "unit_test_${PROJECT_NAME}" + "tests/cxx/unit_tests/${PROJECT_NAME}" ${PROJECT_NAME} - "${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}" ) + +# Register the Python module +include(nwx_python_module) +nwx_python_module(${PROJECT_NAME} "cxx/src") diff --git a/README.md b/README.md index 87bad22..64dca16 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,42 @@ writes their interfaces in terms of "weakly typed" objects like `Float` and `FloatBuffer`, and determination of the actual floating-point type is deferred to runtime. +## Development Setup + +### Prerequisites + +- CMake >= 3.14 +- A C++20-capable compiler +- Python >= 3.8 + +### Editable install + +Create and activate a virtual environment, then install the package in editable +(dev) mode. This builds the Python bindings and the C++ test suite: + +```bash +python3 -m venv .venv +source .venv/bin/activate +pip install -e ".[dev]" +``` + +### Running the C++ tests + +The editable install keeps its build tree in `build/` (configured via +`build-dir` in `pyproject.toml`). Run CTest directly from there: + +```bash +cd build && ctest --output-on-failure +``` + +### Running the Python tests + +With the virtual environment active: + +```bash +pytest tests/python/ +``` + ## Problem Description Full description (TODO: Add link to the documentation) diff --git a/cmake/catch2_tests_from_dir.cmake b/cmake/catch2_tests_from_dir.cmake deleted file mode 100644 index 782cfa2..0000000 --- a/cmake/catch2_tests_from_dir.cmake +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2025 NWChemEx-Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# 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. - -include_guard() - -function(catch2_tests_from_dir ctfd_target_name ctfd_dir) - file(GLOB_RECURSE ctfd_test_files CONFIGURE_DEPENDS ${ctfd_dir}/*.cpp) - - add_executable(${ctfd_target_name} ${ctfd_test_files}) - - target_link_libraries( - ${ctfd_target_name} PRIVATE Catch2::Catch2WithMain ${ARGN}) - - add_test(NAME ${ctfd_target_name} - COMMAND ${ctfd_target_name} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - ) -endfunction() diff --git a/cmake/dependencies/catch2.cmake b/cmake/dependencies/catch2.cmake deleted file mode 100644 index e78a197..0000000 --- a/cmake/dependencies/catch2.cmake +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2025 NWChemEx-Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# 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. - -include_guard() -include(FetchContent) - -FetchContent_Declare( - catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2 - GIT_TAG "v3.11.0" -) diff --git a/cmake/get_dependencies.cmake b/cmake/get_dependencies.cmake deleted file mode 100644 index f89bbec..0000000 --- a/cmake/get_dependencies.cmake +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright 2025 NWChemEx-Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# 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. - -include_guard() -include(FetchContent) - -function(get_dependencies) - foreach(depend_i ${ARGN}) - message(STATUS "Fetching dependency: ${depend_i}") - include("cmake/dependencies/${depend_i}.cmake") - endforeach() - - FetchContent_MakeAvailable(${ARGN}) -endfunction() diff --git a/cmake/get_nwx_cmake.cmake b/cmake/get_nwx_cmake.cmake index de8c4bc..1b29ea6 100644 --- a/cmake/get_nwx_cmake.cmake +++ b/cmake/get_nwx_cmake.cmake @@ -18,7 +18,7 @@ macro(get_nwx_cmake) include(FetchContent) FetchContent_Declare( nwx_cmake - GIT_REPOSITORY https://github.com/NWChemEx/NWXCMake + GIT_REPOSITORY https://github.com/ryanmrichard/NWXCMake ) FetchContent_MakeAvailable(nwx_cmake) set( diff --git a/cmake/install_target.cmake b/cmake/install_target.cmake deleted file mode 100644 index 784fed3..0000000 --- a/cmake/install_target.cmake +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright 2025 NWChemEx-Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# 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. - -include_guard() - -function(write_config_file wcf_file) - file(WRITE "${wcf_file}" "") # Erases it if it already exists - file(APPEND - "${wcf_file}" - "get_filename_component(_IL_CONFIG_DIR " - "\"\${CMAKE_CURRENT_LIST_FILE}\" PATH)\n" - ) - file(APPEND - "${wcf_file}" - "include(\"\${_IL_CONFIG_DIR}/${il_name}Targets.cmake\")\n" - ) -endfunction() - -function(install_library il_name il_header_dir) - #TODO: Get these values programmatically - set(_il_archive_dir lib) - set(_il_library_dir lib) - set(_il_runtime_dir bin) - set(_il_includes_dir include) - - # -- Install target that is a library -- - install(TARGETS ${il_name} - EXPORT ${il_name}Targets - ARCHIVE DESTINATION "${_il_archive_dir}" - LIBRARY DESTINATION "${_il_library_dir}" - RUNTIME DESTINATION "${_il_runtime_dir}" - INCLUDES DESTINATION "${_il_includes_dir}" - ) - - # -- Install CMake Config Files -- - install(EXPORT ${il_name}Targets - FILE ${il_name}Targets.cmake - NAMESPACE nwx:: - DESTINATION "${_il_library_dir}/cmake/${il_name}" - ) - - set(_il_config_file "${CMAKE_CURRENT_BINARY_DIR}/${il_name}Config.cmake") - write_config_file("${_il_config_file}") - - install(FILES "${_il_config_file}" - DESTINATION "${_il_library_dir}/cmake/${il_name}" - ) - - # -- Install Headers -- - #TODO: Assert il_header_dir isn't empty - install(DIRECTORY "${il_header_dir}" - DESTINATION "${_il_includes_dir}" - FILES_MATCHING - PATTERN "*.hpp" - PATTERN "*.h" - ) -endfunction() diff --git a/include/wtf/buffer/buffer.hpp b/cxx/include/wtf/buffer/buffer.hpp similarity index 100% rename from include/wtf/buffer/buffer.hpp rename to cxx/include/wtf/buffer/buffer.hpp diff --git a/include/wtf/buffer/buffer_view.hpp b/cxx/include/wtf/buffer/buffer_view.hpp similarity index 100% rename from include/wtf/buffer/buffer_view.hpp rename to cxx/include/wtf/buffer/buffer_view.hpp diff --git a/include/wtf/buffer/detail_/buffer_holder.hpp b/cxx/include/wtf/buffer/detail_/buffer_holder.hpp similarity index 100% rename from include/wtf/buffer/detail_/buffer_holder.hpp rename to cxx/include/wtf/buffer/detail_/buffer_holder.hpp diff --git a/include/wtf/buffer/detail_/buffer_view_holder.hpp b/cxx/include/wtf/buffer/detail_/buffer_view_holder.hpp similarity index 100% rename from include/wtf/buffer/detail_/buffer_view_holder.hpp rename to cxx/include/wtf/buffer/detail_/buffer_view_holder.hpp diff --git a/include/wtf/buffer/detail_/contiguous_model.hpp b/cxx/include/wtf/buffer/detail_/contiguous_model.hpp similarity index 100% rename from include/wtf/buffer/detail_/contiguous_model.hpp rename to cxx/include/wtf/buffer/detail_/contiguous_model.hpp diff --git a/include/wtf/buffer/detail_/contiguous_view_model.hpp b/cxx/include/wtf/buffer/detail_/contiguous_view_model.hpp similarity index 100% rename from include/wtf/buffer/detail_/contiguous_view_model.hpp rename to cxx/include/wtf/buffer/detail_/contiguous_view_model.hpp diff --git a/include/wtf/buffer/float_buffer.hpp b/cxx/include/wtf/buffer/float_buffer.hpp similarity index 100% rename from include/wtf/buffer/float_buffer.hpp rename to cxx/include/wtf/buffer/float_buffer.hpp diff --git a/include/wtf/concepts/concepts.hpp b/cxx/include/wtf/concepts/concepts.hpp similarity index 100% rename from include/wtf/concepts/concepts.hpp rename to cxx/include/wtf/concepts/concepts.hpp diff --git a/include/wtf/concepts/float_buffer.hpp b/cxx/include/wtf/concepts/float_buffer.hpp similarity index 100% rename from include/wtf/concepts/float_buffer.hpp rename to cxx/include/wtf/concepts/float_buffer.hpp diff --git a/include/wtf/concepts/floating_point.hpp b/cxx/include/wtf/concepts/floating_point.hpp similarity index 100% rename from include/wtf/concepts/floating_point.hpp rename to cxx/include/wtf/concepts/floating_point.hpp diff --git a/include/wtf/concepts/iterator.hpp b/cxx/include/wtf/concepts/iterator.hpp similarity index 100% rename from include/wtf/concepts/iterator.hpp rename to cxx/include/wtf/concepts/iterator.hpp diff --git a/include/wtf/concepts/modifiers.hpp b/cxx/include/wtf/concepts/modifiers.hpp similarity index 100% rename from include/wtf/concepts/modifiers.hpp rename to cxx/include/wtf/concepts/modifiers.hpp diff --git a/include/wtf/concepts/stream_insertion.hpp b/cxx/include/wtf/concepts/stream_insertion.hpp similarity index 100% rename from include/wtf/concepts/stream_insertion.hpp rename to cxx/include/wtf/concepts/stream_insertion.hpp diff --git a/include/wtf/concepts/wtf_float.hpp b/cxx/include/wtf/concepts/wtf_float.hpp similarity index 100% rename from include/wtf/concepts/wtf_float.hpp rename to cxx/include/wtf/concepts/wtf_float.hpp diff --git a/include/wtf/detail_/dispatcher.hpp b/cxx/include/wtf/detail_/dispatcher.hpp similarity index 100% rename from include/wtf/detail_/dispatcher.hpp rename to cxx/include/wtf/detail_/dispatcher.hpp diff --git a/include/wtf/detail_/downcaster.hpp b/cxx/include/wtf/detail_/downcaster.hpp similarity index 100% rename from include/wtf/detail_/downcaster.hpp rename to cxx/include/wtf/detail_/downcaster.hpp diff --git a/include/wtf/detail_/variant_from_tuple.hpp b/cxx/include/wtf/detail_/variant_from_tuple.hpp similarity index 100% rename from include/wtf/detail_/variant_from_tuple.hpp rename to cxx/include/wtf/detail_/variant_from_tuple.hpp diff --git a/include/wtf/forward.hpp b/cxx/include/wtf/forward.hpp similarity index 100% rename from include/wtf/forward.hpp rename to cxx/include/wtf/forward.hpp diff --git a/include/wtf/fp/detail_/float_holder.hpp b/cxx/include/wtf/fp/detail_/float_holder.hpp similarity index 100% rename from include/wtf/fp/detail_/float_holder.hpp rename to cxx/include/wtf/fp/detail_/float_holder.hpp diff --git a/include/wtf/fp/detail_/float_model.hpp b/cxx/include/wtf/fp/detail_/float_model.hpp similarity index 100% rename from include/wtf/fp/detail_/float_model.hpp rename to cxx/include/wtf/fp/detail_/float_model.hpp diff --git a/include/wtf/fp/detail_/float_view_holder.hpp b/cxx/include/wtf/fp/detail_/float_view_holder.hpp similarity index 100% rename from include/wtf/fp/detail_/float_view_holder.hpp rename to cxx/include/wtf/fp/detail_/float_view_holder.hpp diff --git a/include/wtf/fp/detail_/float_view_model.hpp b/cxx/include/wtf/fp/detail_/float_view_model.hpp similarity index 100% rename from include/wtf/fp/detail_/float_view_model.hpp rename to cxx/include/wtf/fp/detail_/float_view_model.hpp diff --git a/include/wtf/fp/float.hpp b/cxx/include/wtf/fp/float.hpp similarity index 100% rename from include/wtf/fp/float.hpp rename to cxx/include/wtf/fp/float.hpp diff --git a/include/wtf/fp/float_base.hpp b/cxx/include/wtf/fp/float_base.hpp similarity index 100% rename from include/wtf/fp/float_base.hpp rename to cxx/include/wtf/fp/float_base.hpp diff --git a/include/wtf/fp/float_view.hpp b/cxx/include/wtf/fp/float_view.hpp similarity index 100% rename from include/wtf/fp/float_view.hpp rename to cxx/include/wtf/fp/float_view.hpp diff --git a/include/wtf/fp/fp.hpp b/cxx/include/wtf/fp/fp.hpp similarity index 100% rename from include/wtf/fp/fp.hpp rename to cxx/include/wtf/fp/fp.hpp diff --git a/include/wtf/rtti/detail_/type_holder.hpp b/cxx/include/wtf/rtti/detail_/type_holder.hpp similarity index 100% rename from include/wtf/rtti/detail_/type_holder.hpp rename to cxx/include/wtf/rtti/detail_/type_holder.hpp diff --git a/include/wtf/rtti/detail_/type_model.hpp b/cxx/include/wtf/rtti/detail_/type_model.hpp similarity index 100% rename from include/wtf/rtti/detail_/type_model.hpp rename to cxx/include/wtf/rtti/detail_/type_model.hpp diff --git a/include/wtf/rtti/rtti.hpp b/cxx/include/wtf/rtti/rtti.hpp similarity index 100% rename from include/wtf/rtti/rtti.hpp rename to cxx/include/wtf/rtti/rtti.hpp diff --git a/include/wtf/rtti/type_info.hpp b/cxx/include/wtf/rtti/type_info.hpp similarity index 100% rename from include/wtf/rtti/type_info.hpp rename to cxx/include/wtf/rtti/type_info.hpp diff --git a/include/wtf/type_traits/float_traits.hpp b/cxx/include/wtf/type_traits/float_traits.hpp similarity index 100% rename from include/wtf/type_traits/float_traits.hpp rename to cxx/include/wtf/type_traits/float_traits.hpp diff --git a/include/wtf/type_traits/is_convertible.hpp b/cxx/include/wtf/type_traits/is_convertible.hpp similarity index 100% rename from include/wtf/type_traits/is_convertible.hpp rename to cxx/include/wtf/type_traits/is_convertible.hpp diff --git a/include/wtf/type_traits/is_floating_point.hpp b/cxx/include/wtf/type_traits/is_floating_point.hpp similarity index 100% rename from include/wtf/type_traits/is_floating_point.hpp rename to cxx/include/wtf/type_traits/is_floating_point.hpp diff --git a/include/wtf/type_traits/precision.hpp b/cxx/include/wtf/type_traits/precision.hpp similarity index 100% rename from include/wtf/type_traits/precision.hpp rename to cxx/include/wtf/type_traits/precision.hpp diff --git a/include/wtf/type_traits/tuple_append.hpp b/cxx/include/wtf/type_traits/tuple_append.hpp similarity index 100% rename from include/wtf/type_traits/tuple_append.hpp rename to cxx/include/wtf/type_traits/tuple_append.hpp diff --git a/include/wtf/type_traits/type_name.hpp b/cxx/include/wtf/type_traits/type_name.hpp similarity index 100% rename from include/wtf/type_traits/type_name.hpp rename to cxx/include/wtf/type_traits/type_name.hpp diff --git a/include/wtf/type_traits/type_traits.hpp b/cxx/include/wtf/type_traits/type_traits.hpp similarity index 100% rename from include/wtf/type_traits/type_traits.hpp rename to cxx/include/wtf/type_traits/type_traits.hpp diff --git a/include/wtf/types.hpp b/cxx/include/wtf/types.hpp similarity index 100% rename from include/wtf/types.hpp rename to cxx/include/wtf/types.hpp diff --git a/include/wtf/warnings.hpp b/cxx/include/wtf/warnings.hpp similarity index 100% rename from include/wtf/warnings.hpp rename to cxx/include/wtf/warnings.hpp diff --git a/include/wtf/wtf.hpp b/cxx/include/wtf/wtf.hpp similarity index 100% rename from include/wtf/wtf.hpp rename to cxx/include/wtf/wtf.hpp diff --git a/cxx/src/wtf/export_wtf.cpp b/cxx/src/wtf/export_wtf.cpp new file mode 100644 index 0000000..d37b67d --- /dev/null +++ b/cxx/src/wtf/export_wtf.cpp @@ -0,0 +1,23 @@ +/* + * Copyright 2025 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + */ + +#include "export_wtf.hpp" + +namespace wtf { + +PYBIND11_MODULE(wtf, m) { fp::export_float(m); } + +} // namespace wtf diff --git a/cxx/src/wtf/export_wtf.hpp b/cxx/src/wtf/export_wtf.hpp new file mode 100644 index 0000000..08dd4ee --- /dev/null +++ b/cxx/src/wtf/export_wtf.hpp @@ -0,0 +1,25 @@ +/* + * Copyright 2025 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + */ + +#pragma once +#include + +namespace wtf { +namespace fp { +/** @brief Exports the wtf::fp::Float class to the Python module @p m. */ +void export_float(pybind11::module_& m); +} // namespace fp +} // namespace wtf diff --git a/src/wtf/fp/detail_/float_holder.cpp b/cxx/src/wtf/fp/detail_/float_holder.cpp similarity index 100% rename from src/wtf/fp/detail_/float_holder.cpp rename to cxx/src/wtf/fp/detail_/float_holder.cpp diff --git a/cxx/src/wtf/fp/export_float.cpp b/cxx/src/wtf/fp/export_float.cpp new file mode 100644 index 0000000..34ca821 --- /dev/null +++ b/cxx/src/wtf/fp/export_float.cpp @@ -0,0 +1,28 @@ +/* + * Copyright 2025 NWChemEx-Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * 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. + */ + +#include "../export_wtf.hpp" +#include + +namespace wtf::fp { + +void export_float(pybind11::module_& m) { + pybind11::class_(m, "Float") + .def(pybind11::init()) + .def("to_string", &wtf::fp::Float::to_string); +} + +} // namespace wtf::fp diff --git a/src/wtf/fp/float.cpp b/cxx/src/wtf/fp/float.cpp similarity index 100% rename from src/wtf/fp/float.cpp rename to cxx/src/wtf/fp/float.cpp diff --git a/src/wtf/rtti/detail_/type_holder.cpp b/cxx/src/wtf/rtti/detail_/type_holder.cpp similarity index 100% rename from src/wtf/rtti/detail_/type_holder.cpp rename to cxx/src/wtf/rtti/detail_/type_holder.cpp diff --git a/src/wtf/rtti/type_info.cpp b/cxx/src/wtf/rtti/type_info.cpp similarity index 100% rename from src/wtf/rtti/type_info.cpp rename to cxx/src/wtf/rtti/type_info.cpp diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..45a0bbe --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,41 @@ +# Copyright 2026 NWChemEx-Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +[build-system] +requires = ["scikit-build-core>=0.10", "pybind11", "setuptools-scm>=8"] +build-backend = "scikit_build_core.build" + +[project] +name = "weaklytypedfloat" +dynamic = ["version"] +description = "Weakly Typed Float — a DSL for type-erased floating-point types" +license = { text = "Apache-2.0" } +requires-python = ">=3.8" + +[project.optional-dependencies] +dev = ["pytest"] + +[tool.scikit-build] +metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" +cmake.build-type = "Release" +cmake.args = ["-DBUILD_PYBIND11_BINDINGS=ON", "-DBUILD_TESTING=OFF"] +wheel.packages = [] +build-dir = "build" + +[tool.setuptools_scm] +fallback_version = "0.0.0" + +[[tool.scikit-build.overrides]] +if.state = "editable" +cmake.args = ["-DBUILD_PYBIND11_BINDINGS=ON", "-DBUILD_TESTING=ON"] diff --git a/tests/test_wtf.hpp b/tests/cxx/test_wtf.hpp similarity index 100% rename from tests/test_wtf.hpp rename to tests/cxx/test_wtf.hpp diff --git a/tests/unit_tests/wtf/buffer/buffer_view.cpp b/tests/cxx/unit_tests/wtf/buffer/buffer_view.cpp similarity index 100% rename from tests/unit_tests/wtf/buffer/buffer_view.cpp rename to tests/cxx/unit_tests/wtf/buffer/buffer_view.cpp diff --git a/tests/unit_tests/wtf/buffer/detail_/buffer_holder.cpp b/tests/cxx/unit_tests/wtf/buffer/detail_/buffer_holder.cpp similarity index 100% rename from tests/unit_tests/wtf/buffer/detail_/buffer_holder.cpp rename to tests/cxx/unit_tests/wtf/buffer/detail_/buffer_holder.cpp diff --git a/tests/unit_tests/wtf/buffer/detail_/buffer_view_holder.cpp b/tests/cxx/unit_tests/wtf/buffer/detail_/buffer_view_holder.cpp similarity index 100% rename from tests/unit_tests/wtf/buffer/detail_/buffer_view_holder.cpp rename to tests/cxx/unit_tests/wtf/buffer/detail_/buffer_view_holder.cpp diff --git a/tests/unit_tests/wtf/buffer/detail_/contiguous_model.cpp b/tests/cxx/unit_tests/wtf/buffer/detail_/contiguous_model.cpp similarity index 100% rename from tests/unit_tests/wtf/buffer/detail_/contiguous_model.cpp rename to tests/cxx/unit_tests/wtf/buffer/detail_/contiguous_model.cpp diff --git a/tests/unit_tests/wtf/buffer/detail_/contiguous_view_model.cpp b/tests/cxx/unit_tests/wtf/buffer/detail_/contiguous_view_model.cpp similarity index 100% rename from tests/unit_tests/wtf/buffer/detail_/contiguous_view_model.cpp rename to tests/cxx/unit_tests/wtf/buffer/detail_/contiguous_view_model.cpp diff --git a/tests/unit_tests/wtf/buffer/float_buffer.cpp b/tests/cxx/unit_tests/wtf/buffer/float_buffer.cpp similarity index 100% rename from tests/unit_tests/wtf/buffer/float_buffer.cpp rename to tests/cxx/unit_tests/wtf/buffer/float_buffer.cpp diff --git a/tests/unit_tests/wtf/concepts/floating_point.cpp b/tests/cxx/unit_tests/wtf/concepts/floating_point.cpp similarity index 100% rename from tests/unit_tests/wtf/concepts/floating_point.cpp rename to tests/cxx/unit_tests/wtf/concepts/floating_point.cpp diff --git a/tests/unit_tests/wtf/concepts/iterator.cpp b/tests/cxx/unit_tests/wtf/concepts/iterator.cpp similarity index 100% rename from tests/unit_tests/wtf/concepts/iterator.cpp rename to tests/cxx/unit_tests/wtf/concepts/iterator.cpp diff --git a/tests/unit_tests/wtf/concepts/modifiers.cpp b/tests/cxx/unit_tests/wtf/concepts/modifiers.cpp similarity index 100% rename from tests/unit_tests/wtf/concepts/modifiers.cpp rename to tests/cxx/unit_tests/wtf/concepts/modifiers.cpp diff --git a/tests/unit_tests/wtf/concepts/stream_insertion.cpp b/tests/cxx/unit_tests/wtf/concepts/stream_insertion.cpp similarity index 100% rename from tests/unit_tests/wtf/concepts/stream_insertion.cpp rename to tests/cxx/unit_tests/wtf/concepts/stream_insertion.cpp diff --git a/tests/unit_tests/wtf/concepts/wtf_float.cpp b/tests/cxx/unit_tests/wtf/concepts/wtf_float.cpp similarity index 100% rename from tests/unit_tests/wtf/concepts/wtf_float.cpp rename to tests/cxx/unit_tests/wtf/concepts/wtf_float.cpp diff --git a/tests/unit_tests/wtf/detail_/dispatcher.cpp b/tests/cxx/unit_tests/wtf/detail_/dispatcher.cpp similarity index 100% rename from tests/unit_tests/wtf/detail_/dispatcher.cpp rename to tests/cxx/unit_tests/wtf/detail_/dispatcher.cpp diff --git a/tests/unit_tests/wtf/detail_/downcaster.cpp b/tests/cxx/unit_tests/wtf/detail_/downcaster.cpp similarity index 100% rename from tests/unit_tests/wtf/detail_/downcaster.cpp rename to tests/cxx/unit_tests/wtf/detail_/downcaster.cpp diff --git a/tests/unit_tests/wtf/detail_/variant_from_tuple.cpp b/tests/cxx/unit_tests/wtf/detail_/variant_from_tuple.cpp similarity index 100% rename from tests/unit_tests/wtf/detail_/variant_from_tuple.cpp rename to tests/cxx/unit_tests/wtf/detail_/variant_from_tuple.cpp diff --git a/tests/unit_tests/wtf/fp/detail_/float_holder.cpp b/tests/cxx/unit_tests/wtf/fp/detail_/float_holder.cpp similarity index 100% rename from tests/unit_tests/wtf/fp/detail_/float_holder.cpp rename to tests/cxx/unit_tests/wtf/fp/detail_/float_holder.cpp diff --git a/tests/unit_tests/wtf/fp/detail_/float_model.cpp b/tests/cxx/unit_tests/wtf/fp/detail_/float_model.cpp similarity index 100% rename from tests/unit_tests/wtf/fp/detail_/float_model.cpp rename to tests/cxx/unit_tests/wtf/fp/detail_/float_model.cpp diff --git a/tests/unit_tests/wtf/fp/detail_/float_view_holder.cpp b/tests/cxx/unit_tests/wtf/fp/detail_/float_view_holder.cpp similarity index 100% rename from tests/unit_tests/wtf/fp/detail_/float_view_holder.cpp rename to tests/cxx/unit_tests/wtf/fp/detail_/float_view_holder.cpp diff --git a/tests/unit_tests/wtf/fp/detail_/float_view_model.cpp b/tests/cxx/unit_tests/wtf/fp/detail_/float_view_model.cpp similarity index 100% rename from tests/unit_tests/wtf/fp/detail_/float_view_model.cpp rename to tests/cxx/unit_tests/wtf/fp/detail_/float_view_model.cpp diff --git a/tests/unit_tests/wtf/fp/float.cpp b/tests/cxx/unit_tests/wtf/fp/float.cpp similarity index 100% rename from tests/unit_tests/wtf/fp/float.cpp rename to tests/cxx/unit_tests/wtf/fp/float.cpp diff --git a/tests/unit_tests/wtf/fp/float_view.cpp b/tests/cxx/unit_tests/wtf/fp/float_view.cpp similarity index 100% rename from tests/unit_tests/wtf/fp/float_view.cpp rename to tests/cxx/unit_tests/wtf/fp/float_view.cpp diff --git a/tests/unit_tests/wtf/main.cpp b/tests/cxx/unit_tests/wtf/main.cpp similarity index 100% rename from tests/unit_tests/wtf/main.cpp rename to tests/cxx/unit_tests/wtf/main.cpp diff --git a/tests/unit_tests/wtf/rtti/detail_/type_holder.cpp b/tests/cxx/unit_tests/wtf/rtti/detail_/type_holder.cpp similarity index 100% rename from tests/unit_tests/wtf/rtti/detail_/type_holder.cpp rename to tests/cxx/unit_tests/wtf/rtti/detail_/type_holder.cpp diff --git a/tests/unit_tests/wtf/rtti/detail_/type_model.cpp b/tests/cxx/unit_tests/wtf/rtti/detail_/type_model.cpp similarity index 100% rename from tests/unit_tests/wtf/rtti/detail_/type_model.cpp rename to tests/cxx/unit_tests/wtf/rtti/detail_/type_model.cpp diff --git a/tests/unit_tests/wtf/rtti/type_info.cpp b/tests/cxx/unit_tests/wtf/rtti/type_info.cpp similarity index 100% rename from tests/unit_tests/wtf/rtti/type_info.cpp rename to tests/cxx/unit_tests/wtf/rtti/type_info.cpp diff --git a/tests/unit_tests/wtf/type_traits/float_traits.cpp b/tests/cxx/unit_tests/wtf/type_traits/float_traits.cpp similarity index 100% rename from tests/unit_tests/wtf/type_traits/float_traits.cpp rename to tests/cxx/unit_tests/wtf/type_traits/float_traits.cpp diff --git a/tests/unit_tests/wtf/type_traits/is_convertible.cpp b/tests/cxx/unit_tests/wtf/type_traits/is_convertible.cpp similarity index 100% rename from tests/unit_tests/wtf/type_traits/is_convertible.cpp rename to tests/cxx/unit_tests/wtf/type_traits/is_convertible.cpp diff --git a/tests/unit_tests/wtf/type_traits/is_floating_point.cpp b/tests/cxx/unit_tests/wtf/type_traits/is_floating_point.cpp similarity index 100% rename from tests/unit_tests/wtf/type_traits/is_floating_point.cpp rename to tests/cxx/unit_tests/wtf/type_traits/is_floating_point.cpp diff --git a/tests/unit_tests/wtf/type_traits/precision.cpp b/tests/cxx/unit_tests/wtf/type_traits/precision.cpp similarity index 100% rename from tests/unit_tests/wtf/type_traits/precision.cpp rename to tests/cxx/unit_tests/wtf/type_traits/precision.cpp diff --git a/tests/unit_tests/wtf/type_traits/tupple_append.cpp b/tests/cxx/unit_tests/wtf/type_traits/tupple_append.cpp similarity index 100% rename from tests/unit_tests/wtf/type_traits/tupple_append.cpp rename to tests/cxx/unit_tests/wtf/type_traits/tupple_append.cpp diff --git a/tests/unit_tests/wtf/type_traits/type_name.cpp b/tests/cxx/unit_tests/wtf/type_traits/type_name.cpp similarity index 100% rename from tests/unit_tests/wtf/type_traits/type_name.cpp rename to tests/cxx/unit_tests/wtf/type_traits/type_name.cpp diff --git a/cmake/disable_in_source_builds.cmake b/tests/python/unit_tests/fp/test_float.py similarity index 63% rename from cmake/disable_in_source_builds.cmake rename to tests/python/unit_tests/fp/test_float.py index a98cc9f..fa482a3 100644 --- a/cmake/disable_in_source_builds.cmake +++ b/tests/python/unit_tests/fp/test_float.py @@ -1,4 +1,4 @@ -# Copyright 2025 NWChemEx-Project +# Copyright 2026 NWChemEx-Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,12 +12,21 @@ # See the License for the specific language governing permissions and # limitations under the License. -include_guard() +"""Unit tests for the wtf.Float Python binding.""" -function(disable_in_source_builds) - if("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") - message(FATAL_ERROR "In-source builds are not allowed.") - endif() -endfunction() +import wtf -disable_in_source_builds() + +def test_import(): + assert hasattr(wtf, "Float") + + +def test_set_value(): + f = wtf.Float(3.14) + assert f is not None + + +def test_to_string(): + f = wtf.Float(3.14) + s = f.to_string() + assert "3.14" in s