File: config_0_4_transition.rst

package info (click to toggle)
python-astropy 1.3-8~bpo8%2B2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 44,292 kB
  • sloc: ansic: 160,360; python: 137,322; sh: 11,493; lex: 7,638; yacc: 4,956; xml: 1,796; makefile: 474; cpp: 364
file content (327 lines) | stat: -rw-r--r-- 12,192 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
.. _config-0-4-transition:

Configuration transition
========================

This document describes the changes in the configuration system in
astropy 0.4 and how to update code to use it.

For users
---------

The config file
^^^^^^^^^^^^^^^

If you never edited the configuration file in
``~/.astropy/config/astropy.cfg``, there is nothing for you to do.
The first time you import astropy 0.4, it will automatically be
replaced with the configuration file template for astropy 0.4.

If you did edit the configuration file, it will be left untouched.
However, the template for astropy 0.4 will be installed as
``~/.astropy/config/astropy.0.4.cfg``.  You can manually compare your
changes to this file to determine what customizations should be
brought over.

Saving
^^^^^^

Saving configuration items from Python has been completely removed.
Instead, the configuration file must be edited directly.

Renames
^^^^^^^

The location of the configuration parameters have been simplified, so
they always appear in a high-level subpackage of astropy, rather than
low-level file names (which were really an implementation detail that
shouldn't have been exposed to the user).  On the Python side,
configuration items always are referenced through a ``conf`` object at
the root of a subpackage.

Some configuration items that affect the results of science
calculations have been removed as configuration parameters altogether
and converted to science state objects that must be changed from
Python code.

The following table lists all of the moves (in alphabetical order by
original configuration file location).  The old names will continue to
work both from Python and the configuration file for the astropy 0.4
release cycle, and will be removed altogether in astropy 0.5.

.. list-table:: Renamed configuration parameters
   :widths: 20 20 20 20
   :header-rows: 1

   * - Old config file location
     - Old Python location
     - New config file location
     - New Python location
   * - ``[] unicode_output``
     - ``UNICODE_OUTPUT``
     - *unchanged*
     - ``conf.unicode_output``
   * - ``[coordinates.name_resolve] name_resolve_timeout``
     - ``coordinates.name_resolve.NAME_RESOLVE_TIMEOUT``
     - ``[astropy.utils.data] remote_timeout``
     - ``astropy.utils.data.conf.remote_timeout``
   * - ``[coordinates.name_resolve] sesame_url``
     - ``coordinates.name_resolve.SESAME_URL``
     - *removed*
     - ``coordinates.name_resolve.sesame_url.get/set``
   * - ``[coordinates.name_resolve] sesame_database``
     - ``coordinates.name_resolve.SESAME_DATABASE``
     - *removed*
     - ``coordinates.name_resolve.sesame_database.get/set``
   * - ``[cosmology.core] default_cosmology``
     - ``cosmology.core.DEFAULT_COSMOLOGY``
     - *removed*
     - ``cosmology.default_cosmology.get/set``
   * - ``[io.fits] enable_record_valued_keyword_cards``
     - ``io.fits.ENABLE_RECORD_VALUED_KEYWORD_CARDS``
     - *unchanged*
     - ``io.fits.conf.enable_record_valued_keyword_cards``
   * - ``[io.fits] extension_name_case_sensitive``
     - ``io.fits.EXTENSION_NAME_CASE_SENSITIVE``
     - *unchanged*
     - ``io.fits.conf.extension_name_case_sensitive``
   * - ``[io.fits] strip_header_whitespace``
     - ``io.fits.STRIP_HEADER_WHITESPACE``
     - *unchanged*
     - ``io.fits.conf.strip_header_whitespace``
   * - ``[io.fits] use_memmap``
     - ``io.fits.USE_MEMMAP``
     - *unchanged*
     - ``io.fits.conf.use_memmap``
   * - ``[io.votable.table] pedantic``
     - ``io.votable.table.PEDANTIC``
     - ``[io.votable] pedantic``
     - ``io.votable.conf.pedantic``
   * - ``[logger] log_exceptions``
     - ``logger.LOG_EXCEPTIONS``
     - *unchanged*
     - ``logger.conf.log_exceptions``
   * - ``[logger] log_file_format``
     - ``logger.LOG_FILE_FORMAT``
     - *unchanged*
     - ``logger.conf.log_file_format``
   * - ``[logger] log_file_level``
     - ``logger.LOG_FILE_LEVEL``
     - *unchanged*
     - ``logger.conf.log_file_level``
   * - ``[logger] log_file_path``
     - ``logger.LOG_FILE_PATH``
     - *unchanged*
     - ``logger.conf.log_file_path``
   * - ``[logger] log_level``
     - ``logger.LOG_LEVEL``
     - *unchanged*
     - ``logger.conf.log_level``
   * - ``[logger] log_to_file``
     - ``logger.LOG_TO_FILE``
     - *unchanged*
     - ``logger.conf.log_to_file``
   * - ``[logger] log_warnings``
     - ``logger.LOG_WARNINGS``
     - *unchanged*
     - ``logger.conf.log_warnings``
   * - ``[logger] use_color``
     - ``logger.USE_COLOR``
     - ``[] use_color``
     - ``conf.use_color``
   * - ``[nddata.nddata] warn_unsupported_correlated``
     - ``nddata.nddata.WARN_UNSUPPORTED_CORRELATED``
     - ``[nddata] warn_unsupported_correlated``
     - ``nddata.conf.warn_unsupported_correlated``
   * - ``[table.column] auto_colname``
     - ``table.column.AUTO_COLNAME``
     - ``[table] auto_colname``
     - ``table.conf.auto_colname``
   * - ``[table.jsviewer] jquery_url``
     - ``table.jsviewer.JQUERY_URL``
     - *unchanged*
     - ``table.jsviewer.conf.jquery_url``
   * - ``[table.jsviewer] datatables_url``
     - ``table.jsviewer.DATATABLES_URL``
     - *unchanged*
     - ``table.jsviewer.conf.datatables_url``
   * - ``[table.pprint] max_lines``
     - ``table.pprint.MAX_LINES``
     - ``[] max_lines``
     - ``conf.max_lines``
   * - ``[table.pprint] max_width``
     - ``table.pprint.MAX_WIDTH``
     - ``[] max_width``
     - ``conf.max_width``
   * - ``[utils.console] use_color``
     - ``utils.console.USE_COLOR``
     - ``[] use_color``
     - ``conf.use_color``
   * - ``[utils.data] compute_hash_block_size``
     - ``astropy.utils.data.COMPUTE_HASH_BLOCK_SIZE``
     - *unchanged*
     - ``astropy.utils.data.conf.compute_hash_block_size``
   * - ``[utils.data] dataurl``
     - ``astropy.utils.data.DATAURL``
     - *unchanged*
     - ``astropy.utils.data.conf.dataurl``
   * - ``[utils.data] delete_temporary_downloads_at_exit``
     - ``astropy.utils.data.DELETE_TEMPORARY_DOWNLOADS_AT_EXIT``
     - *unchanged*
     - ``astropy.utils.data.conf.delete_temporary_downloads_at_exit``
   * - ``[utils.data] download_cache_block_size``
     - ``astropy.utils.data.DOWNLOAD_CACHE_BLOCK_SIZE``
     - *unchanged*
     - ``astropy.utils.data.conf.download_cache_block_size``
   * - ``[utils.data] download_cache_lock_attempts``
     - ``astropy.utils.data.download_cache_lock_attempts``
     - *unchanged*
     - ``astropy.utils.data.conf.download_cache_lock_attempts``
   * - ``[utils.data] remote_timeout``
     - ``astropy.utils.data.REMOTE_TIMEOUT``
     - *unchanged*
     - ``astropy.utils.data.conf.remote_timeout``
   * - ``[vo.client.conesearch] conesearch_dbname``
     - ``vo.client.conesearch.CONESEARCH_DBNAME``
     - ``[vo] conesearch_dbname``
     - ``vo.conf.conesearch_dbname``
   * - ``[vo.client.vos_catalog] vos_baseurl``
     - ``vo.client.vos_catalog.BASEURL``
     - ``[vo] vos_baseurl``
     - ``vo.conf.vos_baseurl``
   * - ``[vo.samp.utils] use_internet``
     - ``vo.samp.utils.ALLOW_INTERNET``
     - ``[vo.samp] use_internet``
     - ``vo.samp.conf.use_internet``
   * - ``[vo.validator.validate] cs_mstr_list``
     - ``vo.validator.validate.CS_MSTR_LIST``
     - ``[vo.validator] conesearch_master_list``
     - ``vo.validator.conf.conesearch_master_list``
   * - ``[vo.validator.validate] cs_urls``
     - ``vo.validator.validate.CS_URLS``
     - ``[vo.validator] conesearch_urls``
     - ``vo.validator.conf.conesearch_urls``
   * - ``[vo.validator.validate] noncrit_warnings``
     - ``vo.validator.validate.noncrit_warnings``
     - ``[vo.validator] noncritical_warnings``
     - ``vo.validator.conf.noncritical_warnings``

For affiliated package authors
------------------------------

For an affiliated package to support both astropy 0.3 and 0.4,
following the astropy 0.3 config instructions should continue to work.
Note that saving of configuration items has been removed entirely from
astropy 0.4 without a deprecation cycle, so if saving configuration
programmatically is important to your package, you may want to
consider another method to save that state.

However, by the release of astropy 0.5, the astropy 0.3 config API
will no longer work.  The following describes how to transition an
affiliated package written for astropy 0.3 to support astropy 0.4 and
later.  It will not be possible to support astropy 0.3, 0.4 and 0.5
simultaneously.  Below ``pkgname`` is the name of your affiliated
package.

The automatic generation of configuration files from the
``ConfigurationItem`` objects that it finds has been removed.
Instead, the project should include a hard-coded "template"
configuration file in ``pkgname/pkgname.cfg``.  By convention, and to
ease upgrades for end users, all of the values should be commented
out.  For example:

.. code-block:: ini

    [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

Affiliated packages should transition to using
`astropy.config.ConfigItem` objects as members of
`astropy.config.ConfigNamespace` subclasses.

For example, the following is an example of the astropy 0.3 and
earlier method to define configuration items::

    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.')

The above, converted to the new method, looks like::

    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()


Moving/renaming configuration items in Python
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

``ConfigAlias`` objects can be used when a configuration item has been
moved from an astropy 0.3-style ``ConfigurationItem`` to an astropy
0.4-style ``ConfigItem`` inside of a ``ConfigNamespace``.

In the above example, the following adds backward-compatible hooks so
the old Python locations of the configuration items will continue to
work from user code::

    ENABLE_RECORD_VALUED_KEYWORD_CARDS = _config.ConfigAlias(
        '0.4', 'ENABLE_RECORD_VALUED_KEYWORD_CARDS',
        'enable_record_valued_keyword_cards')

Moving/renaming configuration items in the config file
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

If a configuration item is moved or renamed within the configuration
file, the ``aliases`` kwarg to ``ConfigItem`` can be used so that the
old location will continue to be used as a fallback.  For example, if
the old location of an item was:

.. code-block:: ini

    [coordinates.name_resolve]
    sesame_url = http://somewhere.com

One might want to drop the fact that that is implemented in the module
``name_resolve`` and just store the configuration in ``coordinates``:

.. code-block:: ini

    [coordinates]
    sesame_url = http://somewhere.com

When defining the ``ConfigItem`` for this entry, the ``aliases`` kwarg
can list the old location(s) of the configuration item::

    sesame_url = _config.ConfigItem(
        ["http://somewhere.com"],
        """Docstring""",
        aliases=['astropy.coordinates.name_resolve.sesame_url'])