Skip to content

Commit

Permalink
Set module version with setuptools-scm
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloferz committed Oct 9, 2024
1 parent 5b30b18 commit 3c6b24c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
uses: docker/build-push-action@v2
with:
context: .

trunk:
runs-on: ubuntu-latest
steps:
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 5 in Dockerfile

View workflow job for this annotation

GitHub Actions / Trunk Check

hadolint(DL3013)

[new] Pin versions in pip. Instead of `pip install <package>` use `pip install <package>==<version>` or `pip install --requirement <requirements file>`

COPY . ../
RUN cmake .. && make install
RUN python -c "import openmm_dlext"
RUN python -c "import openmm.dlext"
22 changes: 22 additions & 0 deletions cmake/Modules/OpenMMTools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 2 additions & 0 deletions wrappers/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions wrappers/python/PyDLExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_<DLDeviceType>(m, "DeviceType").value("CPU", kDLCPU).value("GPU", kDLCUDA);
Expand Down

0 comments on commit 3c6b24c

Please sign in to comment.