-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1692e6b
commit c22435b
Showing
10 changed files
with
329 additions
and
78 deletions.
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
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
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 |
---|---|---|
@@ -1,54 +1,49 @@ | ||
file(GLOB_RECURSE SRCS *.i) | ||
set_source_files_properties(${SRCS} PROPERTIES CPLUSPLUS ON) | ||
option(AUTO_GENERATE "Auto generate the targes" OFF) | ||
if(AUTO_GENERATE) | ||
file(GLOB_RECURSE SRCS *.i) | ||
set_source_files_properties(${SRCS} PROPERTIES CPLUSPLUS ON) | ||
|
||
swig_add_library( | ||
${WEDPR_PYTHON_TRANSPORT} | ||
TYPE MODULE | ||
LANGUAGE python | ||
OUTPUT_DIR ${WEDPR_PYTHON_TRANSPORT_DIR} | ||
SOURCES ${SRCS} | ||
) | ||
|
||
message("#### Python3_INCLUDE_DIRS: ${Python3_INCLUDE_DIRS}") | ||
target_include_directories( | ||
${WEDPR_PYTHON_TRANSPORT} | ||
PRIVATE | ||
../include | ||
${Python3_INCLUDE_DIRS} | ||
) | ||
set_property(TARGET ${WEDPR_PYTHON_TRANSPORT} PROPERTY SWIG_USE_TARGET_INCLUDE_DIRECTORIES ON) | ||
file(MAKE_DIRECTORY ${WEDPR_PYTHON_TRANSPORT_DIR}) | ||
file(MAKE_DIRECTORY ${WEDPR_PYTHON_TRANSPORT_LIB_DIR}) | ||
|
||
swig_add_library( | ||
${WEDPR_PYTHON_TRANSPORT} | ||
TYPE MODULE | ||
LANGUAGE python | ||
OUTPUT_DIR ${WEDPR_PYTHON_TRANSPORT_DIR} | ||
SOURCES ${SRCS} | ||
) | ||
set_property(TARGET ${WEDPR_PYTHON_TRANSPORT} PROPERTY SWIG_USE_TARGET_INCLUDE_DIRECTORIES ON) | ||
else() | ||
file(GLOB_RECURSE SRCS src/*.cxx) | ||
add_library(${WEDPR_PYTHON_TRANSPORT} SHARED ${SRCS}) | ||
endif() | ||
|
||
target_include_directories(${WEDPR_PYTHON_TRANSPORT} PRIVATE ${Python_INCLUDE_DIRS}) | ||
|
||
# note: macOS is APPLE and also UNIX ! | ||
if(APPLE) | ||
set_property(TARGET ${WEDPR_PYTHON_TRANSPORT} APPEND PROPERTY | ||
LINK_FLAGS "-flat_namespace -undefined suppress" | ||
) | ||
set_target_properties(${WEDPR_PYTHON_TRANSPORT} PROPERTIES | ||
SUFFIX ".so" | ||
INSTALL_RPATH "@loader_path;@loader_path/../../${WEDPR_PYTHON_TRANSPORT}/.libs" | ||
set_target_properties(${WEDPR_PYTHON_TRANSPORT} PROPERTIES | ||
INSTALL_RPATH "@loader_path;@loader_path/../../${WEDPR_PYTHON_TRANSPORT}/.libs" | ||
) | ||
elseif(UNIX) | ||
set_target_properties(${WEDPR_PYTHON_TRANSPORT} PROPERTIES | ||
INSTALL_RPATH "$ORIGIN:$ORIGIN/../../${WEDPR_PYTHON_TRANSPORT}/.libs" | ||
) | ||
endif() | ||
target_link_libraries(${WEDPR_PYTHON_TRANSPORT} PRIVATE ${WEDPR_TRANSPORT_SDK_TARGET}) | ||
|
||
SET(LIBRARY_OUTPUT_PATH ${WEDPR_PYTHON_TRANSPORT_DIR}/) | ||
|
||
# Variable PYTHON_LIBRARIES can contains keyword `optimized` | ||
# which won't be interpreted inside a generator expression. | ||
# i.e. we can't use: $<$<PLATFORM_ID:Windows>:${PYTHON_LIBRARIES}> | ||
# see: https://cmake.org/cmake/help/git-stage/command/target_link_libraries.html#command:target_link_libraries | ||
if(MSVC) | ||
target_link_libraries(${WEDPR_PYTHON_TRANSPORT} PRIVATE ${Python3_LIBRARIES}) | ||
else() | ||
target_link_libraries(${WEDPR_PYTHON_TRANSPORT} PRIVATE ${WEDPR_TRANSPORT_SDK_TARGET} ${Python_LIBRARIES}) | ||
endif() | ||
|
||
# Configure setup.py and copy to output directory | ||
file(GENERATE OUTPUT ${WEDPR_PYTHON_TRANSPORT_DIR}/__init__.py CONTENT "__version__ = \"${PYTHON_TOOLKIT_VERSION}\"\n") | ||
set(SETUP_PY_IN ${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in) | ||
set(SETUP_PY_OUT ${WEDPR_PYTHON_TRANSPORT_DIR}/setup.py) | ||
configure_file(${SETUP_PY_IN} ${SETUP_PY_OUT}) | ||
SET(LIBRARY_OUTPUT_PATH ${WEDPR_PYTHON_TRANSPORT_LIB_DIR}) | ||
|
||
message(STATUS "CMAKE_INSTALL_INCLUDEDIR => ${CMAKE_INSTALL_INCLUDEDIR}") | ||
message(STATUS "CMAKE_CURRENT_SOURCE_DIR => ${CMAKE_CURRENT_SOURCE_DIR}") |
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,62 @@ | ||
import sys | ||
|
||
from setuptools import find_packages, setup | ||
from setuptools.command.bdist_egg import bdist_egg | ||
|
||
|
||
class bdist_egg_disabled(bdist_egg): | ||
"""Disabled version of bdist_egg | ||
Prevents setup.py install from performing setuptools' default easy_install, | ||
which it should never ever do. | ||
""" | ||
|
||
def run(self): | ||
sys.exit( | ||
"Aborting implicit building of eggs. Use `pip install .` to install from source." | ||
) | ||
|
||
|
||
setup_args = dict( | ||
name='wedpr-python-gateway-sdk', | ||
packages=find_packages(), | ||
version="1.0.0-rc1", | ||
description="wedpr-python-gateway-sdk: The gateway sdk for WeDPR", | ||
long_description_content_type="text/markdown", | ||
author="Jupyter Development Team", | ||
author_email="[email protected]", | ||
url="https://github.com/WeBankBlockchain/WeDPR-Component", | ||
license="Apache-2.0", | ||
platforms="Linux, Mac OS X", | ||
keywords=['Interactive', 'Interpreter', 'Shell', 'Web'], | ||
python_requires=">=3.8", | ||
include_package_data=True, | ||
classifiers=[ | ||
'Intended Audience :: Developers', | ||
'Intended Audience :: System Administrators', | ||
'Intended Audience :: Science/Research', | ||
'License :: OSI Approved :: Apache License', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 3', | ||
], | ||
) | ||
|
||
setup_args['cmdclass'] = { | ||
'bdist_egg': bdist_egg if 'bdist_egg' in sys.argv else bdist_egg_disabled, | ||
} | ||
|
||
setup_args['install_requires'] = install_requires = [] | ||
with open('requirements.txt') as f: | ||
for line in f.readlines(): | ||
req = line.strip() | ||
if not req or req.startswith(('-e', '#')): | ||
continue | ||
install_requires.append(req) | ||
|
||
|
||
def main(): | ||
setup(**setup_args) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Empty file.
Empty file.
89 changes: 89 additions & 0 deletions
89
cpp/wedpr-transport/sdk-wrapper/python/bindings/utils/lib_loader.py
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 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import platform | ||
import os | ||
from enum import Enum | ||
import sys | ||
import ctypes | ||
|
||
|
||
class OSType(Enum): | ||
MACOS_X64 = 1 | ||
MACOS_ARM64 = 2 | ||
WINDOWS = 3 | ||
LINUX_X64 = 4 | ||
LINUX_ARM64 = 5 | ||
|
||
|
||
class ArchType(Enum): | ||
ARM64 = 1 | ||
X86_64 = 2 | ||
|
||
|
||
class LibLoader: | ||
# the library information | ||
TRANSPORT_LIB_PATH = "libs" | ||
TRANSPORT_LIB_NAME = "wedpr_python_transport" | ||
LIB_PREFIX = "lib" | ||
MACOS_LIB_POSTFIX = "dylib" | ||
WINDOWS_LIB_POSTFIX = "dll" | ||
LINUX_LIB_PORSTFIX = "so" | ||
# the OS name | ||
MACOS_OS = "darwin" | ||
WINDOWS_OS = "windows" | ||
LINUX_OS = "linux" | ||
|
||
AARCH64 = "aarch64" | ||
ARM64 = "arm64" | ||
X86_64 = "x86_64" | ||
|
||
@staticmethod | ||
def get_arch_type(): | ||
arch_type = platform.machine().lower() | ||
if LibLoader.AARCH64 in arch_type or LibLoader.ARM64 in arch_type: | ||
return ArchType.ARM64 | ||
if LibLoader.X86_64 in arch_type: | ||
return ArchType.X86_64 | ||
raise Exception(f"Unsupported arch type: {arch_type}") | ||
|
||
@staticmethod | ||
def get_os_type(): | ||
os_type = platform.system().lower() | ||
arch_type = LibLoader.get_arch_type() | ||
if LibLoader.MACOS_OS in os_type: | ||
if arch_type == ArchType.ARM64: | ||
return OSType.MACOS_ARM64 | ||
else: | ||
return OSType.MACOS_X64 | ||
if LibLoader.LINUX_OS in os_type: | ||
if arch_type == ArchType.ARM64: | ||
return OSType.LINUX_ARM64 | ||
else: | ||
return OSType.LINUX_X64 | ||
if LibLoader.WINDOWS_OS in os_type: | ||
return OSType.WINDOWS | ||
raise Exception(f"Unsupported os {os_type}, arch: {arch_type}") | ||
|
||
@staticmethod | ||
def get_lib_name(): | ||
os_type = LibLoader.get_os_type() | ||
if os_type == OSType.WINDOWS: | ||
return "{}{}.{}".format(LibLoader.LIB_PREFIX, LibLoader.TRANSPORT_LIB_NAME, LibLoader.WINDOWS_LIB_POSTFIX) | ||
if os_type == OSType.MACOS_ARM64: | ||
return "{}{}-arm64.{}".format(LibLoader.LIB_PREFIX, LibLoader.TRANSPORT_LIB_NAME, LibLoader.MACOS_LIB_POSTFIX) | ||
if os_type == OSType.MACOS_X64: | ||
return "{}{}.{}".format(LibLoader.LIB_PREFIX, LibLoader.TRANSPORT_LIB_NAME, LibLoader.MACOS_LIB_POSTFIX) | ||
if os_type == OSType.LINUX_ARM64: | ||
return "{}{}.{}-arm64".format(LibLoader.LIB_PREFIX, LibLoader.TRANSPORT_LIB_NAME, LibLoader.LINUX_LIB_PORSTFIX) | ||
if os_type == OSType.LINUX_X64: | ||
return "{}{}.{}".format(LibLoader.LIB_PREFIX, LibLoader.TRANSPORT_LIB_NAME, LibLoader.LINUX_LIB_PORSTFIX) | ||
raise Exception( | ||
f"get_lib_name failed for not support the os_type: {os_type}") | ||
|
||
@staticmethod | ||
def load_lib(): | ||
lib_path = os.path.join( | ||
LibLoader.TRANSPORT_LIB_PATH, LibLoader.get_lib_name()) | ||
print(f"#### lib_path: {lib_path}") | ||
lib = ctypes.cdll.LoadLibrary(lib_path) | ||
return lib |
12 changes: 12 additions & 0 deletions
12
cpp/wedpr-transport/sdk-wrapper/python/bindings/utils/tests/test_lib_loader.py
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,12 @@ | ||
# -*- coding: utf-8 -*- | ||
import unittest | ||
|
||
|
||
class TestLibLoader(unittest.TestCase): | ||
def test_load_lib(self): | ||
from utils.lib_loader import LibLoader | ||
_wedpr_python_transport = LibLoader.load_lib() | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.