提交 a61b5c3d 编写于 作者: W wuzewu

Fix python2 compatibility issues

上级 048a9ec6
...@@ -62,5 +62,5 @@ class BaseCommand(object): ...@@ -62,5 +62,5 @@ class BaseCommand(object):
def print_args(self): def print_args(self):
print_arguments(self.args) print_arguments(self.args)
def exec(self, argv): def execute(self, argv):
raise NotImplementedError("Base Command should not be execute!") raise NotImplementedError("Base Command should not be execute!")
...@@ -54,7 +54,7 @@ class ClearCommand(BaseCommand): ...@@ -54,7 +54,7 @@ class ClearCommand(BaseCommand):
def cache_dir(self): def cache_dir(self):
return CACHE_HOME return CACHE_HOME
def exec(self, argv): def execute(self, argv):
result = True result = True
total_file_size = 0 total_file_size = 0
total_file_count = 0 total_file_count = 0
......
...@@ -43,7 +43,7 @@ class DownloadCommand(BaseCommand): ...@@ -43,7 +43,7 @@ class DownloadCommand(BaseCommand):
self.add_arg('--uncompress', bool, False, "uncompress the download package or not" ) self.add_arg('--uncompress', bool, False, "uncompress the download package or not" )
# yapf: enable # yapf: enable
def exec(self, argv): def execute(self, argv):
if not argv: if not argv:
print("ERROR: Please provide the model/module name\n") print("ERROR: Please provide the model/module name\n")
self.help() self.help()
......
...@@ -30,7 +30,7 @@ class HelpCommand(BaseCommand): ...@@ -30,7 +30,7 @@ class HelpCommand(BaseCommand):
def get_all_commands(self): def get_all_commands(self):
return BaseCommand.command_dict return BaseCommand.command_dict
def exec(self, argv): def execute(self, argv):
hub_command = BaseCommand.command_dict["hub"] hub_command = BaseCommand.command_dict["hub"]
help_text = "\n" help_text = "\n"
help_text += "Usage:\n" help_text += "Usage:\n"
......
...@@ -34,30 +34,30 @@ class HubCommand(BaseCommand): ...@@ -34,30 +34,30 @@ class HubCommand(BaseCommand):
super(HubCommand, self).__init__(name) super(HubCommand, self).__init__(name)
self.show_in_help = False self.show_in_help = False
def exec(self, argv): def execute(self, argv):
logger.setLevel("NOLOG") logger.setLevel("NOLOG")
if not argv: if not argv:
help.command.exec(argv) help.command.execute(argv)
exit(1) exit(1)
return False return False
sub_command = argv[0] sub_command = argv[0]
if not sub_command in BaseCommand.command_dict: if not sub_command in BaseCommand.command_dict:
print("ERROR: unknown command '%s'" % sub_command) print("ERROR: unknown command '%s'" % sub_command)
help.command.exec(argv) help.command.execute(argv)
exit(1) exit(1)
return False return False
command = BaseCommand.command_dict[sub_command] command = BaseCommand.command_dict[sub_command]
return command.exec(argv[1:]) return command.execute(argv[1:])
command = HubCommand.instance() command = HubCommand.instance()
def main(): def main():
command.exec(sys.argv[1:]) command.execute(sys.argv[1:])
if __name__ == "__main__": if __name__ == "__main__":
command.exec(sys.argv[1:]) command.execute(sys.argv[1:])
...@@ -37,7 +37,7 @@ class InstallCommand(BaseCommand): ...@@ -37,7 +37,7 @@ class InstallCommand(BaseCommand):
add_help=False) add_help=False)
#TODO(wuzewu): add --upgrade option #TODO(wuzewu): add --upgrade option
def exec(self, argv): def execute(self, argv):
if not argv: if not argv:
print("ERROR: Please specify a module name.\n") print("ERROR: Please specify a module name.\n")
self.help() self.help()
......
...@@ -31,7 +31,7 @@ class ListCommand(BaseCommand): ...@@ -31,7 +31,7 @@ class ListCommand(BaseCommand):
self.show_in_help = True self.show_in_help = True
self.description = "List all installed PaddleHub modules." self.description = "List all installed PaddleHub modules."
def exec(self, argv): def execute(self, argv):
all_modules = default_module_manager.all_modules() all_modules = default_module_manager.all_modules()
if utils.is_windows(): if utils.is_windows():
placeholders = [20, 40] placeholders = [20, 40]
......
...@@ -75,7 +75,7 @@ class RunCommand(BaseCommand): ...@@ -75,7 +75,7 @@ class RunCommand(BaseCommand):
demo = "%s %s %s" % (entry, self.name, module.name) demo = "%s %s %s" % (entry, self.name, module.name)
return demo return demo
def exec(self, argv): def execute(self, argv):
if not argv: if not argv:
print("ERROR: Please specify a module name.\n") print("ERROR: Please specify a module name.\n")
self.help() self.help()
......
...@@ -37,7 +37,7 @@ class SearchCommand(BaseCommand): ...@@ -37,7 +37,7 @@ class SearchCommand(BaseCommand):
usage='%(prog)s', usage='%(prog)s',
add_help=False) add_help=False)
def exec(self, argv): def execute(self, argv):
if not argv: if not argv:
argv = ['.*'] argv = ['.*']
......
...@@ -108,7 +108,7 @@ class ShowCommand(BaseCommand): ...@@ -108,7 +108,7 @@ class ShowCommand(BaseCommand):
print(tp.get_text()) print(tp.get_text())
return True return True
def exec(self, argv): def execute(self, argv):
if not argv: if not argv:
print("ERROR: Please specify a module or a model\n") print("ERROR: Please specify a module or a model\n")
self.help() self.help()
......
...@@ -36,7 +36,7 @@ class UninstallCommand(BaseCommand): ...@@ -36,7 +36,7 @@ class UninstallCommand(BaseCommand):
usage='%(prog)s', usage='%(prog)s',
add_help=False) add_help=False)
def exec(self, argv): def execute(self, argv):
if not argv: if not argv:
print("ERROR: Please specify a module\n") print("ERROR: Please specify a module\n")
self.help() self.help()
......
...@@ -28,7 +28,7 @@ class VersionCommand(BaseCommand): ...@@ -28,7 +28,7 @@ class VersionCommand(BaseCommand):
self.show_in_help = True self.show_in_help = True
self.description = "Show PaddleHub's version." self.description = "Show PaddleHub's version."
def exec(self, argv): def execute(self, argv):
print("hub %s" % version.hub_version) print("hub %s" % version.hub_version)
return True return True
......
...@@ -239,14 +239,14 @@ class Module(object): ...@@ -239,14 +239,14 @@ class Module(object):
continue continue
var = global_block.var(param['name']) var = global_block.var(param['name'])
global_block.create_parameter( global_block.create_parameter(
**param,
shape=var.shape, shape=var.shape,
dtype=var.dtype, dtype=var.dtype,
type=var.type, type=var.type,
lod_level=var.lod_level, lod_level=var.lod_level,
error_clip=var.error_clip, error_clip=var.error_clip,
stop_gradient=var.stop_gradient, stop_gradient=var.stop_gradient,
is_data=var.is_data) is_data=var.is_data,
**param)
def _recover_variable_info(self, program): def _recover_variable_info(self, program):
var_infos = self.desc.attr.map.data['var_infos'] var_infos = self.desc.attr.map.data['var_infos']
...@@ -422,8 +422,7 @@ class Module(object): ...@@ -422,8 +422,7 @@ class Module(object):
self.check_processor() self.check_processor()
def _get_reader_and_feeder(data_format, data, place): def _get_reader_and_feeder(data_format, data, place):
def _reader(): def _reader(process_data):
nonlocal process_data
for item in zip(*process_data): for item in zip(*process_data):
yield item yield item
...@@ -433,7 +432,7 @@ class Module(object): ...@@ -433,7 +432,7 @@ class Module(object):
process_data.append([value['processed'] for value in data[key]]) process_data.append([value['processed'] for value in data[key]])
feed_name_list.append(data_format[key]['feed_key']) feed_name_list.append(data_format[key]['feed_key'])
feeder = fluid.DataFeeder(feed_list=feed_name_list, place=place) 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) feed_dict, fetch_dict, program = self.context(sign_name, for_test=True)
#TODO(wuzewu): more option #TODO(wuzewu): more option
......
...@@ -12,5 +12,5 @@ ...@@ -12,5 +12,5 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
""" PaddleHub version string """ """ PaddleHub version string """
hub_version = "0.4.0.alpha" hub_version = "0.4.2.alpha"
module_proto_version = "0.1.0" module_proto_version = "1.0.0"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册