diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f576310..925373c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,7 @@ jobs: uses: docker/build-push-action@v2 with: context: . + trunk: runs-on: ubuntu-latest steps: diff --git a/Dockerfile b/Dockerfile index dcb8c32..cf1d221 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,9 @@ FROM ssages/pysages-hoomd:latest WORKDIR /openmm-dlex/.docker_build +# Install python dependencies +RUN python3 -m pip install --no-cache-dir --upgrade pip setuptools-scm + COPY . ../ RUN cmake .. && make install -RUN python -c "import openmm_dlext" +RUN python -c "import openmm.dlext" diff --git a/cmake/Modules/OpenMMTools.cmake b/cmake/Modules/OpenMMTools.cmake index 189aa1f..f522f37 100644 --- a/cmake/Modules/OpenMMTools.cmake +++ b/cmake/Modules/OpenMMTools.cmake @@ -76,3 +76,25 @@ print(os.path.normpath(os.path.join(openmm.__file__, os.pardir, os.pardir)), end ) set(OpenMMDLExt_Python_PATH "${OpenMM_Python_PATH}" PARENT_SCOPE) endfunction() + +# This requires setuptools-scm to be installed as we will use it to setup the module version +function(set_version target) + find_package(Python QUIET COMPONENTS Interpreter) + set(GET_VERSION_SCRIPT " +from setuptools_scm import get_version +print(get_version(), end='')" + ) + execute_process( + COMMAND ${Python_EXECUTABLE} -c ${GET_VERSION_SCRIPT} + ERROR_VARIABLE error + OUTPUT_VARIABLE GIT_VERSION + RESULT_VARIABLE exit_code + ) + if(NOT exit_code EQUAL 0) + message(FATAL_ERROR + "The build process depends on setuptools-scm, make sure it is installed. " + "Got the following error:\n${error}" + ) + endif() + target_compile_definitions(${target} PUBLIC PYPROJECT_VERSION=${GIT_VERSION}) +endfunction() diff --git a/wrappers/python/CMakeLists.txt b/wrappers/python/CMakeLists.txt index 3ec3912..2b4c813 100644 --- a/wrappers/python/CMakeLists.txt +++ b/wrappers/python/CMakeLists.txt @@ -51,6 +51,7 @@ set(pybind11_MODULE_NAME "_api") pybind11_add_module(${pybind11_MODULE_NAME}_fallback MODULE "") +set_version(${pybind11_MODULE_NAME}_fallback) target_sources(${pybind11_MODULE_NAME}_fallback PRIVATE PyDLExt.cpp) target_compile_features(${pybind11_MODULE_NAME}_fallback PRIVATE cxx_std_11) target_link_libraries(${pybind11_MODULE_NAME}_fallback PRIVATE ${PROJECT_NAME}) @@ -63,6 +64,7 @@ install(TARGETS ${pybind11_MODULE_NAME}_fallback if(BUILD_CUDA_LIB) pybind11_add_module(${pybind11_MODULE_NAME} MODULE "") + set_version(${pybind11_MODULE_NAME}) target_sources(${pybind11_MODULE_NAME} PRIVATE PyDLExt.cpp) target_compile_features(${pybind11_MODULE_NAME} PRIVATE cxx_std_11) target_link_libraries(${pybind11_MODULE_NAME} PRIVATE ${PROJECT_NAME}CUDA) diff --git a/wrappers/python/PyDLExt.cpp b/wrappers/python/PyDLExt.cpp index d53f009..ad54430 100644 --- a/wrappers/python/PyDLExt.cpp +++ b/wrappers/python/PyDLExt.cpp @@ -97,6 +97,7 @@ PYBIND11_MODULE(_api, m) // instead of `openmm.dlext._api.x`. py::str module_name = m.attr("__name__"); m.attr("__name__") = "openmm.dlext"; + m.attr("__version__") = Py_STRINGIFY(PYPROJECT_VERSION); // Enums py::enum_(m, "DeviceType").value("CPU", kDLCPU).value("GPU", kDLCUDA);