import os
import os.path
import sys
import platform
import logging
from pathlib import Path
try:
import wolf_libs
except ImportError:
print("wolf_libs not found. Please install the wolf-libs package -- pip install wolf-libs.")
sys.exit(1)
try:
import wolf_libs_fortran
except ImportError:
print("wolf_libs_fortran not found. Please install the wolf-libs-fortran package -- pip install wolf-libs-fortran.")
sys.exit(1)
[docs]
def _add_path():
_root_dir = os.path.dirname(os.path.realpath(__file__))
# manual specify list of dll directories, with paths relative to _root_dir
_dll_dirs = ['libs', 'shaders']
# add wolf_libs path to __dll_dirs
if wolf_libs.__path__:
_dll_dirs.insert(0, os.path.join(wolf_libs.__path__[0]))
# copy all dll from wolf_libs_fortran to wolf_libs directory, to ensure they are found by the system when importing wolf_libs
if wolf_libs_fortran.__path__:
for file in os.listdir(wolf_libs_fortran.__path__[0]):
if file.endswith('.dll'):
src_file = os.path.join(wolf_libs_fortran.__path__[0], file)
dst_file = os.path.join(wolf_libs.__path__[0], file)
# copy if not present or more recent
if not os.path.exists(dst_file) or os.path.getmtime(src_file) > os.path.getmtime(dst_file):
try:
from shutil import copyfile
copyfile(src_file, dst_file)
except Exception as e:
print(f"Error copying {src_file} to {dst_file}: {e}")
print("Please ensure that the wolf-libs-fortran package is correctly installed and that you have permission to read the source files and write to the destination directory.")
sys.exit(1)
if platform.system() == 'Windows':
os.environ.setdefault('PATH', '')
paths = os.environ['PATH'].split(';')
for x in _dll_dirs:
x = os.path.join(_root_dir, x)
if os.path.isdir(x) and x not in paths:
paths = [x] + paths
os.environ['PATH'] = ';'.join(paths)
_add_path()
# Check if R and make/Cmake are available, and if so, add their paths to the system PATH
try:
from wolfhece.apps.check_install import _check_executables
[docs]
ret = _check_executables()
except Exception as e:
logging.error("Error checking installations: " + str(e))