Repository: gammapy/gammapy

Issue:
Change from bundled to external ci-helpers?
@bsipocz split out the Astropy `ci-helpers` into a separate package:
https://groups.google.com/forum/#!topic/astropy-dev/2pn_lEdK-w4
https://github.com/astropy/ci-helpers

In Gammapy we currently have a bundled and modified (and probably slightly outdated) version of the ci-helpers copied over from the Astropy repo in https://github.com/gammapy/gammapy/tree/master/.continuous-integration .

Of course I'd like to switch to the external `ci-helpers` and have less duplicated files / scripts to maintain in Gammapy. But it's not clear to me if / how the external ci-helpers can be extended like we need it for Gammapy (using Sherpa, external test repo):
https://github.com/gammapy/gammapy/blob/master/.continuous-integration/travis/setup_dependencies_common.sh#L65
https://github.com/gammapy/gammapy/blob/master/.continuous-integration/travis/setup_dependencies_common.sh#L90

@bsipocz - Do you think using the external `ci-helpers` is a good idea (i.e. less work for the coming years) for Gammapy vs what we have now? What would your advice be e.g. where to put the setup of GAMMAPY_EXTRA or other custom setup commands?



Discussion:
@cdeil -  Using several channels is supported by `ci-helpers`, for the Sherpa channel you can use `$CONDA_CHANNELS` variable, just need to list the channels space separated.
As for the `GAMMAPY_EXTRA`, I would put it in .travis.yml, either in the `before_install`, or in the `install` section, after the `ci-helpers` cloning.

Regarding the extra work question: If everything goes well and nothing brakes in the ci system, you won't benefit from switching. But it's more probable that there will be some unforeseen changes (like the change in the conda path) that brakes the testing. With `ci-helpers` that can be fixed independently of the affiliated package maintenances, so probably less work for gammapy itself.


Resolving patch:
diff --git a/gammapy/conftest.py b/gammapy/conftest.py
--- a/gammapy/conftest.py
+++ b/gammapy/conftest.py
@@ -4,8 +4,15 @@
 
 from astropy.tests.pytest_plugins import *
 
+# This is to figure out the affiliated package version, rather than
+# using Astropy's
+from . import version
+
+packagename = os.path.basename(os.path.dirname(__file__))
+TESTED_VERSIONS[packagename] = version.version
+
 # Treat all DeprecationWarnings as exceptions
-enable_deprecations_as_exceptions()
+#enable_deprecations_as_exceptions()
 
 # Declare for which packages version numbers should be displayed
 # when running the tests
diff --git a/gammapy/image/utils.py b/gammapy/image/utils.py
--- a/gammapy/image/utils.py
+++ b/gammapy/image/utils.py
@@ -7,6 +7,9 @@
 from astropy.coordinates import Angle
 from astropy.io import fits
 from astropy.wcs import WCS
+# TODO:
+# Remove this when/if https://github.com/astropy/astropy/issues/4429 is fixed
+from astropy.utils.exceptions import AstropyDeprecationWarning
 
 __all__ = [
     'atrous_hdu',
@@ -993,12 +996,13 @@ def cube_to_image(cube, slicepos=None):
     from astropy.io.fits import ImageHDU
     header = cube.header.copy()
     header['NAXIS'] = 2
-    del header['NAXIS3']
-    del header['CRVAL3']
-    del header['CDELT3']
-    del header['CTYPE3']
-    del header['CRPIX3']
-    del header['CUNIT3']
+
+    for kword in ['NAXIS3', 'CRVAL3', 'CDELT3', 'CTYPE3', 'CRPIX3', 'CUNIT3']:
+        try:
+            del header[kword]
+        except (KeyError, AstropyDeprecationWarning):
+            pass
+
     if slicepos is None:
         data = cube.data.sum(0)
     else:
@@ -1211,7 +1215,7 @@ def lon_lat_circle_mask(lons, lats, center_lon, center_lat, radius):
     mask : `~numpy.ndarray`
         Boolean mask array for a circular sub-region
     """
-    
+
     lons.wrap_angle = Angle('180 deg')
     center_lon.wrap_angle = Angle('180 deg')
 
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -145,13 +145,13 @@
       # To find out if everything works run the Gammapy tests.
       install_requires=[
           'setuptools',
-          'numpy>=1.6',
+          'numpy>=1.8',
           'astropy>=1.0',
       ],
       extras_require=dict(
           analysis=[
               'click',
-              'scipy>=0.14',
+              'scipy>=0.15',
               'scikit-image>=0.10',
               'photutils>=0.1',
               'reproject',


Test patch:
diff --git a/gammapy/region/tests/test_reflected.py b/gammapy/region/tests/test_reflected.py
--- a/gammapy/region/tests/test_reflected.py
+++ b/gammapy/region/tests/test_reflected.py
@@ -2,12 +2,16 @@
 from __future__ import absolute_import, division, print_function, unicode_literals
 from astropy.io import fits
 from astropy.coordinates import SkyCoord, Angle
+from astropy.tests.helper import pytest
+
 from ..reflected import find_reflected_regions
 from ...image import ExclusionMask
 from ..circle import SkyCircleRegion
 from ...datasets import gammapy_extra
 from ...utils.testing import requires_data, requires_dependency
 
+
+@pytest.mark.xfail(reason="exclusion file is missing from gammapy-extra")
 @requires_dependency('scipy')
 @requires_data('gammapy-extra')
 def test_find_reflected_regions():
diff --git a/gammapy/spectrum/tests/test_spectrum_analysis.py b/gammapy/spectrum/tests/test_spectrum_analysis.py
--- a/gammapy/spectrum/tests/test_spectrum_analysis.py
+++ b/gammapy/spectrum/tests/test_spectrum_analysis.py
@@ -1,5 +1,10 @@
 # Licensed under a 3-clause BSD style license - see LICENSE.rst
-from __future__ import absolute_import, division, print_function, unicode_literals
+from __future__ import (absolute_import, division, print_function,
+                        unicode_literals)
+
+from astropy.tests.helper import pytest
+from astropy.utils.compat import NUMPY_LT_1_9
+
 from numpy.testing import assert_allclose
 from astropy.coordinates import SkyCoord, Angle
 from ...utils.testing import requires_dependency, requires_data
@@ -16,6 +21,7 @@
 )
 
 
+@pytest.mark.xfail(reason="exclusion file is missing from gammapy-extra")
 @requires_dependency('scipy')
 @requires_data('gammapy-extra')
 def test_spectrum_analysis(tmpdir):
@@ -41,6 +47,8 @@ def test_spectrum_analysis(tmpdir):
     ana.write_ogip_data(outdir=str(tmpdir))
 
 
+@pytest.mark.xfail(reason="xfailing it until issue #408 is fixed")
+@pytest.mark.skipif('NUMPY_LT_1_9')
 @requires_dependency('sherpa')
 @requires_data('gammapy-extra')
 def test_spectral_fit(tmpdir):
@@ -58,6 +66,7 @@ def test_spectral_fit(tmpdir):
     # fit.run(method='hspec')
 
 
+@pytest.mark.xfail(reason="xfailing it until issue #408 is fixed")
 @requires_dependency('yaml')
 @requires_dependency('scipy')
 @requires_dependency('sherpa')