From 73c2f1821b2f245f90b16229589a67de75e6009c Mon Sep 17 00:00:00 2001 From: Daniel Nouri Date: Tue, 15 Nov 2016 23:40:33 -0500 Subject: [PATCH] Py3K compatiblity --- binding/python/multiverso/__init__.py | 4 ++-- binding/python/multiverso/api.py | 6 +++--- binding/python/multiverso/tables.py | 6 +++--- binding/python/multiverso/utils.py | 24 +++++++++++++----------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/binding/python/multiverso/__init__.py b/binding/python/multiverso/__init__.py index 46a65e3..2ea20b2 100644 --- a/binding/python/multiverso/__init__.py +++ b/binding/python/multiverso/__init__.py @@ -1,5 +1,5 @@ #!/usr/bin/env python # coding:utf8 -from api import init, shutdown, barrier, workers_num, worker_id, server_id, is_master_worker -from tables import ArrayTableHandler, MatrixTableHandler +from .api import init, shutdown, barrier, workers_num, worker_id, server_id, is_master_worker +from .tables import ArrayTableHandler, MatrixTableHandler diff --git a/binding/python/multiverso/api.py b/binding/python/multiverso/api.py index c85aab3..849e51b 100644 --- a/binding/python/multiverso/api.py +++ b/binding/python/multiverso/api.py @@ -2,7 +2,7 @@ # coding:utf8 import ctypes -from utils import Loader +from .utils import Loader import numpy as np @@ -26,9 +26,9 @@ def init(sync=False): `barrier` and `get` with the argument `sync` set to `True` to sync the processes. ''' - args = [""] # the first argument will be ignored. So we put a placeholder here + args = [b""] # the first argument will be ignored. So we put a placeholder here if sync: - args.append("-sync=true") + args.append(b"-sync=true") n = len(args) args_type = ctypes.c_char_p * n mv_lib.MV_Init(ctypes.pointer(ctypes.c_int(n)), args_type(*[ctypes.c_char_p(arg) for arg in args])) diff --git a/binding/python/multiverso/tables.py b/binding/python/multiverso/tables.py index 55be5b6..4ec312b 100644 --- a/binding/python/multiverso/tables.py +++ b/binding/python/multiverso/tables.py @@ -2,10 +2,10 @@ # coding:utf8 import ctypes -from utils import Loader -from utils import convert_data +from .utils import Loader +from .utils import convert_data import numpy as np -import api +from . import api mv_lib = Loader.get_lib() diff --git a/binding/python/multiverso/utils.py b/binding/python/multiverso/utils.py index bae647f..8094f6d 100644 --- a/binding/python/multiverso/utils.py +++ b/binding/python/multiverso/utils.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # coding:utf8 +from __future__ import print_function + import ctypes import os import platform @@ -23,31 +25,31 @@ class Loader(object): if platform.system() == "Windows": mv_lib_path = find_library("Multiverso") if mv_lib_path is None: - print "* Fail to load Multiverso.dll from the windows $PATH."\ + print("* Fail to load Multiverso.dll from the windows $PATH."\ "Because Multiverso.dll can not be found in the $PATH "\ - "directories. Go on loading Multiverso from the package." + "directories. Go on loading Multiverso from the package.") else: return mv_lib_path mv_lib_path = os.path.join(PACKAGE_PATH, "Multiverso.dll") if not os.path.exists(mv_lib_path): - print "* Fail to load Multiverso.dll from the package. Because"\ - " the file " + mv_lib_path + " can not be found." + print("* Fail to load Multiverso.dll from the package. Because"\ + " the file " + mv_lib_path + " can not be found.") else: return mv_lib_path else: mv_lib_path = find_library("multiverso") if mv_lib_path is None: - print "* Fail to load libmultiverso.so from the system"\ + print("* Fail to load libmultiverso.so from the system"\ "libraries. Because libmultiverso.so can't be found in"\ - "library paths. Go on loading Multiverso from the package." + "library paths. Go on loading Multiverso from the package.") else: return mv_lib_path mv_lib_path = os.path.join(PACKAGE_PATH, "libmultiverso.so") if not os.path.exists(mv_lib_path): - print "* Fail to load libmultiverso.so from the package. Because"\ - " the file " + mv_lib_path + " can not be found." + print("* Fail to load libmultiverso.so from the package. Because"\ + " the file " + mv_lib_path + " can not be found.") else: return mv_lib_path return None @@ -56,10 +58,10 @@ class Loader(object): def load_lib(cls): mv_lib_path = cls._find_mv_path() if mv_lib_path is None: - print "Fail to load the multiverso library. Please make sure you"\ - " have installed multiverso successfully" + print("Fail to load the multiverso library. Please make sure you"\ + " have installed multiverso successfully") else: - print "Find the multiverso library successfully(%s)" % mv_lib_path + print("Find the multiverso library successfully(%s)" % mv_lib_path) return ctypes.cdll.LoadLibrary(mv_lib_path) @classmethod