Skip to content

Commit

Permalink
Install universal dlr if libdlr.so is not found (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
apivovarov authored Dec 14, 2020
1 parent ee59be6 commit 9a0cf82
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 31 deletions.
26 changes: 11 additions & 15 deletions python/dlr/libpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
38 changes: 22 additions & 16 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -62,4 +67,5 @@
"Topic :: Utilities",
"License :: OSI Approved :: Apache Software License",
],
python_requires = '>=3.5',
)

0 comments on commit 9a0cf82

Please sign in to comment.