Skip to content

Commit

Permalink
fix library for other OS
Browse files Browse the repository at this point in the history
  • Loading branch information
AWehrhahn committed Dec 8, 2021
1 parent 0769464 commit 642a3cc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 16 deletions.
15 changes: 6 additions & 9 deletions .github/workflows/make.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,12 @@ jobs:
- run: ls lib
- run: zip -r ${{ matrix.container }}-${{ matrix.name }} lib share

- run: pip3 install -r test/requirements.txt
# - run: pip3 install -r cython/requirements.txt
# - run: |
# cd cython/
# cp -r ../lib lib
# cp -r ../share share
# python3 setup.py build_ext --inplace
# pip3 install .
# cd ..
- name: Install Requirements
run: |
pip3 install -r test/requirements.txt
cd pymodule
python3 setup.py build_ext --inplace
- run: python3 -m pytest

- name: Upload Debug Spectrum
Expand Down
34 changes: 34 additions & 0 deletions pymodule/libtools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from os.path import dirname, join, abspath
import platform

def get_lib_name():
"""Get the name of the sme C library"""
system = platform.system().lower()

if system == "windows":
return "libsme-5.dll"

arch = platform.machine()
bits = 64 # platform.architecture()[0][:-3]

return "sme_synth.so.{system}.{arch}.{bits}".format(
system=system, arch=arch, bits=bits
)


def get_lib_directory():
if platform.system() in ["Windows"]:
dirpath = "bin"
else:
# For Linux/MacOS
dirpath = "lib"
return dirpath


def get_full_libfile():
"""Get the full path to the sme C library"""
localdir = dirname(dirname(__file__))
libfile = get_lib_name()
dirpath = get_lib_directory()
libfile = join(localdir, dirpath, libfile)
return libfile
10 changes: 3 additions & 7 deletions pymodule/smelib.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@
import logging

from ctypes import cdll
from .libtools import get_full_libfile

# Load the library
libdir = abspath(join(dirname(__file__), "../lib"))
libfile = join(libdir, "libsme.so")

try:
os.add_dll_directory(libdir)
except AttributeError:
cdll.LoadLibrary(libfile)
libfile = get_full_libfile()
cdll.LoadLibrary(libfile)

from . import _smelib

Expand Down

0 comments on commit 642a3cc

Please sign in to comment.