Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
101ec096
提交
101ec096
authored
12月 08, 2020
作者:
Michael Osthege
提交者:
Brandon T. Willard
12月 09, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add backwards-compatibility for dot-based sectioning.
上级
936554c1
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
60 行增加
和
0 行删除
+60
-0
test_config.py
tests/test_config.py
+27
-0
configparser.py
theano/configparser.py
+33
-0
没有找到文件。
tests/test_config.py
浏览文件 @
101ec096
...
...
@@ -28,6 +28,33 @@ def test_api_deprecation_warning():
pass
def
test_api_redirect
():
root
=
configdefaults
.
config
# one section level
root
.
add
(
"test__section_redirect"
,
"A config var from a test case."
,
configparser
.
StrParam
(
"test_default"
),
)
assert
hasattr
(
root
,
"test__section_redirect"
)
assert
root
.
test__section_redirect
==
"test_default"
assert
hasattr
(
root
,
"test"
)
assert
isinstance
(
root
.
test
,
configparser
.
_SectionRedirect
)
with
pytest
.
warns
(
DeprecationWarning
):
assert
root
.
test
.
section_redirect
==
"test_default"
# two section levels
root
.
add
(
"test__subsection__redirect"
,
"A config var from a test case."
,
configparser
.
StrParam
(
"test_default2"
),
)
assert
hasattr
(
root
,
"test__subsection__redirect"
)
assert
root
.
test__subsection__redirect
==
"test_default2"
with
pytest
.
warns
(
DeprecationWarning
):
assert
root
.
test
.
subsection
.
redirect
==
"test_default2"
def
test_invalid_default
():
# Ensure an invalid default value found in the Theano code only causes
# a crash if it is not overridden by the user.
...
...
theano/configparser.py
浏览文件 @
101ec096
...
...
@@ -74,6 +74,27 @@ def _hash_from_code(msg):
return
"m"
+
hashlib
.
sha256
(
msg
)
.
hexdigest
()
class
_SectionRedirect
:
"""Functions as a mock property on the TheanoConfigParser.
It redirects attribute access (to config subsectinos) to the
new config variable properties that use "__" in their name.
"""
def
__init__
(
self
,
root
,
section_name
):
self
.
_root
=
root
self
.
_section_name
=
section_name
super
()
.
__init__
()
def
__getattr__
(
self
,
attr
):
warnings
.
warn
(
f
"Accessing section '{attr}' through old .-based API. "
f
"This will be removed. Use 'config.{self._section_name}__{attr}' instead."
,
DeprecationWarning
,
)
return
getattr
(
self
.
_root
,
f
"{self._section_name}__{attr}"
)
class
TheanoConfigParser
:
""" Object that holds configuration settings. """
...
...
@@ -175,6 +196,18 @@ class TheanoConfigParser:
# keep the ConfigParam object in a dictionary:
self
.
_config_var_dict
[
name
]
=
configparam
# The old API used dots for accessing a hierarchy of sections.
# The following code adds redirects that spill DeprecationWarnings
# while allowing backwards-compatible access to dot-based subsections.
# Because the subsectioning is recursive, redirects must be added for
# all levels. For example: ".test", ".test.subsection".
sections
=
name
.
split
(
"__"
)
for
s
in
range
(
1
,
len
(
sections
)):
section_name
=
"__"
.
join
(
sections
[:
s
])
if
not
hasattr
(
self
,
section_name
):
redirect
=
_SectionRedirect
(
self
,
section_name
)
setattr
(
self
.
__class__
,
section_name
,
redirect
)
def
fetch_val_for_key
(
self
,
key
,
delete_key
=
False
):
"""Return the overriding config value for a key.
A successful search returns a string value.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论