配置转换¶
本文档描述了中配置系统中的更改 astropy
以及如何更新代码以使用它。
为用户¶
配置文件¶
如果尚未在中编辑配置文件 ~/.astropy/config/astropy.cfg
,你没什么可做的。第一次导入时 astropy
0.4,它将自动替换为的配置文件模板 astropy
0.4。
如果您编辑了配置文件,它将保持不变。但是,的模板 astropy
0.4将安装为 ~/.astropy/config/astropy.0.4.cfg
. 您可以手动比较对此文件所做的更改,以确定应该带来哪些自定义项。
储蓄¶
已从Python配置中完全删除保存项。相反,必须直接编辑配置文件。
更名¶
配置参数的位置已经简化,因此它们总是出现在 astropy
,而不是使用低级文件名(这实际上是一个不应该向用户公开的实现细节)。在Python端,配置项总是通过 conf
对象位于子包的根目录。
一些影响科学计算结果的配置项已作为配置参数一起删除,并转换为必须从Python代码更改的科学状态对象。
下表列出了所有的移动(按原始配置文件位置的字母顺序排列)。旧名称将继续在Python和配置文件中使用 astropy
0.4释放周期,并将在 astropy
0.5.
旧配置文件位置 |
旧Python位置 |
新配置文件位置 |
新Python位置 |
---|---|---|---|
|
|
不变 |
|
|
|
|
|
|
|
远离的 |
|
|
|
远离的 |
|
|
|
远离的 |
|
|
|
不变 |
|
|
|
不变 |
|
|
|
不变 |
|
|
|
不变 |
|
|
|
|
|
|
|
不变 |
|
|
|
不变 |
|
|
|
不变 |
|
|
|
不变 |
|
|
|
不变 |
|
|
|
不变 |
|
|
|
不变 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
不变 |
|
|
|
不变 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
不变 |
|
|
|
不变 |
|
|
|
不变 |
|
|
|
不变 |
|
|
|
不变 |
|
|
|
不变 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
对于附属软件包作者¶
一个附属的一揽子计划来支持两者 astropy
0.3和0.4,遵循 astropy
0.3配置指令应继续工作。请注意,配置项的保存已从中完全删除 astropy
0.4没有弃用循环,因此如果以编程方式保存配置对包很重要,则可能需要考虑另一种方法来保存该状态。
但是,通过释放 astropy
0.5 astropy
0.3配置API将不再工作。下面描述如何转换为 astropy
0.3支持 astropy
0.4及更高版本。不可能支持 astropy
同时为0.3、0.4和0.5。下面 pkgname
是你的附属软件包的名称。
从中自动生成配置文件 ConfigurationItem
它找到的对象已被删除。相反,项目应该在中包含一个硬编码的“模板”配置文件 pkgname/pkgname.cfg
. 按照惯例,为了方便最终用户的升级,所有的值都应该被注释掉。例如:
[nddata]
## Whether to issue a warning if NDData arithmetic is performed with
## uncertainties and the uncertainties do not support the propagation of
## correlated uncertainties.
# warn_unsupported_correlated = True
附属软件包应过渡到使用 astropy.config.ConfigItem
对象作为成员 astropy.config.ConfigNamespace
子类。
例如,下面是 astropy
0.3及更早版本定义配置项的方法:
from astropy.config import ConfigurationItem
ENABLE_RECORD_VALUED_KEYWORD_CARDS = ConfigurationItem(
'enabled_record_valued_keyword_cards', True,
'If True, enable support for record-valued keywords as described by '
'the FITS WCS distortion paper. Otherwise they are treated as normal '
'keywords.')
EXTENSION_NAME_CASE_SENSITIVE = ConfigurationItem(
'extension_name_case_sensitive', False,
'If True, extension names (i.e. the EXTNAME keyword) should be '
'treated as case-sensitive.')
上面的转换为新方法的内容如下:
from astropy import config as _config
class Conf(_config.ConfigNamespace):
"""
Configuration parameters for `astropy.io.fits`.
"""
enable_record_valued_keyword_cards = _config.ConfigItem(
True,
'If True, enable support for record-valued keywords as described by '
'the FITS WCS distortion paper. Otherwise they are treated as normal '
'keywords.',
aliases=['astropy.io.fits.enabled_record_valued_keyword_cards'])
extension_name_case_sensitive = _config.ConfigItem(
False,
'If True, extension names (i.e. the ``EXTNAME`` keyword) should be '
'treated as case-sensitive.')
conf = Conf()
在Python中移动/重命名配置项¶
ConfigAlias
当配置项从 astropy
0.3样式 ConfigurationItem
对 astropy
0.4样式 ConfigItem
内部 ConfigNamespace
.
在上面的示例中,下面添加了向后兼容的钩子,这样配置项的旧Python位置将继续从用户代码中工作:
ENABLE_RECORD_VALUED_KEYWORD_CARDS = _config.ConfigAlias(
'0.4', 'ENABLE_RECORD_VALUED_KEYWORD_CARDS',
'enable_record_valued_keyword_cards')
移动/重命名配置文件中的配置项¶
如果在配置文件中移动或重命名配置项,则 aliases
克瓦格 ConfigItem
可以使用,以便旧位置将继续用作备用。例如,如果项目的旧位置是:
[coordinates.name_resolve]
sesame_url = http://somewhere.com
您可能想放弃这是在模块中实现的事实 name_resolve
只需将配置存储在 coordinates
:
[coordinates]
sesame_url = http://somewhere.com
当定义 ConfigItem
为了这个条目 aliases
kwarg可以列出配置项的旧位置:
sesame_url = _config.ConfigItem(
["http://somewhere.com"],
"""Docstring""",
aliases=['astropy.coordinates.name_resolve.sesame_url'])