From e4a59f9ec6685534b03474cbcfe9395d601516e2 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Thu, 11 Jun 2020 07:23:23 +0200 Subject: Add distributor the right to add dll to the package --- src/python/CMakeLists.txt | 5 ++++- src/python/gudhi/__init__.py.in | 3 +++ src/python/gudhi/_distributor_init.py | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/python/gudhi/_distributor_init.py (limited to 'src/python') diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index fee6b6f5..b35c8de7 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -235,8 +235,11 @@ if(PYTHONINTERP_FOUND) file(COPY "gudhi/point_cloud" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/gudhi") file(COPY "gudhi/weighted_rips_complex.py" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/gudhi") - # Other .py files + # Some files for pip package file(COPY "introduction.rst" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/") + file(COPY "gudhi/_distributor_init.py" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/gudhi") + file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/gudhi/.libs") + message(" o o o ${CMAKE_CURRENT_BINARY_DIR}/gudhi/.libs") add_custom_command( OUTPUT gudhi.so diff --git a/src/python/gudhi/__init__.py.in b/src/python/gudhi/__init__.py.in index 79e12fbc..e4198dcf 100644 --- a/src/python/gudhi/__init__.py.in +++ b/src/python/gudhi/__init__.py.in @@ -10,6 +10,9 @@ from importlib import import_module from sys import exc_info +# Allow distributors to run custom init code +from . import _distributor_init + __author__ = "GUDHI Editorial Board" __copyright__ = "Copyright (C) 2016 Inria" __license__ = "https://gudhi.inria.fr/licensing/" diff --git a/src/python/gudhi/_distributor_init.py b/src/python/gudhi/_distributor_init.py new file mode 100644 index 00000000..0ed451f9 --- /dev/null +++ b/src/python/gudhi/_distributor_init.py @@ -0,0 +1,18 @@ +''' +Helper to preload windows dlls to prevent dll not found errors. +Once a DLL is preloaded, its namespace is made available to any subsequent DLL. +''' +import os +from ctypes import WinDLL +import glob +if os.name == 'nt': + # convention for storing / loading the DLL from gudhi/.libs/, if present + try: + basedir = os.path.dirname(__file__) + except: + pass + else: + libs_dir = os.path.abspath(os.path.join(basedir, '.libs')) + if os.path.isdir(libs_dir): + for filename in glob.glob(os.path.join(libs_dir, '*dll')): + WinDLL(os.path.abspath(filename)) -- cgit v1.2.3