Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Revert some of the changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasdiez committed Nov 12, 2020
1 parent d9f36dc commit 94e20c7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
28 changes: 12 additions & 16 deletions src/sage/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions src/sage/libs/gap/util.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 4 additions & 5 deletions src/sage/libs/singular/singular.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 94e20c7

Please sign in to comment.