snapshot: capture local workspace state (20251019-132103)

This commit is contained in:
Repo Bot
2025-10-19 13:21:07 +02:00
parent d22184cf70
commit 7d5005ce4e
8 changed files with 344 additions and 33 deletions

View File

@@ -112,28 +112,55 @@ class Refifc(object):
# Sauvegardez le répertoire courant pour pouvoir y revenir plus tard
self.original_directory = os.getcwd()
# Determine candidate directories for the native library. Prefer
# app/ipm/lib/<platform> if present, otherwise fall back to the
# package directory (for compatibility with older layouts).
# Determine candidate directories for the native library.
# Prefer central repo-level folders:
# <repo_root>/libs/dll (Windows)
# <repo_root>/libs/so (Linux)
# Fall back to package-local `app/ipm/lib/<platform>` or the package dir.
package_dir = os.path.dirname(os.path.abspath(__file__))
platform_dir = os.path.join(package_dir, 'lib', 'windows' if os.name == 'nt' else 'linux')
dll_directory = platform_dir if os.path.isdir(platform_dir) else package_dir
# repo root is two levels above app/ipm
repo_root = os.path.abspath(os.path.join(package_dir, '..', '..'))
preferred_windows = os.path.join(repo_root, 'libs', 'dll')
preferred_linux = os.path.join(repo_root, 'libs', 'so')
# Change working directory to the chosen directory while loading
os.chdir(dll_directory)
if os.name == 'nt':
candidate_dirs = [preferred_windows]
else:
candidate_dirs = [preferred_linux]
# Try to load the native library from the chosen directory; if that
# fails, attempt to load by name (for system-installed libs) and
# otherwise raise the original exception.
try:
self.lib = ctypes.cdll.LoadLibrary(os.path.join(dll_directory, REFIFC_LIB_NAME))
except OSError:
# also consider the package-local lib/<platform> layout as fallback
candidate_dirs.append(os.path.join(package_dir, 'lib', 'windows' if os.name == 'nt' else 'linux'))
candidate_dirs.append(package_dir)
# Try each candidate directory in order until we can load the library.
load_exc = None
for dll_directory in candidate_dirs:
if not dll_directory:
continue
try:
if os.path.isdir(dll_directory):
# temporarily change cwd to help some LoadLibrary behaviors
os.chdir(dll_directory)
self.lib = ctypes.cdll.LoadLibrary(os.path.join(dll_directory, REFIFC_LIB_NAME))
else:
# attempt to load directly by path anyway
self.lib = ctypes.cdll.LoadLibrary(os.path.join(dll_directory, REFIFC_LIB_NAME))
load_exc = None
break
except OSError as e:
load_exc = e
# try next candidate
continue
# if we failed to load from candidates, try loading by name (system path)
if load_exc is not None:
try:
self.lib = ctypes.cdll.LoadLibrary(REFIFC_LIB_NAME)
except Exception as e:
# Restore cwd before raising
load_exc = None
except Exception:
# restore cwd before raising
os.chdir(self.original_directory)
raise
raise load_exc
ctypes_refrig_name = refrig_name
if os.name == 'posix':
@@ -145,7 +172,8 @@ class Refifc(object):
try:
ctypes.CDLL(os.path.join(dll_directory, REFIFC_LIB_NAME))
except OSError:
print(f"Refrig {refrig_name} not found, please check!")
# don't raise here; letting the subsequent load/check handle missing refrigerant libs
print(f"Refrig {refrig_name} not found in {dll_directory}, please check!")
func = self.lib.refdll_load
func.restype = POINTER(c_void_p)