Skip to content

Commit

Permalink
Bump version to 1.6.1; fix pylint and improving loadlibrary code; add…
Browse files Browse the repository at this point in the history
… more insights about testmatrix failures; restoring Dart for code coverage
  • Loading branch information
marco committed Nov 9, 2023
1 parent 30ff71b commit 36b6f4c
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 72 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ build/*
.kdev4
.vscode
.vscode/*
.venv

# Object files
*.o
Expand Down
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 3.18)
cmake_minimum_required(VERSION 3.17)
project(libscientific LANGUAGES C)
set(AUTHOR "Giuseppe Marco Randazzo")
set(VERSION_MAJOR 1)
set(VERSION_MINOR 6)
set(VERSION_PATCH 0)
set(VERSION_PATCH 1)
configure_file(src/scientificconfig.h.in scientificconfig.h)

if(NOT CMAKE_BUILD_TYPE)
Expand Down Expand Up @@ -68,8 +68,8 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")

if(cmake_build_type_tolower STREQUAL "debug")
# include(Dart)
# cmake_policy(SET CMP0145 OLD)
include(Dart)
cmake_policy(SET CMP0145 OLD)
enable_testing()
endif()

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ make -j # on Linux
mingw32-make # on Windows
cd ../src/python_bindings/
OSX: python3 setup.py bdist_wheel --plat-name macosx-14-arm64
# pip3 debug --verbose to get the compatible tags
OSX: python3 setup.py bdist_wheel --plat-name macosx-14-0-arm64
Linux: python3 setup.py bdist_wheel --plat-name manylinux1_x86_64
Win32: python3 setup.py bdist_wheel --plat-name win_amd64
```
Expand Down
27 changes: 25 additions & 2 deletions src/python_bindings/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,35 @@ Compile from source
cd libscientific
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/ ..
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/ ..
make -j5
sudo make install
cd ../src/python_bindings
python3 setup.py install --user

Create portable linux/osx python package
----------------------------------------
cd libscientific
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DPORTABLE_PYTHON_PACKAGE=True ..
make -j5
sudo make install
cd ../src/python_bindings
On Linux: python3 setup.py bdist_wheel --plat-name manylinux1_x86_64
On OSX: python3 setup.py bdist_wheel --plat-name macosx-14-0-arm64


Create portable Windows python package (MSYS2/Mingw64)
------------------------------------------------------
mkdir build
cd build
cmake -G "MinGW Makefiles" -CMAKE_BUILD_TYPE=Release -DPORTABLE_PYTHON_PACKAGE=True ..
mingw32-make
cd ../src/python_bindings/
python3 setup.py bdist_wheel --plat-name win_amd64

N.B.: Use pip3 debug --verbose to get the compatible platform name tags

Homebrew OSX
------------
Expand Down Expand Up @@ -52,4 +75,4 @@ However some recommendations before open a Pull Request:
* A test example is necessary.

Probably your code will be integrated but some quality controls and goals
have to be respected.
have to be respected.
2 changes: 1 addition & 1 deletion src/python_bindings/libscientific/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@
from . import clustering

# __version__ = info.Scientific().__version__
__version__ = "1.6.0"
__version__ = "1.6.1"
81 changes: 41 additions & 40 deletions src/python_bindings/libscientific/loadlibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
import pathlib
import ctypes

def load_library_for_nt():
"""Load the libscientific library for NT systems
"""
try:
lib_path = f'{pathlib.Path(__file__).parent}'
_ = ctypes.CDLL(f'{lib_path}/libsqlite3-0.dll', winmode=0)
_ = ctypes.CDLL(f'{lib_path}/libwinpthread-1.dll', winmode=0)
return ctypes.CDLL(f'{lib_path}/libscientific.dll', winmode=0)
except TypeError:
return None

def get_posix_library():
"""Find the path to the libscientific POSIX library.
Expand All @@ -39,6 +50,34 @@ def get_posix_library():
return path
return None

def load_library_for_posix():
"""Load the libscientific library for posix systems
"""
lib_path = get_posix_library()
if lib_path is not None:
return ctypes.cdll.LoadLibrary(lib_path)
try:
lib_path = str(pathlib.Path(__file__).parent.absolute())
if os.uname()[0] == "Darwin":
return ctypes.CDLL(f'{lib_path}/libscientific.dylib')
# else load library for linux systems
for i in range(3, 5):
if pathlib.Path(f'{lib_path}/libgfortran.so.{i}').is_file():
_ = ctypes.CDLL(f'{lib_path}/libgfortran.so.{i}')
break
_ = ctypes.CDLL(f'{lib_path}/libquadmath.so.0.0.0')
_ = ctypes.CDLL(f'{lib_path}/libblas.so')
_ = ctypes.CDLL(f'{lib_path}/liblapack.so')
return ctypes.CDLL(f'{lib_path}/libscientific.so')
except OSError as err:
msg = f"Don't know how to load libscientific on {os.name}\n"
msg += "Please install the library directly "
msg += "from its source code "
msg += "https://github.com/gmrandazzo/libscientific"
msg += "\nIf the library is installed please "
msg += "check/specify the location in LD_LIBRARY_PATH "
msg += "with export LD_LIBRARY_PATH=<path libscientific>"
raise RuntimeError(msg) from err

def load_libscientific_library():
"""Load the libscientific library dynamically.
Expand All @@ -53,44 +92,6 @@ def load_libscientific_library():
RuntimeError
If the library cannot be loaded or the platform is not supported.
"""
lsci = None
if os.name == "nt":
lib_path = f'{pathlib.Path(__file__).parent}'
try:
_ = ctypes.CDLL(f'{lib_path}/libsqlite3-0.dll', winmode=0)
_ = ctypes.CDLL(f'{lib_path}/libwinpthread-1.dll', winmode=0)
lsci = ctypes.CDLL(f'{lib_path}/libscientific.dll', winmode=0)
except TypeError:
lsci = ctypes.CDLL(f'{lib_path}/libscientific.dll', winmode=0)

elif os.name == "posix":
lib_path = get_posix_library()
if lib_path is not None:
lsci = ctypes.cdll.LoadLibrary(lib_path)
else:
try:
lib_path = str(pathlib.Path(__file__).parent.absolute())
if os.uname()[0] == "Darwin":
lsci = ctypes.CDLL(f'{lib_path}/libscientific.dylib')
else:
for i in range(3, 5):
if pathlib.Path(f'{lib_path}/libgfortran.so.{i}').is_file():
_ = ctypes.CDLL(f'{lib_path}/libgfortran.so.{i}')
break
_ = ctypes.CDLL(f'{lib_path}/libquadmath.so.0.0.0')
_ = ctypes.CDLL(f'{lib_path}/libblas.so')
_ = ctypes.CDLL(f'{lib_path}/liblapack.so')
lsci = ctypes.CDLL(f'{lib_path}/libscientific.so')
except OSError as err:
msg = "Please install sqlite3 and lapack library "
msg += "if you want to use the binary library in this package.\n"
msg += "Alternativelly you can install the library directly "
msg += "from its source code from here "
msg += "https://github.com/gmrandazzo/libscientific"
msg += "\nIf the library is installed please "
msg += "check/specify the location in LD_LIBRARY_PATH "
msg += "with export LD_LIBRARY_PATH=<path libscientific>"
raise RuntimeError(msg) from err
else:
raise RuntimeError(f"Don't know how to load library on {os.name}")
return lsci
return load_library_for_nt()
return load_library_for_posix()
2 changes: 1 addition & 1 deletion src/python_bindings/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name="libscientific",
version="1.6.0",
version="1.6.1",
packages=["libscientific"],
package_data={"": [library]},
platforms=[arch],
Expand Down
Loading

0 comments on commit 36b6f4c

Please sign in to comment.