We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `setup.py`
Content:
```
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 FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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

{"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"}], "after_files": [{"content": "# Licensed under a 3-clause BSD style license - see LICENSE.rst\nimport setuptools\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"}]}