Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
80c223bf
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
1 年多 前同步成功
通知
283
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
80c223bf
编写于
2月 24, 2020
作者:
W
wuzewu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Recover module.py
上级
997c3882
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
22 addition
and
42 deletion
+22
-42
paddlehub/module/module.py
paddlehub/module/module.py
+22
-42
未找到文件。
paddlehub/module/module.py
浏览文件 @
80c223bf
...
...
@@ -135,18 +135,15 @@ def runnable(func):
class
Module
(
object
):
def
__new__
(
cls
,
name
=
None
,
directory
=
None
,
module_dir
=
None
,
version
=
None
,
**
kwargs
):
_record
=
{}
def
__new__
(
cls
,
name
=
None
,
directory
=
None
,
module_dir
=
None
,
version
=
None
):
if
cls
.
__name__
==
"Module"
:
if
name
:
module
=
cls
.
init_with_name
(
name
=
name
,
version
=
version
,
**
kwargs
)
module
=
cls
.
init_with_name
(
name
=
name
,
version
=
version
)
elif
directory
:
module
=
cls
.
init_with_directory
(
directory
=
directory
,
**
kwargs
)
module
=
cls
.
init_with_directory
(
directory
=
directory
)
elif
module_dir
:
logger
.
warning
(
"Parameter module_dir is deprecated, please use directory to specify the path"
...
...
@@ -157,28 +154,19 @@ class Module(object):
version
=
module_dir
[
1
]
else
:
directory
=
module_dir
module
=
cls
.
init_with_directory
(
directory
=
directory
,
**
kwargs
)
module
=
cls
.
init_with_directory
(
directory
=
directory
)
CacheUpdater
(
"update_cache"
,
module
.
name
,
module
.
version
).
start
()
else
:
if
not
name
and
not
directory
:
directory
=
os
.
path
.
dirname
(
sys
.
modules
[
cls
.
__module__
].
__file__
)
module
=
Module
.
init_with_directory
(
directory
=
directory
,
**
kwargs
)
else
:
module
=
object
.
__new__
(
cls
)
module
=
object
.
__new__
(
cls
)
return
module
def
__init__
(
self
,
name
=
None
,
directory
=
None
,
module_dir
=
None
,
version
=
None
,
**
kwargs
):
def
__init__
(
self
,
name
=
None
,
directory
=
None
,
module_dir
=
None
,
version
=
None
):
# Avoid module being initialized multiple times
if
"_is_initialize"
in
self
.
__dict__
and
self
.
_is_initialize
:
if
not
directory
or
id
(
self
)
in
Module
.
_record
:
return
Module
.
_record
[
id
(
self
)]
=
True
mod
=
self
.
__class__
.
__module__
+
"."
+
self
.
__class__
.
__name__
if
mod
in
_module_runnable_func
:
...
...
@@ -207,11 +195,10 @@ class Module(object):
self
.
_summary
=
utils
.
from_module_attr_to_pyobj
(
module_info
.
map
.
data
[
'summary'
])
self
.
_initialize
(
**
kwargs
)
self
.
_is_initialize
=
True
self
.
_initialize
()
@
classmethod
def
init_with_name
(
cls
,
name
,
version
=
None
,
**
kwargs
):
def
init_with_name
(
cls
,
name
,
version
=
None
):
fp_lock
=
open
(
os
.
path
.
join
(
CACHE_HOME
,
name
),
"a"
)
lock
.
flock
(
fp_lock
,
lock
.
LOCK_EX
)
log_msg
=
"Installing %s module"
%
name
...
...
@@ -227,29 +214,22 @@ class Module(object):
logger
.
info
(
tips
)
lock
.
flock
(
fp_lock
,
lock
.
LOCK_UN
)
return
cls
.
init_with_directory
(
directory
=
module_dir
[
0
]
,
**
kwargs
)
return
cls
.
init_with_directory
(
directory
=
module_dir
[
0
])
@
classmethod
def
init_with_directory
(
cls
,
directory
,
**
kwargs
):
def
init_with_directory
(
cls
,
directory
):
desc_file
=
os
.
path
.
join
(
directory
,
MODULE_DESC_PBNAME
)
checker
=
ModuleChecker
(
directory
)
checker
.
check
()
module_code_version
=
checker
.
module_code_version
if
module_code_version
==
"v2"
:
sys
.
path
.
insert
(
0
,
directory
)
# clear module cache
if
'module'
in
sys
.
modules
:
sys
.
modules
.
pop
(
'module'
)
_module
=
importlib
.
import_module
(
"module"
)
for
_item
,
_cls
in
inspect
.
getmembers
(
_module
,
inspect
.
isclass
):
_item
=
_module
.
__dict__
[
_item
]
if
issubclass
(
_item
,
Module
):
user_module
=
_item
(
directory
=
directory
,
**
kwargs
)
break
sys
.
path
.
pop
(
0
)
return
user_module
return
ModuleV1
(
directory
=
directory
,
**
kwargs
)
basename
=
os
.
path
.
split
(
directory
)[
-
1
]
dirname
=
os
.
path
.
join
(
*
list
(
os
.
path
.
split
(
directory
)[:
-
1
]))
sys
.
path
.
append
(
dirname
)
user_module
=
importlib
.
import_module
(
"{}.module"
.
format
(
basename
))
return
user_module
.
HubModule
(
directory
=
directory
)
return
ModuleV1
(
directory
=
directory
)
@
property
def
run_func
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录