fixes test helper to not import astropy.config if invoked from setup #197

Merged
merged 3 commits into from Apr 19, 2012
View
@@ -6,6 +6,17 @@
managing them.
"""
+#this indicates whether or not we are in astropy's setup.py
+try:
+ _ASTROPY_SETUP_
+except NameError:
+ from sys import version_info
+ if version_info[0] >= 3:
+ import builtins
+ else:
+ import __builtin__ as builtins
+ builtins._ASTROPY_SETUP_ = False
+ del version_info
try:
from .version import version as __version__
View
@@ -434,11 +434,42 @@ def adjust_compiler():
def is_in_build_mode():
- return __builtins__.get('_build_mode')
+ """
+ Determines if the current package is being built.
+
+ Returns
+ -------
+ buildmode : bool
+ True if the current package is in the process of being built.
+
+ See Also
+ --------
+ `set_build_mode`
+ """
+ #_ASTROPY_SETUP_ is added to the builtins in setup.py or astropy/__init__.py
+ return _ASTROPY_SETUP_
+
+def set_build_mode(val=True):
+ """
+ Sets whether or not the current package is being built.
+
+ Parameters
+ ----------
+ val : bool
+ Whether or not build mode should be activated.
-def set_build_mode():
- __builtins__['_build_mode'] = True
+ See Also
+ --------
+ `is_in_build_mode`
+ """
+ from sys import version_info
+
+ if version_info[0] >= 3:
+ import builtins
+ else:
+ import __builtin__ as builtins
+ builtins._ASTROPY_SETUP_ = val
def setup_test_command(package_name):
View
@@ -14,11 +14,23 @@
from distutils.core import Command
-from ..config import ConfigurationItem
-
-USE_SYSTEM_PYTEST = ConfigurationItem('use_system_pytest', False,
- 'Set to True to load system pytest',
- 'boolean', 'astropy.tests.helper')
+#If we are in setup.py, we don't want to import astropy.config
+if __builtins__.get('_ASTROPY_SETUP_'):
+ if os.environ.get('ASTROPY_USE_SYSTEM_PYTEST'):
+ USE_SYSTEM_PYTEST = lambda: True
+ else:
+ USE_SYSTEM_PYTEST = lambda: False
+else:
+ from ..config import ConfigurationItem
+
+ USE_SYSTEM_PYTEST = ConfigurationItem('use_system_pytest', False,
+ 'Set to True to load system pytest. '
+ 'This item will *not* be obeyed if '
+ 'using setup.py. In that case the '
+ 'environment variable '
+ 'ASTROPY_USE_SYSTEM_TEST must be '
+ 'used',
+ 'boolean', 'astropy.tests.helper')
if USE_SYSTEM_PYTEST():
import pytest
View
@@ -9,8 +9,18 @@
import glob
import os
+import sys
from setuptools import setup, find_packages
+#A dirty hack to get around some early import/configurations ambiguities
+#This is the same as setup_helpers.set_build_mode(), but does not require
+#importing setup_helpers
+if sys.version_info[0] >= 3:
+ import builtins
+else:
+ import __builtin__ as builtins
+builtins._ASTROPY_SETUP_ = True
+
import astropy
from astropy import setup_helpers
from astropy.version_helper import get_git_devstr, generate_version_py
@@ -25,9 +35,6 @@
# broken one.
setup_helpers.adjust_compiler()
-# Indicate that we are in building mode
-setup_helpers.set_build_mode()
-
if not release:
version += get_git_devstr(False)
generate_version_py('astropy', version, release,