targodan / jupyter-swi-prolog

A Jupyter Kernel for SWI-Prolog
MIT License
24 stars 6 forks source link

Finding libswipl on macOS and other unixen #11

Open rljacobson opened 4 years ago

rljacobson commented 4 years ago

If swipl is accessible from a shell, executing swipl --dump-runtime-variables will dump the SWIPL runtime variables:

$ swipl --dump-runtime-variables
PLBASE="/usr/local/Cellar/swi-prolog/8.0.2_2/libexec/lib/swipl";
PLARCH="x86_64-darwin";
PLBITS="64";
PLVERSION="80002";
PLSOEXT="so";
PLSOPATH="DYLD_LIBRARY_PATH";
PLLIBDIR="/usr/local/Cellar/swi-prolog/8.0.2_2/libexec/lib/swipl/lib/x86_64-darwin";
PLLIB="-lswipl";
PLSHARED="yes";
PLTHREADS="yes";

You can see that on my Mac Homebrew has installed the libswipl.dylib to /usr/local/Cellar/swi-prolog/8.0.2_2/libexec/lib/swipl/lib/x86_64-darwin.

Additionally, setting one of the environment variables jupyter-swi-prolog looks for should work but appears to have a bug:

[I 16:10:56.045 LabApp] KernelRestarter: restarting kernel (4/5), new random ports
[FATAL ERROR: at Tue Jun  2 16:10:56 2020
    Could not find system resources]
Traceback (most recent call last):
  File "/usr/local/bin/jswiplkernel", line 5, in <module>
    from jswipl.jupyter import main
  File "/usr/local/lib/python3.7/site-packages/jswipl/jupyter.py", line 1, in <module>
    from . import swipl
  File "/usr/local/lib/python3.7/site-packages/jswipl/swipl.py", line 1, in <module>
    from pyswip import Prolog
  File "/usr/local/lib/python3.7/site-packages/pyswip/__init__.py", line 29, in <module>
    from pyswip.prolog import Prolog
  File "/usr/local/lib/python3.7/site-packages/pyswip/prolog.py", line 28, in <module>
    from pyswip.core import *
  File "/usr/local/lib/python3.7/site-packages/pyswip/core.py", line 568, in <module>
    (_path, SWI_HOME_DIR) = _findSwipl()
  File "/usr/local/lib/python3.7/site-packages/pyswip/core.py", line 420, in _findSwipl
    (path, swiHome) = _findSwiplMacOSHome()
  File "/usr/local/lib/python3.7/site-packages/pyswip/core.py", line 349, in _findSwiplMacOSHome
    (path_res, back_path) = walk(path, name)
ValueError: too many values to unpack (expected 2)

I guess I'm describing two things:

  1. Feature request: Add an additional heuristic to find the swipl library using the output of swipl --dump-runtime-variables.
  2. Bug report: There seems to be an issue with how the _findSwiplMacOSHome function walks the directory tree.

I personally am not able to work on these right now, unfortunately, but thought I would record them here in case someone else will be.