Skip to content

Commit 1fecadb

Browse files
committed
Monkey patch astropy so that configuration system works
1 parent 499c260 commit 1fecadb

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

astroquery/__init__.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,39 @@
1515
# For egg_info test builds to pass, put package imports here.
1616
#if not _ASTROPY_SETUP_:
1717
# from astroquery import *
18+
19+
20+
# This is to monkey-patch around a config system bug in astropy 1.0.1.
21+
# REMOVEME: when astropy 1.0.1 support is no longer needed
22+
if not _ASTROPY_SETUP_:
23+
import astropy
24+
if astropy.__version__ == '1.0.1':
25+
from astropy.config import configuration
26+
27+
_existing_ConfigItem__init__ = configuration.ConfigItem.__init__
28+
29+
def _monkey_patch_1_0_1_ConfigItem__init__(
30+
self, defaultvalue='', description=None, cfgtype=None,
31+
module=None, aliases=None):
32+
if module is None:
33+
from astropy.utils import find_current_module
34+
module = find_current_module(2)
35+
if module is None:
36+
msg1 = 'Cannot automatically determine get_config module, '
37+
msg2 = 'because it is not called from inside a valid module'
38+
raise RuntimeError(msg1 + msg2)
39+
else:
40+
module = module.__name__
41+
42+
return _existing_ConfigItem__init__(
43+
self,
44+
defaultvalue=defaultvalue,
45+
description=description,
46+
cfgtype=cfgtype,
47+
module=module,
48+
aliases=aliases)
49+
50+
# Don't apply the same monkey patch twice
51+
if (configuration.ConfigItem.__init__.__name__ !=
52+
'_monkey_patch_1_0_1_ConfigItem__init__'):
53+
configuration.ConfigItem.__init__ = _monkey_patch_1_0_1_ConfigItem__init__

0 commit comments

Comments
 (0)