提交 7715f42e 编写于 作者: K kinghuin 提交者: wuzewu

remove needless import (#258)

* remove needless import
Co-authored-by: Nwuzewu <wuzewu@baidu.com>
上级 ca3e9774
......@@ -36,7 +36,8 @@ from .common.dir import CACHE_HOME
from .common.dir import CONF_HOME
from .common.logger import logger
from .common.paddle_helper import connect_program
from .common.hub_server import default_hub_server
from .common.hub_server import HubServer
from .common.hub_server import server_check
from .module.module import Module
from .module.base_processor import BaseProcessor
......@@ -61,5 +62,3 @@ from .finetune.strategy import ULMFiTStrategy
from .finetune.strategy import CombinedStrategy
from .autofinetune.evaluator import report_final_result
from .common.hub_server import server_check
......@@ -18,26 +18,13 @@ from __future__ import division
from __future__ import print_function
import argparse
import io
import json
import os
import sys
import ast
import six
import shutil
import pandas
import numpy as np
from paddlehub.commands.base_command import BaseCommand, ENTRY
from paddlehub.common.arg_helper import add_argument, print_arguments
from paddlehub.autofinetune.autoft import PSHE2
from paddlehub.autofinetune.autoft import HAZero
from paddlehub.autofinetune.evaluator import FullTrailEvaluator
from paddlehub.autofinetune.evaluator import PopulationBasedEvaluator
from paddlehub.common.logger import logger
import paddlehub as hub
class AutoFineTuneCommand(BaseCommand):
......
......@@ -20,9 +20,9 @@ from __future__ import print_function
import argparse
import os
import paddlehub as hub
from paddlehub.common import utils
from paddlehub.common.downloader import default_downloader
from paddlehub.common.hub_server import default_hub_server
from paddlehub.commands.base_command import BaseCommand, ENTRY
......@@ -57,20 +57,20 @@ class DownloadCommand(BaseCommand):
extra = {"command": "download"}
if self.args.type in ["Module", "Model"]:
search_result = default_hub_server.get_resource_url(
search_result = hub.HubServer().get_resource_url(
mod_name,
resource_type=self.args.type,
version=mod_version,
extra=extra)
else:
search_result = default_hub_server.get_resource_url(
search_result = hub.HubServer().get_resource_url(
mod_name,
resource_type="Module",
version=mod_version,
extra=extra)
self.args.type = "Module"
if search_result == {}:
search_result = default_hub_server.get_resource_url(
search_result = hub.HubServer().get_resource_url(
mod_name,
resource_type="Model",
version=mod_version,
......@@ -79,7 +79,7 @@ class DownloadCommand(BaseCommand):
url = search_result.get('url', None)
except_md5_value = search_result.get('md5', None)
if not url:
if default_hub_server._server_check() is False:
if hub.HubServer()._server_check() is False:
tips = "Request Hub-Server unsuccessfully, please check your network."
else:
tips = "PaddleHub can't find model/module named %s" % mod_name
......
......@@ -20,15 +20,11 @@ from __future__ import print_function
import six
import sys
from paddlehub.commands.base_command import BaseCommand
from paddlehub.common.logger import logger
from paddlehub.common.utils import sys_stdin_encoding
from paddlehub.common import srv_utils
from paddlehub.commands.base_command import BaseCommand
from paddlehub.commands import show
from paddlehub.commands import help
from paddlehub.commands import version
from paddlehub.commands import run
from paddlehub.commands import download
class HubCommand(BaseCommand):
......
......@@ -44,6 +44,7 @@ class InstallCommand(BaseCommand):
self.help()
return False
extra = {"command": "install"}
if argv[0].endswith("tar.gz") or argv[0].endswith("phm"):
result, tips, module_dir = default_module_manager.install_module(
module_package=argv[0], extra=extra)
......@@ -60,7 +61,9 @@ class InstallCommand(BaseCommand):
module_name=module_name,
module_version=module_version,
extra=extra)
print(tips)
return True
......
......@@ -20,20 +20,16 @@ from __future__ import print_function
import argparse
import json
import os
import sys
import ast
import six
import pandas
import imghdr
import cv2
import numpy as np
from paddlehub.commands.base_command import BaseCommand, ENTRY
from paddlehub.io.parser import yaml_parser, txt_parser
from paddlehub.module.manager import default_module_manager
from paddlehub.common import utils
from paddlehub.common.arg_helper import add_argument, print_arguments
import paddlehub as hub
......
......@@ -19,8 +19,8 @@ from __future__ import print_function
import argparse
import paddlehub as hub
from paddlehub.common import utils
from paddlehub.common.hub_server import default_hub_server
from paddlehub.commands.base_command import BaseCommand, ENTRY
from paddlehub.common.cml_utils import TablePrinter
......@@ -44,7 +44,7 @@ class SearchCommand(BaseCommand):
resource_name = argv[0]
extra = {"command": "search"}
resource_list = default_hub_server.search_resource(
resource_list = hub.HubServer().search_resource(
resource_name, resource_type="Module", extra=extra)
if utils.is_windows():
placeholders = [20, 8, 8, 20]
......@@ -54,7 +54,7 @@ class SearchCommand(BaseCommand):
titles=["ResourceName", "Type", "Version", "Summary"],
placeholders=placeholders)
if len(resource_list) == 0:
if default_hub_server._server_check() is False:
if hub.HubServer()._server_check() is False:
print(
"Request Hub-Server unsuccessfully, please check your network."
)
......
......@@ -26,7 +26,6 @@ import yaml
import random
import threading
from random import randint
from paddlehub.common import utils, srv_utils
from paddlehub.common.downloader import default_downloader
from paddlehub.common.server_config import default_server_config
......@@ -38,6 +37,29 @@ RESOURCE_LIST_FILE = "resource_list_file.yml"
CACHE_TIME = 60 * 10
def synchronized(func):
func.__lock__ = threading.Lock()
def synced_func(*args, **kwargs):
with func.__lock__:
return func(*args, **kwargs)
return synced_func
def singleton(cls):
_instance = {}
@synchronized
def _get_instance(*args, **kwargs):
if cls not in _instance:
_instance[cls] = cls(*args, **kwargs)
return _instance[cls]
return _get_instance
@singleton
class HubServer(object):
def __init__(self, config_file_path=None):
if not config_file_path:
......@@ -295,8 +317,7 @@ class CacheUpdater(threading.Thread):
payload = {'word': module}
if version:
payload['version'] = version
api_url = srv_utils.uri_path(default_hub_server.get_server_url(),
'search')
api_url = srv_utils.uri_path(HubServer().get_server_url(), 'search')
cache_path = os.path.join(CACHE_HOME, RESOURCE_LIST_FILE)
if os.path.exists(cache_path):
extra = {
......@@ -321,7 +342,4 @@ class CacheUpdater(threading.Thread):
def server_check():
default_hub_server.server_check()
default_hub_server = HubServer()
HubServer().server_check()
......@@ -19,7 +19,6 @@ from __future__ import print_function
import copy
import paddle
import paddle.fluid as fluid
from paddlehub.module import module_desc_pb2
......
......@@ -12,15 +12,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import requests
import time
import paddle
import socket
import json
from random import randint, seed
from paddlehub import version
......
......@@ -19,12 +19,10 @@ from __future__ import print_function
import sys
import os
import time
import multiprocessing
import hashlib
import platform
import paddle
import paddle.fluid as fluid
import six
......
......@@ -20,7 +20,6 @@ from __future__ import print_function
import os
import paddle.fluid as fluid
import numpy as np
import paddlehub as hub
......
......@@ -17,9 +17,7 @@ from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import math
import multiprocessing
import paddle.fluid as fluid
......
......@@ -24,9 +24,7 @@ from functools import cmp_to_key
import tarfile
from paddlehub.common import utils
from paddlehub.common import srv_utils
from paddlehub.common.downloader import default_downloader
from paddlehub.common.hub_server import default_hub_server
from paddlehub.common.dir import MODULE_HOME
from paddlehub.common.cml_utils import TablePrinter
from paddlehub.module import module_desc_pb2
......@@ -102,7 +100,7 @@ class LocalModuleManager(object):
module_dir)
return True, tips, self.modules_dict[module_name]
search_result = hub.default_hub_server.get_module_url(
search_result = hub.HubServer().get_module_url(
module_name, version=module_version, extra=extra)
name = search_result.get('name', None)
url = search_result.get('url', None)
......@@ -111,10 +109,10 @@ class LocalModuleManager(object):
if not url or (module_version is not None
and installed_module_version != module_version) or (
name != module_name):
if default_hub_server._server_check() is False:
if hub.HubServer()._server_check() is False:
tips = "Request Hub-Server unsuccessfully, please check your network."
return False, tips, None
module_versions_info = default_hub_server.search_module_info(
module_versions_info = hub.HubServer().search_module_info(
module_name)
if module_versions_info is not None and len(
module_versions_info) > 0:
......@@ -150,8 +148,6 @@ class LocalModuleManager(object):
tips = "Can't find module %s" % module_name
if module_version:
tips += " with version %s" % module_version
module_tag = module_name if not module_version else '%s-%s' % (
module_name, module_version)
return False, tips, None
result, tips, module_zip_file = default_downloader.download_file(
......
......@@ -37,7 +37,6 @@ from paddlehub.common.lock import lock
from paddlehub.common.logger import logger
from paddlehub.common.hub_server import CacheUpdater
from paddlehub.module import module_desc_pb2
from paddlehub.module import check_info_pb2
from paddlehub.module.manager import default_module_manager
from paddlehub.module.checker import ModuleChecker
from paddlehub.module.signature import Signature, create_signature
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册