From a61b5c3d5d277c6308f34753f4863abf6d7c440a Mon Sep 17 00:00:00 2001 From: wuzewu Date: Wed, 17 Apr 2019 10:14:40 +0800 Subject: [PATCH] Fix python2 compatibility issues --- paddlehub/commands/base_command.py | 2 +- paddlehub/commands/clear.py | 2 +- paddlehub/commands/download.py | 2 +- paddlehub/commands/help.py | 2 +- paddlehub/commands/hub.py | 12 ++++++------ paddlehub/commands/install.py | 2 +- paddlehub/commands/list.py | 2 +- paddlehub/commands/run.py | 2 +- paddlehub/commands/search.py | 2 +- paddlehub/commands/show.py | 2 +- paddlehub/commands/uninstall.py | 2 +- paddlehub/commands/version.py | 2 +- paddlehub/module/module.py | 9 ++++----- paddlehub/version.py | 4 ++-- 14 files changed, 23 insertions(+), 24 deletions(-) diff --git a/paddlehub/commands/base_command.py b/paddlehub/commands/base_command.py index 1d085259..96707cdb 100644 --- a/paddlehub/commands/base_command.py +++ b/paddlehub/commands/base_command.py @@ -62,5 +62,5 @@ class BaseCommand(object): def print_args(self): print_arguments(self.args) - def exec(self, argv): + def execute(self, argv): raise NotImplementedError("Base Command should not be execute!") diff --git a/paddlehub/commands/clear.py b/paddlehub/commands/clear.py index 645de3ff..a2103d85 100644 --- a/paddlehub/commands/clear.py +++ b/paddlehub/commands/clear.py @@ -54,7 +54,7 @@ class ClearCommand(BaseCommand): def cache_dir(self): return CACHE_HOME - def exec(self, argv): + def execute(self, argv): result = True total_file_size = 0 total_file_count = 0 diff --git a/paddlehub/commands/download.py b/paddlehub/commands/download.py index 8a06144f..b3b8a462 100644 --- a/paddlehub/commands/download.py +++ b/paddlehub/commands/download.py @@ -43,7 +43,7 @@ class DownloadCommand(BaseCommand): self.add_arg('--uncompress', bool, False, "uncompress the download package or not" ) # yapf: enable - def exec(self, argv): + def execute(self, argv): if not argv: print("ERROR: Please provide the model/module name\n") self.help() diff --git a/paddlehub/commands/help.py b/paddlehub/commands/help.py index 9534a95a..8b7e5f1d 100644 --- a/paddlehub/commands/help.py +++ b/paddlehub/commands/help.py @@ -30,7 +30,7 @@ class HelpCommand(BaseCommand): def get_all_commands(self): return BaseCommand.command_dict - def exec(self, argv): + def execute(self, argv): hub_command = BaseCommand.command_dict["hub"] help_text = "\n" help_text += "Usage:\n" diff --git a/paddlehub/commands/hub.py b/paddlehub/commands/hub.py index d338ef12..d2eef0bd 100644 --- a/paddlehub/commands/hub.py +++ b/paddlehub/commands/hub.py @@ -34,30 +34,30 @@ class HubCommand(BaseCommand): super(HubCommand, self).__init__(name) self.show_in_help = False - def exec(self, argv): + def execute(self, argv): logger.setLevel("NOLOG") if not argv: - help.command.exec(argv) + help.command.execute(argv) exit(1) return False sub_command = argv[0] if not sub_command in BaseCommand.command_dict: print("ERROR: unknown command '%s'" % sub_command) - help.command.exec(argv) + help.command.execute(argv) exit(1) return False command = BaseCommand.command_dict[sub_command] - return command.exec(argv[1:]) + return command.execute(argv[1:]) command = HubCommand.instance() def main(): - command.exec(sys.argv[1:]) + command.execute(sys.argv[1:]) if __name__ == "__main__": - command.exec(sys.argv[1:]) + command.execute(sys.argv[1:]) diff --git a/paddlehub/commands/install.py b/paddlehub/commands/install.py index 3387565c..c181f398 100644 --- a/paddlehub/commands/install.py +++ b/paddlehub/commands/install.py @@ -37,7 +37,7 @@ class InstallCommand(BaseCommand): add_help=False) #TODO(wuzewu): add --upgrade option - def exec(self, argv): + def execute(self, argv): if not argv: print("ERROR: Please specify a module name.\n") self.help() diff --git a/paddlehub/commands/list.py b/paddlehub/commands/list.py index 366aa594..44421b51 100644 --- a/paddlehub/commands/list.py +++ b/paddlehub/commands/list.py @@ -31,7 +31,7 @@ class ListCommand(BaseCommand): self.show_in_help = True self.description = "List all installed PaddleHub modules." - def exec(self, argv): + def execute(self, argv): all_modules = default_module_manager.all_modules() if utils.is_windows(): placeholders = [20, 40] diff --git a/paddlehub/commands/run.py b/paddlehub/commands/run.py index 70df85f7..c2cb939f 100644 --- a/paddlehub/commands/run.py +++ b/paddlehub/commands/run.py @@ -75,7 +75,7 @@ class RunCommand(BaseCommand): demo = "%s %s %s" % (entry, self.name, module.name) return demo - def exec(self, argv): + def execute(self, argv): if not argv: print("ERROR: Please specify a module name.\n") self.help() diff --git a/paddlehub/commands/search.py b/paddlehub/commands/search.py index c65c9ba6..73f59886 100644 --- a/paddlehub/commands/search.py +++ b/paddlehub/commands/search.py @@ -37,7 +37,7 @@ class SearchCommand(BaseCommand): usage='%(prog)s', add_help=False) - def exec(self, argv): + def execute(self, argv): if not argv: argv = ['.*'] diff --git a/paddlehub/commands/show.py b/paddlehub/commands/show.py index 82947781..990ce2e0 100644 --- a/paddlehub/commands/show.py +++ b/paddlehub/commands/show.py @@ -108,7 +108,7 @@ class ShowCommand(BaseCommand): print(tp.get_text()) return True - def exec(self, argv): + def execute(self, argv): if not argv: print("ERROR: Please specify a module or a model\n") self.help() diff --git a/paddlehub/commands/uninstall.py b/paddlehub/commands/uninstall.py index 8a6ca4ab..c00b9acd 100644 --- a/paddlehub/commands/uninstall.py +++ b/paddlehub/commands/uninstall.py @@ -36,7 +36,7 @@ class UninstallCommand(BaseCommand): usage='%(prog)s', add_help=False) - def exec(self, argv): + def execute(self, argv): if not argv: print("ERROR: Please specify a module\n") self.help() diff --git a/paddlehub/commands/version.py b/paddlehub/commands/version.py index a812fcc7..47e95950 100644 --- a/paddlehub/commands/version.py +++ b/paddlehub/commands/version.py @@ -28,7 +28,7 @@ class VersionCommand(BaseCommand): self.show_in_help = True self.description = "Show PaddleHub's version." - def exec(self, argv): + def execute(self, argv): print("hub %s" % version.hub_version) return True diff --git a/paddlehub/module/module.py b/paddlehub/module/module.py index aff4f531..9eee594b 100644 --- a/paddlehub/module/module.py +++ b/paddlehub/module/module.py @@ -239,14 +239,14 @@ class Module(object): continue var = global_block.var(param['name']) global_block.create_parameter( - **param, shape=var.shape, dtype=var.dtype, type=var.type, lod_level=var.lod_level, error_clip=var.error_clip, stop_gradient=var.stop_gradient, - is_data=var.is_data) + is_data=var.is_data, + **param) def _recover_variable_info(self, program): var_infos = self.desc.attr.map.data['var_infos'] @@ -422,8 +422,7 @@ class Module(object): self.check_processor() def _get_reader_and_feeder(data_format, data, place): - def _reader(): - nonlocal process_data + def _reader(process_data): for item in zip(*process_data): yield item @@ -433,7 +432,7 @@ class Module(object): process_data.append([value['processed'] for value in data[key]]) feed_name_list.append(data_format[key]['feed_key']) feeder = fluid.DataFeeder(feed_list=feed_name_list, place=place) - return _reader, feeder + return functools.partial(_reader, process_data=process_data), feeder feed_dict, fetch_dict, program = self.context(sign_name, for_test=True) #TODO(wuzewu): more option diff --git a/paddlehub/version.py b/paddlehub/version.py index e6a0c61f..daf7bd50 100644 --- a/paddlehub/version.py +++ b/paddlehub/version.py @@ -12,5 +12,5 @@ # See the License for the specific language governing permissions and # limitations under the License. """ PaddleHub version string """ -hub_version = "0.4.0.alpha" -module_proto_version = "0.1.0" +hub_version = "0.4.2.alpha" +module_proto_version = "1.0.0" -- GitLab