From d2da55463f4d2ea76c5eb621a4d54a5e7d31ed40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Tue, 23 Oct 2012 10:18:24 +0100 Subject: [PATCH] more python fixes. --- packages/pyswip/pyswip/core.py | 23 +++++++++++++++-------- packages/pyswip/python.pl | 6 +++++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/pyswip/pyswip/core.py b/packages/pyswip/pyswip/core.py index 901f763ad..04960e208 100644 --- a/packages/pyswip/pyswip/core.py +++ b/packages/pyswip/pyswip/core.py @@ -61,14 +61,26 @@ def _findYap(): :raises ImportError: If we cannot guess the name of the library """ + # Now begins the guesswork + platform = sys.platform[:3] + + # use YAPLIBDIR first + path=os.getenv('YAPLIBDIR') + if path is not None: + if platform == 'lin': + name = 'libYap.so' + elif platform == 'dar': + name = 'libYap.dylib' + path = os.path.join(path, name) + if os.path.exists(path): + return path + # No matter what the platform is, the first try should alway be # find_library. path = find_library('Yap') # or find_library('swipl') or find_library('pl') if path is not None: return path - # Now begins the guesswork - platform = sys.platform[:3] if platform == 'win': # In Windows, we have the default installer path and # the registry to look @@ -140,12 +152,6 @@ def _findYap(): if os.path.exists(path): return path - # unix in general - path=os.getenv('YAPLIBDIR') - path = os.path.join(path, name) - if os.path.exists(path): - return path - # Last resource: see if executable is on the path try: # try to get library path from swipl executable. cmd = Popen(['yap', '-dump-runtime-variables'], stdout=PIPE) @@ -196,6 +202,7 @@ c_void_p = POINTER(c_void) # Load the library path = _findYap() _fixWindowsPath(path) +print path _lib = CDLL(path) # PySWIP constants diff --git a/packages/pyswip/python.pl b/packages/pyswip/python.pl index 8eb01576a..60b0ba9ce 100644 --- a/packages/pyswip/python.pl +++ b/packages/pyswip/python.pl @@ -46,7 +46,11 @@ python_command(Cmd) :- start_python :- use_foreign_library(foreign(python)), - init_python. + init_python, + python_command('import sys'), + unix(getcwd(Dir)), + atom_concat(['sys.path.append(\"',Dir,'\")'], Command), + python_command(Command). % done