From df15dd14a640f594148c136e2984be1348222e4c Mon Sep 17 00:00:00 2001 From: Steffy-zxf <48793257+Steffy-zxf@users.noreply.github.com> Date: Thu, 12 Mar 2020 14:46:24 +0800 Subject: [PATCH] fix load module in py2 (#441) * fix load module in py2 --- paddlehub/module/manager.py | 5 +++-- paddlehub/module/module.py | 2 +- paddlehub/module/nlp_module.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/paddlehub/module/manager.py b/paddlehub/module/manager.py index 5714fb4b..6509f7ae 100644 --- a/paddlehub/module/manager.py +++ b/paddlehub/module/manager.py @@ -74,8 +74,9 @@ class LocalModuleManager(object): _item = _module.__dict__[_item] _file = os.path.realpath( sys.modules[_item.__module__].__file__) - if issubclass(_item, - hub.Module) and _file == module_file: + if issubclass( + _item, + hub.Module) and _file.startwith(module_file): version = _item._version break sys.path.pop(0) diff --git a/paddlehub/module/module.py b/paddlehub/module/module.py index 17bfa6bf..196b43fd 100644 --- a/paddlehub/module/module.py +++ b/paddlehub/module/module.py @@ -194,7 +194,7 @@ class Module(object): _file = os.path.realpath(sys.modules[_item.__module__].__file__) _module_path = os.path.realpath( os.path.join(directory, "module.py")) - if issubclass(_item, Module) and _file == _module_path: + if issubclass(_item, Module) and _file.startswith(_module_path): user_module = _item(directory=directory, **kwargs) break sys.path.pop(0) diff --git a/paddlehub/module/nlp_module.py b/paddlehub/module/nlp_module.py index 632dbfbc..d29f455c 100644 --- a/paddlehub/module/nlp_module.py +++ b/paddlehub/module/nlp_module.py @@ -124,8 +124,8 @@ class NLPPredictionModule(NLPBaseModule): Run as a command """ self.parser = argparse.ArgumentParser( - description='Run the %s module.' % self.module_name, - prog='hub run %s' % self.module_name, + description='Run the %s module.' % self.name, + prog='hub run %s' % self.name, usage='%(prog)s', add_help=True) -- GitLab