We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Remove the need to have astropy installed before installing SunPy
Currently you can not have a clean python environment and do a `pip install sunpy` you have to have astropy + numpy installed first.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `sunpy/io/setup_package.py`
Content:
```
1 from __future__ import absolute_import
2 
3 import os
4 import platform
5 
6 from distutils.core import Extension
7 from glob import glob
8 
9 from astropy_helpers import setup_helpers
10 from astropy.extern import six
11 
12 
13 def get_extensions():
14 
15     if platform.system() == 'Windows' or six.PY3:
16         return list()
17     else:
18         # 'numpy' will be replaced with the proper path to the numpy includes
19         cfg = setup_helpers.DistutilsExtensionArgs()
20         cfg['include_dirs'].append('numpy')
21         cfg['sources'].extend(glob(os.path.join(os.path.dirname(__file__), 'src', 'ana', '*.c')))
22         cfg['extra_compile_args'].extend(['-std=c99', '-O3'])
23         # Squash some warnings
24         cfg['extra_compile_args'].extend(['-Wno-unused-but-set-variable',
25                                           '-Wno-unused-variable',
26                                           '-Wno-unused-result'])
27 
28         e = Extension('sunpy.io._pyana', **cfg)
29         return [e]
30 
31 def requires_2to3():
32     return False
33
```

Path: `setup.py`
Content:
```
1 #!/usr/bin/env python
2 # This file is based havily on the astropy version here:
3 # https://github.com/astropy/package-template/blob/master/setup.py
4 # Which is licensed under the astropy license.
5 
6 import glob
7 import os
8 import sys
9 
10 import ah_bootstrap
11 from setuptools import setup
12 
13 # A dirty hack to get around some early import/configurations ambiguities
14 if sys.version_info[0] >= 3:
15     import builtins
16 else:
17     import __builtin__ as builtins
18 builtins._ASTROPY_SETUP_ = True
19 
20 # -- Read the Docs Setup  -----------------------------------------------------
21 
22 on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
23 
24 if on_rtd:
25     os.environ['HOME'] = '/home/docs/checkouts/readthedocs.org/user_builds/sunpy/'
26     os.environ['SUNPY_CONFIGDIR'] = '/home/docs/checkouts/readthedocs.org/user_builds/sunpy/'
27 
28 from astropy_helpers.setup_helpers import (
29     register_commands, adjust_compiler, get_debug_option, get_package_info)
30 from astropy_helpers.git_helpers import get_git_devstr
31 from astropy_helpers.version_helpers import generate_version_py
32 from sunpy.tests.setup_command import SunPyTest
33 
34 # Get some values from the setup.cfg
35 from distutils import config
36 conf = config.ConfigParser()
37 conf.read(['setup.cfg'])
38 metadata = dict(conf.items('metadata'))
39 
40 PACKAGENAME = metadata.get('package_name', 'packagename')
41 DESCRIPTION = metadata.get('description', 'SunPy: Python for Solar Physics')
42 AUTHOR = metadata.get('author', 'The SunPy Community')
43 AUTHOR_EMAIL = metadata.get('author_email', 'sunpy@googlegroups.com')
44 LICENSE = metadata.get('license', 'BSD 2-Clause')
45 URL = metadata.get('url', 'http://sunpy.org')
46 
47 LONG_DESCRIPTION = "SunPy is a Python library for solar physics data analysis."
48 
49 # Store the package name in a built-in variable so it's easy
50 # to get from other parts of the setup infrastructure
51 builtins._ASTROPY_PACKAGE_NAME_ = PACKAGENAME
52 
53 # VERSION should be PEP386 compatible (http://www.python.org/dev/peps/pep-0386)
54 VERSION = '0.7.dev'
55 
56 # Indicates if this version is a release version
57 RELEASE = 'dev' not in VERSION
58 
59 if not RELEASE:
60     VERSION += get_git_devstr(False)
61 
62 # Populate the dict of setup command overrides; this should be done before
63 # invoking any other functionality from distutils since it can potentially
64 # modify distutils' behavior.
65 cmdclassd = register_commands(PACKAGENAME, VERSION, RELEASE)
66 
67 # Overwrite the Astropy Testing framework
68 cmdclassd['test'] = type('SunPyTest', (SunPyTest,),
69                          {'package_name': 'sunpy'})
70 
71 # Adjust the compiler in case the default on this platform is to use a
72 # broken one.
73 adjust_compiler(PACKAGENAME)
74 
75 # Freeze build information in version.py
76 generate_version_py(PACKAGENAME, VERSION, RELEASE,
77                     get_debug_option(PACKAGENAME))
78 
79 # Treat everything in scripts except README.rst as a script to be installed
80 scripts = [fname for fname in glob.glob(os.path.join('scripts', '*'))
81            if os.path.basename(fname) != 'README.rst']
82 
83 
84 # Get configuration information from all of the various subpackages.
85 # See the docstring for setup_helpers.update_package_files for more
86 # details.
87 package_info = get_package_info()
88 
89 # Add the project-global data
90 package_info['package_data'].setdefault(PACKAGENAME, [])
91 
92 # Include all .c files, recursively, including those generated by
93 # Cython, since we can not do this in MANIFEST.in with a "dynamic"
94 # directory name.
95 c_files = []
96 for root, dirs, files in os.walk(PACKAGENAME):
97     for filename in files:
98         if filename.endswith('.c'):
99             c_files.append(
100                 os.path.join(
101                     os.path.relpath(root, PACKAGENAME), filename))
102 package_info['package_data'][PACKAGENAME].extend(c_files)
103 
104 extras_require = {'database': ["sqlalchemy"],
105                   'image': ["scikit-image"],
106                   'jpeg2000': ["glymur"],
107                   'net': ["suds", "beautifulsoup4", "requests"]}
108 extras_require['all'] = extras_require['database'] + extras_require['image'] + \
109                         extras_require['net'] + ["wcsaxes>=0.6"]
110 
111 setup(name=PACKAGENAME,
112       version=VERSION,
113       description=DESCRIPTION,
114       scripts=scripts,
115       setup_requires=['numpy>1.7.1'],
116       install_requires=['numpy>1.7.1',
117                         'astropy>=1.0.0',
118                         'scipy',
119                         'pandas>=0.12.0',
120                         'matplotlib>=1.1'],
121       extras_require=extras_require,
122       provides=[PACKAGENAME],
123       author=AUTHOR,
124       author_email=AUTHOR_EMAIL,
125       license=LICENSE,
126       url=URL,
127       long_description=LONG_DESCRIPTION,
128       cmdclass=cmdclassd,
129       zip_safe=False,
130       use_2to3=False,
131       include_package_data=True,
132       **package_info
133       )
134
```
--- 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
@@ -29,7 +29,6 @@
     register_commands, adjust_compiler, get_debug_option, get_package_info)
 from astropy_helpers.git_helpers import get_git_devstr
 from astropy_helpers.version_helpers import generate_version_py
-from sunpy.tests.setup_command import SunPyTest
 
 # Get some values from the setup.cfg
 from distutils import config
@@ -64,9 +63,14 @@
 # modify distutils' behavior.
 cmdclassd = register_commands(PACKAGENAME, VERSION, RELEASE)
 
-# Overwrite the Astropy Testing framework
-cmdclassd['test'] = type('SunPyTest', (SunPyTest,),
-                         {'package_name': 'sunpy'})
+try:
+    from sunpy.tests.setup_command import SunPyTest
+    # Overwrite the Astropy Testing framework
+    cmdclassd['test'] = type('SunPyTest', (SunPyTest,),
+                            {'package_name': 'sunpy'})
+except Exception:
+    # Catch everything, if it doesn't work, we still want SunPy to install.
+    pass
 
 # Adjust the compiler in case the default on this platform is to use a
 # broken one.
diff --git a/sunpy/io/setup_package.py b/sunpy/io/setup_package.py
--- a/sunpy/io/setup_package.py
+++ b/sunpy/io/setup_package.py
@@ -1,18 +1,18 @@
 from __future__ import absolute_import
 
 import os
+import sys
 import platform
 
 from distutils.core import Extension
 from glob import glob
 
 from astropy_helpers import setup_helpers
-from astropy.extern import six
 
 
 def get_extensions():
 
-    if platform.system() == 'Windows' or six.PY3:
+    if platform.system() == 'Windows' or sys.version_info.major == 3:
         return list()
     else:
         # 'numpy' will be replaced with the proper path to the numpy includes

{"golden_diff": "diff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -29,7 +29,6 @@\n     register_commands, adjust_compiler, get_debug_option, get_package_info)\n from astropy_helpers.git_helpers import get_git_devstr\n from astropy_helpers.version_helpers import generate_version_py\n-from sunpy.tests.setup_command import SunPyTest\n \n # Get some values from the setup.cfg\n from distutils import config\n@@ -64,9 +63,14 @@\n # modify distutils' behavior.\n cmdclassd = register_commands(PACKAGENAME, VERSION, RELEASE)\n \n-# Overwrite the Astropy Testing framework\n-cmdclassd['test'] = type('SunPyTest', (SunPyTest,),\n-                         {'package_name': 'sunpy'})\n+try:\n+    from sunpy.tests.setup_command import SunPyTest\n+    # Overwrite the Astropy Testing framework\n+    cmdclassd['test'] = type('SunPyTest', (SunPyTest,),\n+                            {'package_name': 'sunpy'})\n+except Exception:\n+    # Catch everything, if it doesn't work, we still want SunPy to install.\n+    pass\n \n # Adjust the compiler in case the default on this platform is to use a\n # broken one.\ndiff --git a/sunpy/io/setup_package.py b/sunpy/io/setup_package.py\n--- a/sunpy/io/setup_package.py\n+++ b/sunpy/io/setup_package.py\n@@ -1,18 +1,18 @@\n from __future__ import absolute_import\n \n import os\n+import sys\n import platform\n \n from distutils.core import Extension\n from glob import glob\n \n from astropy_helpers import setup_helpers\n-from astropy.extern import six\n \n \n def get_extensions():\n \n-    if platform.system() == 'Windows' or six.PY3:\n+    if platform.system() == 'Windows' or sys.version_info.major == 3:\n         return list()\n     else:\n         # 'numpy' will be replaced with the proper path to the numpy includes\n", "issue": "Remove the need to have astropy installed before installing SunPy\nCurrently you can not have a clean python environment and do a `pip install sunpy` you have to have astropy + numpy installed first.\n\n", "before_files": [{"content": "from __future__ import absolute_import\n\nimport os\nimport platform\n\nfrom distutils.core import Extension\nfrom glob import glob\n\nfrom astropy_helpers import setup_helpers\nfrom astropy.extern import six\n\n\ndef get_extensions():\n\n    if platform.system() == 'Windows' or six.PY3:\n        return list()\n    else:\n        # 'numpy' will be replaced with the proper path to the numpy includes\n        cfg = setup_helpers.DistutilsExtensionArgs()\n        cfg['include_dirs'].append('numpy')\n        cfg['sources'].extend(glob(os.path.join(os.path.dirname(__file__), 'src', 'ana', '*.c')))\n        cfg['extra_compile_args'].extend(['-std=c99', '-O3'])\n        # Squash some warnings\n        cfg['extra_compile_args'].extend(['-Wno-unused-but-set-variable',\n                                          '-Wno-unused-variable',\n                                          '-Wno-unused-result'])\n\n        e = Extension('sunpy.io._pyana', **cfg)\n        return [e]\n\ndef requires_2to3():\n    return False\n", "path": "sunpy/io/setup_package.py"}, {"content": "#!/usr/bin/env python\n# This file is based havily on the astropy version here:\n# https://github.com/astropy/package-template/blob/master/setup.py\n# Which is licensed under the astropy license.\n\nimport glob\nimport os\nimport sys\n\nimport ah_bootstrap\nfrom setuptools import setup\n\n# A dirty hack to get around some early import/configurations ambiguities\nif sys.version_info[0] >= 3:\n    import builtins\nelse:\n    import __builtin__ as builtins\nbuiltins._ASTROPY_SETUP_ = True\n\n# -- Read the Docs Setup  -----------------------------------------------------\n\non_rtd = os.environ.get('READTHEDOCS', None) == 'True'\n\nif on_rtd:\n    os.environ['HOME'] = '/home/docs/checkouts/readthedocs.org/user_builds/sunpy/'\n    os.environ['SUNPY_CONFIGDIR'] = '/home/docs/checkouts/readthedocs.org/user_builds/sunpy/'\n\nfrom astropy_helpers.setup_helpers import (\n    register_commands, adjust_compiler, get_debug_option, get_package_info)\nfrom astropy_helpers.git_helpers import get_git_devstr\nfrom astropy_helpers.version_helpers import generate_version_py\nfrom sunpy.tests.setup_command import SunPyTest\n\n# Get some values from the setup.cfg\nfrom distutils import config\nconf = config.ConfigParser()\nconf.read(['setup.cfg'])\nmetadata = dict(conf.items('metadata'))\n\nPACKAGENAME = metadata.get('package_name', 'packagename')\nDESCRIPTION = metadata.get('description', 'SunPy: Python for Solar Physics')\nAUTHOR = metadata.get('author', 'The SunPy Community')\nAUTHOR_EMAIL = metadata.get('author_email', 'sunpy@googlegroups.com')\nLICENSE = metadata.get('license', 'BSD 2-Clause')\nURL = metadata.get('url', 'http://sunpy.org')\n\nLONG_DESCRIPTION = \"SunPy is a Python library for solar physics data analysis.\"\n\n# Store the package name in a built-in variable so it's easy\n# to get from other parts of the setup infrastructure\nbuiltins._ASTROPY_PACKAGE_NAME_ = PACKAGENAME\n\n# VERSION should be PEP386 compatible (http://www.python.org/dev/peps/pep-0386)\nVERSION = '0.7.dev'\n\n# Indicates if this version is a release version\nRELEASE = 'dev' not in VERSION\n\nif not RELEASE:\n    VERSION += get_git_devstr(False)\n\n# Populate the dict of setup command overrides; this should be done before\n# invoking any other functionality from distutils since it can potentially\n# modify distutils' behavior.\ncmdclassd = register_commands(PACKAGENAME, VERSION, RELEASE)\n\n# Overwrite the Astropy Testing framework\ncmdclassd['test'] = type('SunPyTest', (SunPyTest,),\n                         {'package_name': 'sunpy'})\n\n# Adjust the compiler in case the default on this platform is to use a\n# broken one.\nadjust_compiler(PACKAGENAME)\n\n# Freeze build information in version.py\ngenerate_version_py(PACKAGENAME, VERSION, RELEASE,\n                    get_debug_option(PACKAGENAME))\n\n# Treat everything in scripts except README.rst as a script to be installed\nscripts = [fname for fname in glob.glob(os.path.join('scripts', '*'))\n           if os.path.basename(fname) != 'README.rst']\n\n\n# Get configuration information from all of the various subpackages.\n# See the docstring for setup_helpers.update_package_files for more\n# details.\npackage_info = get_package_info()\n\n# Add the project-global data\npackage_info['package_data'].setdefault(PACKAGENAME, [])\n\n# Include all .c files, recursively, including those generated by\n# Cython, since we can not do this in MANIFEST.in with a \"dynamic\"\n# directory name.\nc_files = []\nfor root, dirs, files in os.walk(PACKAGENAME):\n    for filename in files:\n        if filename.endswith('.c'):\n            c_files.append(\n                os.path.join(\n                    os.path.relpath(root, PACKAGENAME), filename))\npackage_info['package_data'][PACKAGENAME].extend(c_files)\n\nextras_require = {'database': [\"sqlalchemy\"],\n                  'image': [\"scikit-image\"],\n                  'jpeg2000': [\"glymur\"],\n                  'net': [\"suds\", \"beautifulsoup4\", \"requests\"]}\nextras_require['all'] = extras_require['database'] + extras_require['image'] + \\\n                        extras_require['net'] + [\"wcsaxes>=0.6\"]\n\nsetup(name=PACKAGENAME,\n      version=VERSION,\n      description=DESCRIPTION,\n      scripts=scripts,\n      setup_requires=['numpy>1.7.1'],\n      install_requires=['numpy>1.7.1',\n                        'astropy>=1.0.0',\n                        'scipy',\n                        'pandas>=0.12.0',\n                        'matplotlib>=1.1'],\n      extras_require=extras_require,\n      provides=[PACKAGENAME],\n      author=AUTHOR,\n      author_email=AUTHOR_EMAIL,\n      license=LICENSE,\n      url=URL,\n      long_description=LONG_DESCRIPTION,\n      cmdclass=cmdclassd,\n      zip_safe=False,\n      use_2to3=False,\n      include_package_data=True,\n      **package_info\n      )\n", "path": "setup.py"}], "after_files": [{"content": "from __future__ import absolute_import\n\nimport os\nimport sys\nimport platform\n\nfrom distutils.core import Extension\nfrom glob import glob\n\nfrom astropy_helpers import setup_helpers\n\n\ndef get_extensions():\n\n    if platform.system() == 'Windows' or sys.version_info.major == 3:\n        return list()\n    else:\n        # 'numpy' will be replaced with the proper path to the numpy includes\n        cfg = setup_helpers.DistutilsExtensionArgs()\n        cfg['include_dirs'].append('numpy')\n        cfg['sources'].extend(glob(os.path.join(os.path.dirname(__file__), 'src', 'ana', '*.c')))\n        cfg['extra_compile_args'].extend(['-std=c99', '-O3'])\n        # Squash some warnings\n        cfg['extra_compile_args'].extend(['-Wno-unused-but-set-variable',\n                                          '-Wno-unused-variable',\n                                          '-Wno-unused-result'])\n\n        e = Extension('sunpy.io._pyana', **cfg)\n        return [e]\n\ndef requires_2to3():\n    return False\n", "path": "sunpy/io/setup_package.py"}, {"content": "#!/usr/bin/env python\n# This file is based havily on the astropy version here:\n# https://github.com/astropy/package-template/blob/master/setup.py\n# Which is licensed under the astropy license.\n\nimport glob\nimport os\nimport sys\n\nimport ah_bootstrap\nfrom setuptools import setup\n\n# A dirty hack to get around some early import/configurations ambiguities\nif sys.version_info[0] >= 3:\n    import builtins\nelse:\n    import __builtin__ as builtins\nbuiltins._ASTROPY_SETUP_ = True\n\n# -- Read the Docs Setup  -----------------------------------------------------\n\non_rtd = os.environ.get('READTHEDOCS', None) == 'True'\n\nif on_rtd:\n    os.environ['HOME'] = '/home/docs/checkouts/readthedocs.org/user_builds/sunpy/'\n    os.environ['SUNPY_CONFIGDIR'] = '/home/docs/checkouts/readthedocs.org/user_builds/sunpy/'\n\nfrom astropy_helpers.setup_helpers import (\n    register_commands, adjust_compiler, get_debug_option, get_package_info)\nfrom astropy_helpers.git_helpers import get_git_devstr\nfrom astropy_helpers.version_helpers import generate_version_py\n\n# Get some values from the setup.cfg\nfrom distutils import config\nconf = config.ConfigParser()\nconf.read(['setup.cfg'])\nmetadata = dict(conf.items('metadata'))\n\nPACKAGENAME = metadata.get('package_name', 'packagename')\nDESCRIPTION = metadata.get('description', 'SunPy: Python for Solar Physics')\nAUTHOR = metadata.get('author', 'The SunPy Community')\nAUTHOR_EMAIL = metadata.get('author_email', 'sunpy@googlegroups.com')\nLICENSE = metadata.get('license', 'BSD 2-Clause')\nURL = metadata.get('url', 'http://sunpy.org')\n\nLONG_DESCRIPTION = \"SunPy is a Python library for solar physics data analysis.\"\n\n# Store the package name in a built-in variable so it's easy\n# to get from other parts of the setup infrastructure\nbuiltins._ASTROPY_PACKAGE_NAME_ = PACKAGENAME\n\n# VERSION should be PEP386 compatible (http://www.python.org/dev/peps/pep-0386)\nVERSION = '0.7.dev'\n\n# Indicates if this version is a release version\nRELEASE = 'dev' not in VERSION\n\nif not RELEASE:\n    VERSION += get_git_devstr(False)\n\n# Populate the dict of setup command overrides; this should be done before\n# invoking any other functionality from distutils since it can potentially\n# modify distutils' behavior.\ncmdclassd = register_commands(PACKAGENAME, VERSION, RELEASE)\n\ntry:\n    from sunpy.tests.setup_command import SunPyTest\n    # Overwrite the Astropy Testing framework\n    cmdclassd['test'] = type('SunPyTest', (SunPyTest,),\n                            {'package_name': 'sunpy'})\nexcept Exception:\n    # Catch everything, if it doesn't work, we still want SunPy to install.\n    pass\n\n# Adjust the compiler in case the default on this platform is to use a\n# broken one.\nadjust_compiler(PACKAGENAME)\n\n# Freeze build information in version.py\ngenerate_version_py(PACKAGENAME, VERSION, RELEASE,\n                    get_debug_option(PACKAGENAME))\n\n# Treat everything in scripts except README.rst as a script to be installed\nscripts = [fname for fname in glob.glob(os.path.join('scripts', '*'))\n           if os.path.basename(fname) != 'README.rst']\n\n\n# Get configuration information from all of the various subpackages.\n# See the docstring for setup_helpers.update_package_files for more\n# details.\npackage_info = get_package_info()\n\n# Add the project-global data\npackage_info['package_data'].setdefault(PACKAGENAME, [])\n\n# Include all .c files, recursively, including those generated by\n# Cython, since we can not do this in MANIFEST.in with a \"dynamic\"\n# directory name.\nc_files = []\nfor root, dirs, files in os.walk(PACKAGENAME):\n    for filename in files:\n        if filename.endswith('.c'):\n            c_files.append(\n                os.path.join(\n                    os.path.relpath(root, PACKAGENAME), filename))\npackage_info['package_data'][PACKAGENAME].extend(c_files)\n\nextras_require = {'database': [\"sqlalchemy\"],\n                  'image': [\"scikit-image\"],\n                  'jpeg2000': [\"glymur\"],\n                  'net': [\"suds\", \"beautifulsoup4\", \"requests\"]}\nextras_require['all'] = extras_require['database'] + extras_require['image'] + \\\n                        extras_require['net'] + [\"wcsaxes>=0.6\"]\n\nsetup(name=PACKAGENAME,\n      version=VERSION,\n      description=DESCRIPTION,\n      scripts=scripts,\n      setup_requires=['numpy>1.7.1'],\n      install_requires=['numpy>1.7.1',\n                        'astropy>=1.0.0',\n                        'scipy',\n                        'pandas>=0.12.0',\n                        'matplotlib>=1.1'],\n      extras_require=extras_require,\n      provides=[PACKAGENAME],\n      author=AUTHOR,\n      author_email=AUTHOR_EMAIL,\n      license=LICENSE,\n      url=URL,\n      long_description=LONG_DESCRIPTION,\n      cmdclass=cmdclassd,\n      zip_safe=False,\n      use_2to3=False,\n      include_package_data=True,\n      **package_info\n      )\n", "path": "setup.py"}]}