prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Install fails when Cython is not already installed
  **Gammapy version**
  
  Every I tested
  
  **Bug description**
  
  The setup.py hard imports Cython, so setuptools has no chance to install it.
  
  **Expected behavior**
  
  Install cython if needed before attempting to import it
  
  **To Reproduce**
  
  
  ```
  $ python -m venv test_gammapy
  $ . test_gammapy/bin/activate
  $ pip install gammapy
  ```
  
  
  **Other information**
  There is a very simple fix: provide a pyproject.toml that requires cython for the build system.
  
  
  </issue>
  <code>
  [start of setup.py]
  1 # Licensed under a 3-clause BSD style license - see LICENSE.rst
  2 import sys
  3 import setuptools
  4 from distutils.version import LooseVersion
  5 
  6 if LooseVersion(setuptools.__version__) < "30.3":
  7     sys.stderr.write("ERROR: setuptools 30.3 or later is required by gammapy\n")
  8     sys.exit(1)
  9 
  10 # TODO: check if setuptools_scm, numpy, ... are OK
  11 # Exit with good error message telling people to install those first if not
  12 
  13 
  14 from Cython.Build import cythonize
  15 from distutils.extension import Extension
  16 import numpy as np
  17 
  18 
  19 def make_cython_extension(filename):
  20     return Extension(
  21         filename.strip(".pyx").replace("/", "."),
  22         [filename],
  23         include_dirs=[np.get_include()],
  24     )
  25 
  26 
  27 cython_files = [
  28     "gammapy/stats/fit_statistics_cython.pyx",
  29 ]
  30 
  31 ext_modules = cythonize([make_cython_extension(_) for _ in cython_files])
  32 
  33 setuptools.setup(use_scm_version=True, ext_modules=ext_modules)
  34
  [end of setup.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/setup.py b/setup.py
  --- a/setup.py
  +++ b/setup.py
  @@ -1,16 +1,5 @@
   # Licensed under a 3-clause BSD style license - see LICENSE.rst
  -import sys
   import setuptools
  -from distutils.version import LooseVersion
  -
  -if LooseVersion(setuptools.__version__) < "30.3":
  -    sys.stderr.write("ERROR: setuptools 30.3 or later is required by gammapy\n")
  -    sys.exit(1)
  -
  -# TODO: check if setuptools_scm, numpy, ... are OK
  -# Exit with good error message telling people to install those first if not
  -
  -
   from Cython.Build import cythonize
   from distutils.extension import Extension
   import numpy as np
  
verification_info: {"golden_diff": "diff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -1,16 +1,5 @@\n # Licensed under a 3-clause BSD style license - see LICENSE.rst\n-import sys\n import setuptools\n-from distutils.version import LooseVersion\n-\n-if LooseVersion(setuptools.__version__) < \"30.3\":\n-    sys.stderr.write(\"ERROR: setuptools 30.3 or later is required by gammapy\\n\")\n-    sys.exit(1)\n-\n-# TODO: check if setuptools_scm, numpy, ... are OK\n-# Exit with good error message telling people to install those first if not\n-\n-\n from Cython.Build import cythonize\n from distutils.extension import Extension\n import numpy as np\n", "issue": "Install fails when Cython is not already installed\n**Gammapy version**\r\n\r\nEvery I tested\r\n\r\n**Bug description**\r\n\r\nThe setup.py hard imports Cython, so setuptools has no chance to install it.\r\n\r\n**Expected behavior**\r\n\r\nInstall cython if needed before attempting to import it\r\n\r\n**To Reproduce**\r\n\r\n\r\n```\r\n$ python -m venv test_gammapy\r\n$ . test_gammapy/bin/activate\r\n$ pip install gammapy\r\n```\r\n\r\n\r\n**Other information**\r\nThere is a very simple fix: provide a pyproject.toml that requires cython for the build system.\r\n\n", "before_files": [{"content": "# Licensed under a 3-clause BSD style license - see LICENSE.rst\nimport sys\nimport setuptools\nfrom distutils.version import LooseVersion\n\nif LooseVersion(setuptools.__version__) < \"30.3\":\n    sys.stderr.write(\"ERROR: setuptools 30.3 or later is required by gammapy\\n\")\n    sys.exit(1)\n\n# TODO: check if setuptools_scm, numpy, ... are OK\n# Exit with good error message telling people to install those first if not\n\n\nfrom Cython.Build import cythonize\nfrom distutils.extension import Extension\nimport numpy as np\n\n\ndef make_cython_extension(filename):\n    return Extension(\n        filename.strip(\".pyx\").replace(\"/\", \".\"),\n        [filename],\n        include_dirs=[np.get_include()],\n    )\n\n\ncython_files = [\n    \"gammapy/stats/fit_statistics_cython.pyx\",\n]\n\next_modules = cythonize([make_cython_extension(_) for _ in cython_files])\n\nsetuptools.setup(use_scm_version=True, ext_modules=ext_modules)\n", "path": "setup.py"}]}