-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add recipe for Scine Python bindings #18482
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
{% set name = "scine-utilities-python" %} | ||
{% set version = "4.0.0" %} | ||
|
||
package: | ||
name: {{ name }} | ||
version: {{ version }} | ||
|
||
source: | ||
- url: https://github.com/qcscine/utilities/archive/refs/tags/{{ version }}.tar.gz | ||
sha256: 3bcabd8f4270f0c1efd235a0d22506f4750b0ccffa99184d4362b95a1da7a1d4 | ||
fn: {{ name }}.tar.gz | ||
patches: | ||
- skip_library_build.patch | ||
- url: https://github.com/qcscine/development-utils/archive/refs/tags/4.0.0.tar.gz | ||
sha256: 54002c2082b6bb75672ec66bf9cf3935bbdf6b085ed9b4d7174cbdedb7c2275d | ||
fn: dev.tar.gz | ||
folder: dev | ||
patches: | ||
- pybind11_pin.patch | ||
|
||
build: | ||
number: 0 | ||
skip: true # [win or osx] | ||
script: | ||
- set -ex | ||
- > | ||
cmake | ||
${CMAKE_ARGS} | ||
-B _build -G Ninja | ||
-DPYTHON_EXECUTABLE={{ PYTHON }} | ||
-DSCINE_MARCH="" | ||
-DSCINE_SKIP_LIBRARY=ON | ||
-DSCINE_BUILD_TESTS=OFF | ||
-DSCINE_BUILD_PYTHON_BINDINGS=ON | ||
- cmake --build _build | ||
- cmake --install _build | ||
|
||
requirements: | ||
build: | ||
- {{ compiler('c') }} | ||
- {{ compiler('cxx') }} | ||
- cmake | ||
- ninja | ||
- pkg-config | ||
- llvm-openmp # [osx] | ||
- libgomp # [linux] | ||
host: | ||
- boost-cpp | ||
- eigen | ||
- gtest | ||
- gmock | ||
- libblas | ||
- pip | ||
- pybind11 | ||
- pybind11-abi | ||
- python | ||
- scine-core | ||
- scine-utilsos {{ version }} | ||
- yaml-cpp | ||
run: | ||
- numpy | ||
- python | ||
- scine-utilsos {{ version }} | ||
- scipy | ||
- yaml-cpp | ||
|
||
test: | ||
imports: | ||
- scine_utilities | ||
source_files: | ||
- src/Utils/Python/Tests/ | ||
requires: | ||
- pip | ||
- pytest | ||
commands: | ||
- pip check | ||
- pytest src/Utils/Python/Tests/ | ||
|
||
about: | ||
license: BSD-3-Clause | ||
license_file: LICENSE.txt | ||
summary: | | ||
Contains functionality which is used in most SCINE modules (Python bindings). | ||
home: https://scine.ethz.ch/ | ||
dev_url: https://github.com/qcscine/utilities | ||
|
||
extra: | ||
recipe-maintainers: | ||
- awvwgk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
diff --git a/cmake/ImportPybind11.cmake b/cmake/ImportPybind11.cmake | ||
index 34d009c..a819e4c 100644 | ||
--- a/cmake/ImportPybind11.cmake | ||
+++ b/cmake/ImportPybind11.cmake | ||
@@ -6,7 +6,7 @@ | ||
macro(import_pybind11) | ||
# If the target already exists, do nothing | ||
if(NOT TARGET pybind11::pybind11) | ||
- find_package(pybind11 2.6.2 EXACT QUIET) | ||
+ find_package(pybind11) | ||
if(TARGET pybind11::pybind11) | ||
message(STATUS "Found pybind11 at ${pybind11_DIR}") | ||
else() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
diff --git a/src/Utils/CMakeLists.txt b/src/Utils/CMakeLists.txt | ||
index f435593..cfc8fb7 100644 | ||
--- a/src/Utils/CMakeLists.txt | ||
+++ b/src/Utils/CMakeLists.txt | ||
@@ -29,6 +29,7 @@ if(SCINE_PARALLELIZE) | ||
find_package(OpenMP REQUIRED) | ||
endif() | ||
|
||
+if(NOT SCINE_SKIP_LIBRARY) | ||
# Obey standard CMake behavior regarding shared/static libraries | ||
add_library(UtilsOS ${UTILS_HEADERS} ${UTILS_CPPS}) | ||
if(NOT BUILD_SHARED_LIBS) | ||
@@ -119,6 +120,10 @@ if(SCINE_BUILD_TESTS) | ||
DESTINATION ${CMAKE_CURRENT_BINARY_DIR} | ||
) | ||
endif() | ||
+else() | ||
+include(ImportUtilsOS) | ||
+import_utils_os() | ||
+endif() | ||
|
||
# Python bindings | ||
if(SCINE_BUILD_PYTHON_BINDINGS) | ||
@@ -164,11 +169,13 @@ if(SCINE_BUILD_PYTHON_BINDINGS) | ||
${CMAKE_CURRENT_BINARY_DIR}/scine_utilities/__init__.py | ||
) | ||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Python/README.rst DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) | ||
+ if(NOT SCINE_SKIP_LIBRARY) | ||
add_custom_command(TARGET UtilsOSModule POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:UtilsOSModule> ${CMAKE_CURRENT_BINARY_DIR}/scine_utilities | ||
COMMENT "Copying UtilsOS module into python package directory" | ||
) | ||
add_dependencies(scine_utilities UtilsOSModule) | ||
+ endif() | ||
|
||
# Figure out which targets need to be copied along | ||
set(_py_targets_to_copy Scine::Core) # Core is always shared | ||
@@ -187,11 +194,13 @@ if(SCINE_BUILD_PYTHON_BINDINGS) | ||
string(APPEND utils_PY_DEPS ", \"${_target_filename}\"") | ||
endforeach() | ||
|
||
+ if(NOT SCINE_SKIP_LIBRARY) | ||
add_custom_command(TARGET UtilsOS POST_BUILD | ||
COMMAND ${CMAKE_COMMAND} -E copy ${_py_target_gen_exprs} ${CMAKE_CURRENT_BINARY_DIR}/scine_utilities | ||
COMMENT "Copying dependent shared libraries into python package directory" | ||
) | ||
message(STATUS "Targets to copy for python bindings: ${_py_targets_to_copy}") | ||
+ endif() | ||
unset(_py_targets_to_copy) | ||
|
||
# Typing stubs | ||
@@ -227,10 +236,12 @@ if(SCINE_BUILD_PYTHON_BINDINGS) | ||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/doc-py | ||
DOCTEST | ||
) | ||
+ if(NOT SCINE_SKIP_LIBRARY) | ||
# The UtilsOSModule is technically also a dependency of the documentation | ||
if(TARGET scine_utilitiesDocumentation) | ||
add_dependencies(scine_utilitiesDocumentation UtilsOSModule) | ||
endif() | ||
+ endif() | ||
endif() | ||
|
||
if(SCINE_BUILD_PYTHON_BINDINGS) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all of these included because your patched build fails if they aren't present? In theory python bindings should only depend on the library it is binding. i.e. scine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The upstream package has the bad habit of downloading everything that is not present in the host environment. Since I patched the build files I need most of those present as well, alternative I can try to patch the build files further to only require the essential ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am concerned about overlinking from the python module to libraries that are not actually used directly. It looks like the module should only link to scine and yaml, but it is also linking to BLAS.
https://github.com/qcscine/utilities/blob/493b8db45772b231bc0296535a09905b8e292f77/src/Utils/CMakeLists.txt#L135
What do you know about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned about over-linking because conda-build will not be able to detect it since BLAS is listed in the host section in order to satisfy the build system requirements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Python export of the utilities library is actually quite heavy and more than just a thin wrapper around the respective C++ library, making use of most of the libraries in host, which are also found correctly by conda-build:
I can further patch the build files to remove dependencies like gtest/gmock, which are actually superfluous here, but downloading a few additional packages in the host environment which don't add any run exports or pins not already present from the C++ library seems not very harmful to me, especially when the C++ library is pinned with an exact version constraint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having libblas in host is useful to have the netlib variant installed via conda-forge-pinning, without the OpenBLAS variant would get in the build step.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good enough for me.