open-lasso-python / lasso-python

Home of the open-source CAE library lasso-python 🐍
BSD 3-Clause "New" or "Revised" License
50 stars 12 forks source link

Compiled Femzip Library References #44

Open Vortex-CAE opened 7 months ago

Vortex-CAE commented 7 months ago

Compiling with module with Pyinstaller breaks the Femzip Library References, requiring /lasso/femzip/*.dll's and .so's. to be packaged alongside the exe.

Additional path update allows library files to be explicitly added during compilation bundled in root of the EXE & referenced.

class FemzipAPI: """FemzipAPI contains wrapper functions around the femzip library."""

_api: Union[None, CDLL] = None

@staticmethod
def load_dynamic_library(path: str) -> CDLL:
    """Load a library and check for correct execution

    Parameters
    ----------
    path: str
        path to the library

    Returns
    -------
    library: CDLL
        loaded library
    """

    # check executable rights
    if not os.access(path, os.X_OK) or not os.access(path, os.R_OK):
        if getattr( sys, 'frozen', False ):
            # running in a bundle
            path = os.path.join(sys._MEIPASS, os.path.basename(path))  
        os.chmod(path, os.stat(path).st_mode | stat.S_IEXEC | stat.S_IREAD)
        if not os.access(path, os.X_OK) or not os.access(path, os.R_OK):
            err_msg = "Library '{0}' is not executable and couldn't change execution rights."
            raise RuntimeError(err_msg.format(path))

    return CDLL(path)
MatthieuDebray commented 2 months ago

Thanks. I'm confirmed it works correctly. @codie3611 , you think you will implement it ?

codie3611 commented 2 months ago

Yeah should find time this weekend