From 9a0cf827b071b73487e5f2504e5c55ada4a49fd1 Mon Sep 17 00:00:00 2001 From: Alexander Pivovarov Date: Mon, 14 Dec 2020 14:47:53 -0800 Subject: [PATCH] Install universal dlr if libdlr.so is not found (#310) --- python/dlr/libpath.py | 26 +++++++++++--------------- python/setup.py | 38 ++++++++++++++++++++++---------------- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/python/dlr/libpath.py b/python/dlr/libpath.py index e0e397697..02cf7e80c 100644 --- a/python/dlr/libpath.py +++ b/python/dlr/libpath.py @@ -10,24 +10,20 @@ class DLRLibraryNotFound(Exception): pass -def find_lib_path(model_path=None, use_default_dlr=True, logger=None, setup=False): +def find_lib_path(model_path=None, use_default_dlr=True, logger=None): """Find the path to DLR dynamic library files.""" curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) - if setup: - # Only look in build directory when installing or building wheel. - dll_paths = [os.path.join(curr_path, '../../build/lib/')] - else: - # Prioritize library in system path over the current_path. - dll_paths = [os.path.join(sys.prefix, 'dlr'), - os.path.join(sys.prefix, 'local', 'dlr'), - os.path.join(sys.exec_prefix, 'local', 'dlr'), - os.path.join(os.path.expanduser('~'), '.local', 'dlr'), - os.path.join(curr_path, '../../lib/'), - os.path.join(curr_path, '../../build/lib/'), - os.path.join(curr_path, './lib/'), - os.path.join(curr_path, './build/lib/'), - curr_path] + # Prioritize library in system path over the current_path. + dll_paths = [os.path.join(sys.prefix, 'dlr'), + os.path.join(sys.prefix, 'local', 'dlr'), + os.path.join(sys.exec_prefix, 'local', 'dlr'), + os.path.join(os.path.expanduser('~'), '.local', 'dlr'), + os.path.join(curr_path, '../../lib/'), + os.path.join(curr_path, '../../build/lib/'), + os.path.join(curr_path, './lib/'), + os.path.join(curr_path, './build/lib/'), + curr_path] if sys.platform == 'win32': if platform.architecture()[0] == '64bit': diff --git a/python/setup.py b/python/setup.py index cbb107c3f..926b51c7e 100644 --- a/python/setup.py +++ b/python/setup.py @@ -6,27 +6,32 @@ from setuptools.dist import Distribution from platform import system -# Universal build will only contain python files, and libdlr.so is expected to be found in compiled -# model artifact folder. -is_universal = "--universal" in sys.argv +if "--universal" in sys.argv: + raise ValueError("Creating py2.py3 wheels is not supported") CURRENT_DIR = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) -if not is_universal: - # Use libpath.py to locate libdlr.so - LIBPATH_PY = os.path.abspath('./dlr/libpath.py') - LIBPATH = {'__file__': LIBPATH_PY} - exec(compile(open(LIBPATH_PY, "rb").read(), LIBPATH_PY, 'exec'), - LIBPATH, LIBPATH) - LIB_PATH = [os.path.relpath(LIBPATH['find_lib_path'](setup=True), CURRENT_DIR)] +BUILD_DIR = "../build/lib/" - if not LIB_PATH: - raise RuntimeError('libdlr.so missing. Please compile first using CMake') - include_package_data = True - data_files = [('dlr', LIB_PATH)] +libname = 'libdlr.so' +if sys.platform == 'win32': + libname = 'dlr.dll' +elif sys.platform == 'darwin': + libname = 'libdlr.dylib' + +LIB_PATH = os.path.join(BUILD_DIR, libname) + +if os.path.exists(LIB_PATH): + print("Found", libname, "at", LIB_PATH) + include_package_data = True + data_files = [('dlr', [LIB_PATH,])] else: - include_package_data = False - data_files = None + print(libname, "is not found!") + print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") + print("!!! Preparing universal py3 version of DLR !!!") + print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") + include_package_data = False + data_files = None # fetch meta data METADATA_PY = os.path.abspath("./dlr/metadata.py") @@ -62,4 +67,5 @@ "Topic :: Utilities", "License :: OSI Approved :: Apache Software License", ], + python_requires = '>=3.5', )