Commit d9e5709d authored by Morten Ofstad's avatar Morten Ofstad
Browse files

Merge branch feature/morten.ofstad/PythonBuild with refs/heads/master into...

Merge branch feature/morten.ofstad/PythonBuild with refs/heads/master into refs/merge-requests/16/train
parents 53d5bf78 7f19581d
Pipeline #542 passed with stages
in 7 minutes
......@@ -3,10 +3,6 @@ Builds
Dist
CMakeSettings.json
CMakeLists.txt.user
python/.eggs
python/_skbuild
python/*.log
python/**/*.pyd
python/openvds/test/aws_defs.py
CMakeSettings.json
out
......@@ -15,4 +11,7 @@ build/
python/tools/tmpinclude/
python/tools/generated
python/tools/.vscode
python/tools/WrapperReport.txt
\ No newline at end of file
python/tools/WrapperReport.txt
/.pytest_cache
/_skbuild
/aws_sdk*.log
......@@ -5,4 +5,5 @@ zlib*
fmt*
cpprestapi*
azure-storage-cpp*
pybind11-2.4.3
CMakeArtifacts*
......@@ -17,4 +17,5 @@ macro(build3rdparty)
BuildFmt()
BuildCppRestSdk()
BuildAzure()
add_subdirectory(${pybind11_SOURCE_DIR} ${PROJECT_BINARY_DIR}/pybind11_${pybind11_VERSION} EXCLUDE_FROM_ALL)
endmacro()
......@@ -27,6 +27,7 @@ function(Fetch3rdParty)
Fetch3rdParty_Package(fmt 6.0.0 https://github.com/fmtlib/fmt/archive/6.0.0.tar.gz SHA256=f1907a58d5e86e6c382e51441d92ad9e23aea63827ba47fd647eacc0d3a16c78)
Fetch3rdParty_Package(cpprestapi 2.10.14 https://github.com/microsoft/cpprestsdk/archive/v2.10.14.tar.gz SHA256=f2628b248f714d7bbd6a536553bc3782602c68ca1b129017985dd70cc3515278)
Fetch3rdParty_Package(azure-storage-cpp 7.0.0 https://github.com/Azure/azure-storage-cpp/archive/v7.0.0.tar.gz SHA256=2129511dcf40383de5ac643abf68cad4907b5cdbfe471c75ba264a83e3078dc7)
Fetch3rdParty_Package(pybind11 2.4.3 https://github.com/pybind/pybind11/archive/v2.4.3.tar.gz SHA256=1eed57bc6863190e35637290f97a20c81cfe4d9090ac0a24f3bbf08f265eb71d)
if (BUILD_ZLIB)
Fetch3rdParty_Package(zlib 1.2.11 http://zlib.net/zlib-1.2.11.tar.gz SHA256=c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1)
......
[build-system]
requires = ["setuptools", "wheel", "scikit-build", "cmake", "ninja"]
cmake_minimum_required(VERSION 3.12.0)
project(OpenVDS-python)
set(python ${Python3_EXECUTABLE})
set(setup.py ${CMAKE_CURRENT_SOURCE_DIR}/setup.py)
#this line doesn't work to have inline in add_custom_target so expand it in a variable
#$<$<BOOL:${zlib_INSTALL_INT_CONFIG}>:-DCMAKE_PREFIX_PATH=${zlib_INSTALL_INT_CONFIG}>
if (zlib_INSTALL_INT_CONFIG)
set(ZLIB_PREFIX_PATH "-DCMAKE_PREFIX_PATH=${zlib_INSTALL_INT_CONFIG}")
endif()
add_custom_target(
openvds-python ALL
COMMENT "Building python library with setup.py"
SOURCES ${setup.py}
VERBATIM
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${python} ${setup.py}
# build the extension inplace (really, once its built, copy it to the
# source tree) so that post-build, the directory can be used to run
# tests against
build_ext --inplace
build # setup.py build args
--cmake-executable ${CMAKE_COMMAND}
--generator ${CMAKE_GENERATOR}
$<$<BOOL:$<CONFIG>>:--build-type=$<CONFIG>>
-- # cmake to the extension
-Dopenvds_DIR=${OPENVDS_LIB_BINARY_DIR}
-Dpython3_EXE=${Python3_EXECUTABLE}
-Dpackage_DIR=${CMAKE_CURRENT_SOURCE_DIR}
-DTEST_AWS_BUCKET=${TEST_AWS_BUCKET}
-DTEST_AWS_OBJECTID=${TEST_AWS_OBJECTID}
-DTEST_AWS_REGION=${TEST_AWS_REGION}
${ZLIB_PREFIX_PATH}
# "install" to the python/openvds dir with rpath, so there's no need
# to fiddle with environment in ctest to load the core library from
# the build tree
-DENABLE_OPENMP=${ENABLE_OPENMP}
-DCMAKE_BUILD_TYPE=$<CONFIG>
-DCMAKE_GENERATOR=${CMAKE_GENERATOR}
-DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
$<$<BOOL:$<CONFIG>>:-DCMAKE_BUILD_TYPE=$<CONFIG>>
-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=ON
-DCMAKE_INSTALL_RPATH=$<TARGET_FILE_DIR:openvds>
-DCMAKE_INSTALL_NAME_DIR=$<TARGET_FILE_DIR:openvds>
)
add_dependencies(openvds-python openvds)
# run tests with setup.py test
# this is very slow compared to invoking pytest directly, but setuptools will
# copy the built extension into the tree as it sees fit
add_test(NAME python.unit
COMMAND ${python} ${setup.py} --skip-cmake test
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
add_subdirectory(openvds)
\ No newline at end of file
cmake_minimum_required(VERSION 3.5.0)
project(openvds-python-extension LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_VISIBILITY_PRESET "hidden")
set(CMAKE_C_VISIBILITY_PRESET "hidden")
find_package(PythonExtensions REQUIRED)
find_package(Threads REQUIRED)
if(ENABLE_OPENMP)
find_package(OpenMP REQUIRED)
endif()
find_package(ZLIB REQUIRED)
find_package(openvds REQUIRED)
if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
# Set up debugging environment for "core" project in Visual Studio
set(PYTHONEXE "${python3_EXE}")
set(BINDIR "${openvds_DIR}/SEG-Y") # A bit of a hack to get all the dependent dlls
set(PYTHONPATH "${package_DIR}")
configure_file("../core.vcxproj.user.txt" "${CMAKE_CURRENT_BINARY_DIR}/core.vcxproj.user" @ONLY)
endif()
configure_file("../aws_defs.txt" "${CMAKE_CURRENT_SOURCE_DIR}/test/aws_defs.py" @ONLY)
add_library(core MODULE
pybind11_add_module(core MODULE
core.cpp
PyGlobal.cpp
PyGlobal.h
......@@ -54,25 +28,23 @@ add_library(core MODULE
PyVolumeSampler.h
)
SET(pythonsources
${CMAKE_CURRENT_SOURCE_DIR}/__init__.py
)
add_custom_command(TARGET core
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${pythonsources} $<TARGET_FILE_DIR:core>)
copyDllForTarget(core)
target_include_directories(core
PRIVATE
${PYBIND11_INCLUDE_DIRS}
)
python_extension_module(core)
target_link_libraries(core openvds::openvds)
if (MSVC)
target_compile_options(core
BEFORE
PRIVATE
/EHsc
)
string(REPLACE "/" "\\" _package_dir ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_command(
TARGET core
POST_BUILD
COMMAND copy $(TargetPath) ${_package_dir}
)
endif ()
target_link_libraries(core PRIVATE openvds)
install(TARGETS core LIBRARY DESTINATION python/openvds)
install(FILES ${pythonsources} DESTINATION python/openvds)
install(TARGETS core LIBRARY DESTINATION openvds)
#!/usr/bin/env python3
import os
import skbuild
import setuptools
class get_pybind_include(object):
def __init__(self, user=False):
self.user = user
def __str__(self):
# postpone importing pybind11 until building actually happens
import pybind11
return pybind11.get_include(self.user)
pybind_includes = [
str(get_pybind_include()),
str(get_pybind_include(user = True))
]
skbuild.setup(
name = 'openvds',
packages = [
'openvds',
],
install_requires = [
'numpy',
],
setup_requires = [
'pybind11 >= 2.2',
'pytest-runner',
],
tests_require = [
'pytest',
],
cmake_args = [
'-DPYBIND11_INCLUDE_DIRS=' + ';'.join(pybind_includes),
],
cmake_source_dir = 'openvds',
# skbuild's test imples develop, which is pretty obnoxious instead, use a
# manually integrated pytest.
cmdclass = { 'test': setuptools.command.test.test },
)
#!/usr/bin/env python3
import sys
try:
from skbuild import setup
except ImportError:
print('scikit-build is required to build from source.', file=sys.stderr)
print('Please run:', file=sys.stderr)
print('', file=sys.stderr)
print(' python -m pip install scikit-build')
sys.exit(1)
setup(
name="openvds",
version="0.1",
description="Open-source implementation of the Volume Data Store (VDS) standard for fast random access to multi-dimensional volumetric data",
author='The Open Group / Bluware, Inc.',
license="Apache License, Version 2.0",
packages=['openvds'],
package_dir={'': 'python'}
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment