diff --git a/src/sage/env.py b/src/sage/env.py index 993271769e9..44c41fa5cf5 100644 --- a/src/sage/env.py +++ b/src/sage/env.py @@ -206,7 +206,7 @@ def var(key, *fallbacks, **kwds): var('SAGE_IMPORTALL', 'yes') -def _get_shared_lib_path(libname, *additional_libnames) -> Optional[Path]: +def _get_shared_lib_path(libname, *additional_libnames) -> Optional[str]: """ Return the full path to a shared library file installed in ``$SAGE_LOCAL/lib`` or the directories associated with the @@ -251,7 +251,7 @@ def _get_shared_lib_path(libname, *additional_libnames) -> Optional[Path]: # Later down we take the first matching DLL found, so search # SAGE_LOCAL first so that it takes precedence search_directories = [ - get_sage_local() / 'bin', + _get_sage_local() / 'bin', Path(sysconfig.get_config_var('BINDIR')), ] # Note: The following is not very robust, since if there are multible @@ -265,7 +265,7 @@ def _get_shared_lib_path(libname, *additional_libnames) -> Optional[Path]: else: ext = 'so' - search_directories = [get_sage_local() / 'lib'] + search_directories = [_get_sage_local() / 'lib'] libdir = sysconfig.get_config_var('LIBDIR') if libdir is not None: libdir = Path(libdir_str) @@ -281,26 +281,22 @@ def _get_shared_lib_path(libname, *additional_libnames) -> Optional[Path]: for pattern in patterns: path = next(directory.glob(pattern), None) if path is not None: - return path.resolve() + return str(path.resolve()) # Just return None if no files were found return None -def get_sage_local() -> Path: +def _get_sage_local() -> Path: return Path(SAGE_LOCAL) -def get_singular_lib_path() -> Optional[Path]: - """ - Return the location of the singular shared object. - """ - # On Debian it's libsingular-Singular so try that as well - return _get_shared_lib_path('Singular', 'singular-Singular') +# locate singular shared object +# On Debian it's libsingular-Singular so try that as well +SINGULAR_SO = _get_shared_lib_filename('Singular', 'singular-Singular') +var('SINGULAR_SO', SINGULAR_SO) -def get_gap_lib_path() -> Optional[Path]: - """ - Return the location of the libgap shared object. - """ - return _get_shared_lib_path('gap', '') +# locate libgap shared object +GAP_SO = _get_shared_lib_filename('gap','') +var('GAP_SO', GAP_SO) # post process if ' ' in DOT_SAGE: diff --git a/src/sage/libs/gap/util.pyx b/src/sage/libs/gap/util.pyx index ac052da85af..b4e868ea32f 100644 --- a/src/sage/libs/gap/util.pyx +++ b/src/sage/libs/gap/util.pyx @@ -229,8 +229,7 @@ cdef initialize(): # this isn't portable cdef void* handle - from sage.env import get_gap_lib_path - libgapname = str_to_bytes(str(get_gap_lib_path())) + libgapname = str_to_bytes(sage.env.GAP_SO) handle = dlopen(libgapname, RTLD_NOW | RTLD_GLOBAL) if handle is NULL: raise RuntimeError( diff --git a/src/sage/libs/singular/singular.pyx b/src/sage/libs/singular/singular.pyx index 78d83f12d49..f5440ba944b 100644 --- a/src/sage/libs/singular/singular.pyx +++ b/src/sage/libs/singular/singular.pyx @@ -768,19 +768,18 @@ cdef init_libsingular(): cdef void *handle = NULL - from sage.env import get_singular_lib_path - singular_path = get_singular_lib_path() - if singular_path is None: + from sage.env import SINGULAR_SO + if not SINGULAR_SO or not os.path.exists(SINGULAR_SO): raise RuntimeError( "libSingular not found--a working Singular install " "is required for Sage to work") - lib = str_to_bytes(str(singular_path), FS_ENCODING, "surrogateescape") + lib = str_to_bytes(str(SINGULAR_SO), FS_ENCODING, "surrogateescape") handle = dlopen(lib, RTLD_GLOBAL|RTLD_LAZY) if not handle: err = dlerror() - raise ImportError(f"cannot load Singular library from {singular_path} ({err})") + raise ImportError(f"cannot load Singular library from {SINGULAR_SO} ({err})") # load SINGULAR siInit(lib)