Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions astropy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
managing them.
"""

#this indicates whether or not we are in astropy's setup.py
# this indicates whether or not we are in astropy's setup.py
try:
_ASTROPY_SETUP_
except NameError:
Expand All @@ -30,6 +30,9 @@
__githash__ = ''


import logging


# The location of the online documentation for astropy
# This location will normally point to the current released version of astropy
if 'dev' in __version__:
Expand Down Expand Up @@ -114,10 +117,13 @@ def test(package=None, test_path=None, args=None, plugins=None,
coverage=coverage, open_files=open_files)


# Use the root logger as a dummy log before initilizing Astropy's logger
log = logging.getLogger()

# if we are *not* in setup mode, import the logger and possibly populate the
# configuration file with the defaults
if not _ASTROPY_SETUP_:
from .logger import log
from .logger import _init_log
from . import config

import os
Expand All @@ -142,14 +148,15 @@ def test(package=None, test_path=None, args=None, plugins=None,
# add these here so we only need to cleanup the namespace at the end
config_dir = None

if not os.environ.get('ASTROPY_SKIP_CONFIG_UPDATE', False):
config_dir = os.path.dirname(__file__)
try:
config.configuration.update_default_config(__package__, config_dir)
except config.configuration.ConfigurationDefaultMissingError as e:
wmsg = (e.args[0] + " Cannot install default profile. If you are "
"importing from source, this is expected.")
warn(config.configuration.ConfigurationDefaultMissingWarning(wmsg))
del e

del os, warn, config_dir # clean up namespace
log = _init_log()

config_dir = os.path.dirname(__file__)
try:
config.configuration.update_default_config(__package__, config_dir)
except config.configuration.ConfigurationDefaultMissingError as e:
wmsg = (e.args[0] + " Cannot install default profile. If you are "
"importing from source, this is expected.")
warn(config.configuration.ConfigurationDefaultMissingWarning(wmsg))
del e

del _init_log, os, warn, config_dir # clean up namespace
34 changes: 19 additions & 15 deletions astropy/config/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from ..extern.configobj import configobj, validate


__all__ = ['ConfigurationItem', 'InvalidConfigurationItemWarning',
'ConfigurationMissingWarning', 'get_config', 'save_config',
'reload_config']
Expand Down Expand Up @@ -416,22 +417,25 @@ def get_config(packageormod=None, reload=False):
cobj = _cfgobjs.get(rootname, None)

if cobj is None:
try:
cfgfn = join(get_config_dir(), rootname + '.cfg')
cobj = configobj.ConfigObj(cfgfn, interpolation=False)
_cfgobjs[rootname] = cobj

except (IOError, OSError) as e:
msg1 = 'Configuration defaults will be used, and configuration '
msg2 = 'cannot be saved due to '
errstr = '' if len(e.args) < 1 else (':' + str(e.args[0]))
wmsg = msg1 + msg2 + e.__class__.__name__ + errstr
warn(ConfigurationMissingWarning(wmsg))

# This caches the object, so if the file becomes accessible, this
# function won't see it unless the module is reloaded
if _ASTROPY_SETUP_:
# There's no reason to use anything but the default config
cobj = configobj.ConfigObj(interpolation=False)
_cfgobjs[rootname] = cobj
else:
try:
cfgfn = join(get_config_dir(), rootname + '.cfg')
cobj = configobj.ConfigObj(cfgfn, interpolation=False)
except (IOError, OSError) as e:
msg = ('Configuration defaults will be used, and '
'configuration cannot be saved due to ')
errstr = '' if len(e.args) < 1 else (':' + str(e.args[0]))
msg += e.__class__.__name__ + errstr
warn(ConfigurationMissingWarning(msg))

# This caches the object, so if the file becomes accessible, this
# function won't see it unless the module is reloaded
cobj = configobj.ConfigObj(interpolation=False)

_cfgobjs[rootname] = cobj

if secname: # not the root package
if secname not in cobj:
Expand Down
2 changes: 1 addition & 1 deletion astropy/io/fits/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ def _int_or_float(s):
except (ValueError, TypeError):
try:
return float(s)
except (ValueError, TypeError), e:
except (ValueError, TypeError) as e:
raise ValueError(str(e))


Expand Down
Loading