提交 dfc7aee2 编写于 作者: W wuzewu

Speed up the command line

上级 d2fece3e
......@@ -23,7 +23,7 @@ from paddlehub.commands import register, _commands
class HelpCommand:
def execute(self, argv: List) -> bool:
msg = 'Usage:\n'
msg += '\thub <command> <options>\n\n'
msg += ' hub <command> <options>\n\n'
msg += 'Commands:\n'
for command, detail in _commands['hub'].items():
if command.startswith('_'):
......@@ -31,7 +31,7 @@ class HelpCommand:
if not '_description' in detail:
continue
msg += '\t{:>15}\t\t{}\n'.format(command, detail['_description'])
msg += ' {:<15} {}\n'.format(command, detail['_description'])
print(msg)
return True
......@@ -23,5 +23,4 @@ from paddlehub.commands import register, get_command
class HubCommand:
def execute(self, argv):
help = get_command('hub.help')
help().execute(argv)
return True
return help().execute(argv)
......@@ -32,7 +32,6 @@ def register(name: str, description: str = '') -> Any:
name(str) : The name of the command, separated by '.' (e.g, hub.serving)
description(str) : The description of the specified command showd in the help command, if not description given, this command would not be shown in help command. Default is None.
'''
def _warpper(command):
items = name.split('.')
......@@ -66,4 +65,4 @@ def execute():
else:
idx += 1
exit(com['_entry']().execute(sys.argv[idx:]))
return com['_entry']().execute(sys.argv[idx:])
......@@ -22,23 +22,22 @@ PADDLEHUB_PUBLIC_SERVER = 'http://paddlepaddle.org.cn/paddlehub'
class HubServer(object):
'''PaddleHub server'''
def __init__(self):
self.sources = OrderedDict()
def _generate_source(self, url: str):
if ServerSource.check(url):
def _generate_source(self, url: str, source_type: str = 'server'):
if source_type == 'server':
source = ServerSource(url)
elif GitSource.check(url):
elif source_type == 'git':
source = GitSource(url)
else:
raise RuntimeError()
return source
def add_source(self, url: str, key: str = None):
def add_source(self, url: str, key: str = None, source_type: str = 'server'):
'''Add a module source(GitSource or ServerSource)'''
key = "source_{}".format(len(self.sources)) if not key else key
self.sources[key] = self._generate_source(url)
self.sources[key] = self._generate_source(url, source_type)
def remove_source(self, url: str = None, key: str = None):
'''Remove a module source'''
......
......@@ -18,8 +18,6 @@ import platform
import requests
import sys
import paddle
import paddlehub
from paddlehub.utils import utils
......@@ -32,7 +30,6 @@ class ServerSource(object):
url(str) : Url of the server
timeout(int) : Request timeout
'''
def __init__(self, url: str, timeout: int = 10):
self._url = url
self._timeout = timeout
......@@ -63,6 +60,8 @@ class ServerSource(object):
if version:
payload['version'] = version
# Delay module loading to improve command line speed
import paddle
payload['environments']['hub_version'] = paddlehub.__version__
payload['environments']['paddle_version'] = paddle.__version__
payload['environments']['python_version'] = '.'.join(map(str, sys.version_info[0:3]))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册