Skip to content

Commit 8ef1b7b

Browse files
committed
Implement use of the astropy config system for PyFITS' handful of settings. This removes, for now, support for setting these options by environment variable, but that will be restored once environment variable support is added to the Astropy config system (issue astropy#48).
1 parent bf14d08 commit 8ef1b7b

5 files changed

Lines changed: 29 additions & 21 deletions

File tree

‎astropy/io/fits/__init__.py‎

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,32 @@
4141
# restructured at some point)
4242
from .verify import VerifyError
4343

44-
# Set module-global boolean variables--these variables can also get their
45-
# values from environment variables
46-
GLOBALS = [
47-
# Variable name # Default
48-
('EXTENSION_NAME_CASE_SENSITIVE', False),
49-
('USE_MEMMAP', True),
50-
('ENABLE_RECORD_VALUED_KEYWORD_CARDS', True)
51-
]
44+
from ...config import ConfigurationItem
45+
46+
# Set module-global boolean variables
47+
# TODO: Make it possible to set these variables via environment variables
48+
# again, once support for that is added to Astropy
49+
EXTENSION_NAME_CASE_SENSITIVE = ConfigurationItem(
50+
'extension_name_case_sensitive', False,
51+
'If True, extension names (i.e. the EXTNAME keyword) should be '
52+
'treated as case-sensitive.')
53+
54+
USE_MEMMAP = ConfigurationItem(
55+
'use_memmap', True,
56+
'If True, use memory-mapped file access to read/write the data in '
57+
'FITS files. This generally provides better performance, especially '
58+
'for large files, but may affect performance in I/O-heavy '
59+
'applications.')
60+
61+
ENABLE_RECORD_VALUED_KEYWORD_CARDS = ConfigurationItem(
62+
'enabled_record_valued_keyword_cards', True,
63+
'If True, enable support for record-valued keywords as described by '
64+
'FITS WCS Paper IV. Otherwise they are treated as normal keywords.')
5265

53-
for varname, default in GLOBALS:
54-
try:
55-
envvar = os.environ.get('ASTROPY_FITS_' + varname, default)
56-
locals()[varname] = bool(int(envvar))
57-
except ValueError:
58-
locals()[varname] = default
5966

6067
__all__ = (card.__all__ + column.__all__ + convenience.__all__ +
6168
hdu.__all__ +
62-
['FITS_record', 'FITS_rec', 'GroupData', 'open', 'Section',
63-
'new_table', 'Header', 'VerifyError',
64-
'setExtensionNameCaseSensitive'] + [g[0] for g in GLOBALS])
69+
['FITS_record', 'FITS_rec', 'GroupData', 'open', 'Section',
70+
'new_table', 'Header', 'VerifyError',
71+
'EXTENSION_NAME_CASE_SENSITIVE', 'USE_MEMMAP',
72+
'ENABLE_RECORD_VALUED_KEYWORD_CARDS'])

‎astropy/io/fits/card.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,7 @@ def _check_if_rvkc(self, *args):
691691
"""
692692

693693
from . import ENABLE_RECORD_VALUED_KEYWORD_CARDS
694-
695-
if not ENABLE_RECORD_VALUED_KEYWORD_CARDS:
694+
if not ENABLE_RECORD_VALUED_KEYWORD_CARDS():
696695
return False
697696

698697
if len(args) == 1:

‎astropy/io/fits/convenience.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Licensed under a 3-clause BSD style license - see PYFITS.rst
2+
23
"""
34
Convenience functions
45
=====================

‎astropy/io/fits/hdu/base.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ def __setattr__(self, attr, value):
13151315
if attr == 'name' and value:
13161316
if not isinstance(value, basestring):
13171317
raise TypeError("'name' attribute must be a string")
1318-
if not EXTENSION_NAME_CASE_SENSITIVE:
1318+
if not EXTENSION_NAME_CASE_SENSITIVE():
13191319
value = value.upper()
13201320
if 'EXTNAME' in self._header:
13211321
self._header['EXTNAME'] = value

‎astropy/io/fits/hdu/hdulist.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def fitsopen(name, mode='readonly', memmap=None, **kwargs):
8383

8484
if memmap is None:
8585
from .. import USE_MEMMAP
86-
memmap = USE_MEMMAP
86+
memmap = USE_MEMMAP()
8787

8888
if 'uint16' in kwargs and 'uint' not in kwargs:
8989
kwargs['uint'] = kwargs['uint16']

0 commit comments

Comments
 (0)