We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
pyreadline version dependency not correctly checked
Installing IPython on windows with `python setup.py install` and pyreadline 1.5:

<pre>
C:\code\dev_trees\ipython [main-master]> ipython
Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 0.13.dev -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
Traceback (most recent call last):
  File "C:\Python26\Scripts\ipython-script.py", line 9, in <module>
    load_entry_point('ipython==0.13.dev', 'console_scripts', 'ipython')()
  File "C:\Python26\lib\site-packages\ipython-0.13.dev-py2.6.egg\IPython\frontend\terminal\ipapp.py", line 409, in launch_new_instance
    app.start()
  File "C:\Python26\lib\site-packages\ipython-0.13.dev-py2.6.egg\IPython\frontend\terminal\ipapp.py", line 383, in start
    self.shell.mainloop()
  File "C:\Python26\lib\site-packages\ipython-0.13.dev-py2.6.egg\IPython\frontend\terminal\interactiveshell.py", line 290, in mainloop
    self.interact(display_banner=display_banner)
  File "C:\Python26\lib\site-packages\ipython-0.13.dev-py2.6.egg\IPython\frontend\terminal\interactiveshell.py", line 346, in interact
    hlen_b4_cell = self.readline.get_current_history_length()
AttributeError: 'module' object has no attribute 'get_current_history_length'
</pre>


I see that `setup.py` `requires` pyreadline >= 1.7.1, iff `setupext.check_for_readline()` returns False.  However, in my case, it returns True because the function does not check the version, and I have version 1.5.   I wasn't sure how best to put the version dependency into the function.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `setupext/setupext.py`
Content:
```
1 # encoding: utf-8
2 from __future__ import print_function
3 
4 __docformat__ = "restructuredtext en"
5 
6 #-------------------------------------------------------------------------------
7 #  Copyright (C) 2008  The IPython Development Team
8 #
9 #  Distributed under the terms of the BSD License.  The full license is in
10 #  the file COPYING, distributed as part of this software.
11 #-------------------------------------------------------------------------------
12 
13 #-------------------------------------------------------------------------------
14 # Imports
15 #-------------------------------------------------------------------------------
16 
17 import sys, os
18 from textwrap import fill
19 
20 display_status=True
21 
22 def check_display(f):
23     """decorator to allow display methods to be muted by mod.display_status"""
24     def maybe_display(*args, **kwargs):
25         if display_status:
26             return f(*args, **kwargs)
27     return maybe_display
28 
29 @check_display
30 def print_line(char='='):
31     print(char * 76)
32 
33 @check_display
34 def print_status(package, status):
35     initial_indent = "%22s: " % package
36     indent = ' ' * 24
37     print(fill(str(status), width=76,
38                initial_indent=initial_indent,
39                subsequent_indent=indent))
40 
41 @check_display
42 def print_message(message):
43     indent = ' ' * 24 + "* "
44     print(fill(str(message), width=76,
45                initial_indent=indent,
46                subsequent_indent=indent))
47 
48 @check_display
49 def print_raw(section):
50     print(section)
51 
52 #-------------------------------------------------------------------------------
53 # Tests for specific packages
54 #-------------------------------------------------------------------------------
55 
56 def check_for_ipython():
57     try:
58         import IPython
59     except ImportError:
60         print_status("IPython", "Not found")
61         return False
62     else:
63         print_status("IPython", IPython.__version__)
64         return True
65 
66 def check_for_sphinx():
67     try:
68         import sphinx
69     except ImportError:
70         print_status('sphinx', "Not found (required for building documentation)")
71         return False
72     else:
73         print_status('sphinx', sphinx.__version__)
74         return True
75 
76 def check_for_pygments():
77     try:
78         import pygments
79     except ImportError:
80         print_status('pygments', "Not found (required for syntax highlighting documentation)")
81         return False
82     else:
83         print_status('pygments', pygments.__version__)
84         return True
85 
86 def check_for_nose():
87     try:
88         import nose
89     except ImportError:
90         print_status('nose', "Not found (required for running the test suite)")
91         return False
92     else:
93         print_status('nose', nose.__version__)
94         return True
95 
96 def check_for_pexpect():
97     try:
98         import pexpect
99     except ImportError:
100         print_status("pexpect", "no (required for running standalone doctests)")
101         return False
102     else:
103         print_status("pexpect", pexpect.__version__)
104         return True
105 
106 def check_for_httplib2():
107     try:
108         import httplib2
109     except ImportError:
110         print_status("httplib2", "no (required for blocking http clients)")
111         return False
112     else:
113         print_status("httplib2","yes")
114         return True
115 
116 def check_for_sqlalchemy():
117     try:
118         import sqlalchemy
119     except ImportError:
120         print_status("sqlalchemy", "no (required for the ipython1 notebook)")
121         return False
122     else:
123         print_status("sqlalchemy","yes")
124         return True
125 
126 def check_for_simplejson():
127     try:
128         import simplejson
129     except ImportError:
130         print_status("simplejson", "no (required for the ipython1 notebook)")
131         return False
132     else:
133         print_status("simplejson","yes")
134         return True
135 
136 def check_for_pyzmq():
137     try:
138         import zmq
139     except ImportError:
140         print_status('pyzmq', "no (required for qtconsole, notebook, and parallel computing capabilities)")
141         return False
142     else:
143         # pyzmq 2.1.10 adds pyzmq_version_info funtion for returning
144         # version as a tuple
145         if hasattr(zmq, 'pyzmq_version_info'):
146             if zmq.pyzmq_version_info() >= (2,1,4):
147                 print_status("pyzmq", zmq.__version__)
148                 return True
149             else:
150                 # this branch can never occur, at least until we update our
151                 # pyzmq dependency beyond 2.1.10
152                 return False
153         # this is necessarily earlier than 2.1.10, so string comparison is
154         # okay
155         if zmq.__version__ < '2.1.4':
156             print_status('pyzmq', "no (have %s, but require >= 2.1.4 for"
157             " qtconsole and parallel computing capabilities)"%zmq.__version__)
158             return False
159         else:
160             print_status("pyzmq", zmq.__version__)
161             return True
162 
163 def check_for_readline():
164     try:
165         import readline
166     except ImportError:
167         try:
168             import pyreadline
169         except ImportError:
170             print_status('readline', "no (required for good interactive behavior)")
171             return False
172         else:
173             print_status('readline', "yes pyreadline-"+pyreadline.release.version)
174             return True
175     else:
176         print_status('readline', "yes")
177         return True
178
```
--- 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/setupext/setupext.py b/setupext/setupext.py
--- a/setupext/setupext.py
+++ b/setupext/setupext.py
@@ -161,17 +161,22 @@
             return True
 
 def check_for_readline():
+    from distutils.version import LooseVersion
     try:
         import readline
     except ImportError:
         try:
             import pyreadline
-        except ImportError:
+            vs = pyreadline.release.version
+        except (ImportError, AttributeError):
             print_status('readline', "no (required for good interactive behavior)")
             return False
-        else:
-            print_status('readline', "yes pyreadline-"+pyreadline.release.version)
+        if LooseVersion(vs).version >= [1,7,1]:
+            print_status('readline', "yes pyreadline-" + vs)
             return True
+        else:
+            print_status('readline', "no pyreadline-%s < 1.7.1" % vs)
+            return False
     else:
         print_status('readline', "yes")
         return True

{"golden_diff": "diff --git a/setupext/setupext.py b/setupext/setupext.py\n--- a/setupext/setupext.py\n+++ b/setupext/setupext.py\n@@ -161,17 +161,22 @@\n             return True\n \n def check_for_readline():\n+    from distutils.version import LooseVersion\n     try:\n         import readline\n     except ImportError:\n         try:\n             import pyreadline\n-        except ImportError:\n+            vs = pyreadline.release.version\n+        except (ImportError, AttributeError):\n             print_status('readline', \"no (required for good interactive behavior)\")\n             return False\n-        else:\n-            print_status('readline', \"yes pyreadline-\"+pyreadline.release.version)\n+        if LooseVersion(vs).version >= [1,7,1]:\n+            print_status('readline', \"yes pyreadline-\" + vs)\n             return True\n+        else:\n+            print_status('readline', \"no pyreadline-%s < 1.7.1\" % vs)\n+            return False\n     else:\n         print_status('readline', \"yes\")\n         return True\n", "issue": "pyreadline version dependency not correctly checked\nInstalling IPython on windows with `python setup.py install` and pyreadline 1.5:\n\n<pre>\nC:\\code\\dev_trees\\ipython [main-master]> ipython\nPython 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)]\nType \"copyright\", \"credits\" or \"license\" for more information.\n\nIPython 0.13.dev -- An enhanced Interactive Python.\n?         -> Introduction and overview of IPython's features.\n%quickref -> Quick reference.\nhelp      -> Python's own help system.\nobject?   -> Details about 'object', use 'object??' for extra details.\nTraceback (most recent call last):\n  File \"C:\\Python26\\Scripts\\ipython-script.py\", line 9, in <module>\n    load_entry_point('ipython==0.13.dev', 'console_scripts', 'ipython')()\n  File \"C:\\Python26\\lib\\site-packages\\ipython-0.13.dev-py2.6.egg\\IPython\\frontend\\terminal\\ipapp.py\", line 409, in launch_new_instance\n    app.start()\n  File \"C:\\Python26\\lib\\site-packages\\ipython-0.13.dev-py2.6.egg\\IPython\\frontend\\terminal\\ipapp.py\", line 383, in start\n    self.shell.mainloop()\n  File \"C:\\Python26\\lib\\site-packages\\ipython-0.13.dev-py2.6.egg\\IPython\\frontend\\terminal\\interactiveshell.py\", line 290, in mainloop\n    self.interact(display_banner=display_banner)\n  File \"C:\\Python26\\lib\\site-packages\\ipython-0.13.dev-py2.6.egg\\IPython\\frontend\\terminal\\interactiveshell.py\", line 346, in interact\n    hlen_b4_cell = self.readline.get_current_history_length()\nAttributeError: 'module' object has no attribute 'get_current_history_length'\n</pre>\n\n\nI see that `setup.py` `requires` pyreadline >= 1.7.1, iff `setupext.check_for_readline()` returns False.  However, in my case, it returns True because the function does not check the version, and I have version 1.5.   I wasn't sure how best to put the version dependency into the function.\n\n", "before_files": [{"content": "# encoding: utf-8\nfrom __future__ import print_function\n\n__docformat__ = \"restructuredtext en\"\n\n#-------------------------------------------------------------------------------\n#  Copyright (C) 2008  The IPython Development Team\n#\n#  Distributed under the terms of the BSD License.  The full license is in\n#  the file COPYING, distributed as part of this software.\n#-------------------------------------------------------------------------------\n\n#-------------------------------------------------------------------------------\n# Imports\n#-------------------------------------------------------------------------------\n\nimport sys, os\nfrom textwrap import fill\n\ndisplay_status=True\n\ndef check_display(f):\n    \"\"\"decorator to allow display methods to be muted by mod.display_status\"\"\"\n    def maybe_display(*args, **kwargs):\n        if display_status:\n            return f(*args, **kwargs)\n    return maybe_display\n\n@check_display\ndef print_line(char='='):\n    print(char * 76)\n\n@check_display\ndef print_status(package, status):\n    initial_indent = \"%22s: \" % package\n    indent = ' ' * 24\n    print(fill(str(status), width=76,\n               initial_indent=initial_indent,\n               subsequent_indent=indent))\n\n@check_display\ndef print_message(message):\n    indent = ' ' * 24 + \"* \"\n    print(fill(str(message), width=76,\n               initial_indent=indent,\n               subsequent_indent=indent))\n\n@check_display\ndef print_raw(section):\n    print(section)\n\n#-------------------------------------------------------------------------------\n# Tests for specific packages\n#-------------------------------------------------------------------------------\n\ndef check_for_ipython():\n    try:\n        import IPython\n    except ImportError:\n        print_status(\"IPython\", \"Not found\")\n        return False\n    else:\n        print_status(\"IPython\", IPython.__version__)\n        return True\n\ndef check_for_sphinx():\n    try:\n        import sphinx\n    except ImportError:\n        print_status('sphinx', \"Not found (required for building documentation)\")\n        return False\n    else:\n        print_status('sphinx', sphinx.__version__)\n        return True\n\ndef check_for_pygments():\n    try:\n        import pygments\n    except ImportError:\n        print_status('pygments', \"Not found (required for syntax highlighting documentation)\")\n        return False\n    else:\n        print_status('pygments', pygments.__version__)\n        return True\n\ndef check_for_nose():\n    try:\n        import nose\n    except ImportError:\n        print_status('nose', \"Not found (required for running the test suite)\")\n        return False\n    else:\n        print_status('nose', nose.__version__)\n        return True\n\ndef check_for_pexpect():\n    try:\n        import pexpect\n    except ImportError:\n        print_status(\"pexpect\", \"no (required for running standalone doctests)\")\n        return False\n    else:\n        print_status(\"pexpect\", pexpect.__version__)\n        return True\n\ndef check_for_httplib2():\n    try:\n        import httplib2\n    except ImportError:\n        print_status(\"httplib2\", \"no (required for blocking http clients)\")\n        return False\n    else:\n        print_status(\"httplib2\",\"yes\")\n        return True\n\ndef check_for_sqlalchemy():\n    try:\n        import sqlalchemy\n    except ImportError:\n        print_status(\"sqlalchemy\", \"no (required for the ipython1 notebook)\")\n        return False\n    else:\n        print_status(\"sqlalchemy\",\"yes\")\n        return True\n\ndef check_for_simplejson():\n    try:\n        import simplejson\n    except ImportError:\n        print_status(\"simplejson\", \"no (required for the ipython1 notebook)\")\n        return False\n    else:\n        print_status(\"simplejson\",\"yes\")\n        return True\n\ndef check_for_pyzmq():\n    try:\n        import zmq\n    except ImportError:\n        print_status('pyzmq', \"no (required for qtconsole, notebook, and parallel computing capabilities)\")\n        return False\n    else:\n        # pyzmq 2.1.10 adds pyzmq_version_info funtion for returning\n        # version as a tuple\n        if hasattr(zmq, 'pyzmq_version_info'):\n            if zmq.pyzmq_version_info() >= (2,1,4):\n                print_status(\"pyzmq\", zmq.__version__)\n                return True\n            else:\n                # this branch can never occur, at least until we update our\n                # pyzmq dependency beyond 2.1.10\n                return False\n        # this is necessarily earlier than 2.1.10, so string comparison is\n        # okay\n        if zmq.__version__ < '2.1.4':\n            print_status('pyzmq', \"no (have %s, but require >= 2.1.4 for\"\n            \" qtconsole and parallel computing capabilities)\"%zmq.__version__)\n            return False\n        else:\n            print_status(\"pyzmq\", zmq.__version__)\n            return True\n\ndef check_for_readline():\n    try:\n        import readline\n    except ImportError:\n        try:\n            import pyreadline\n        except ImportError:\n            print_status('readline', \"no (required for good interactive behavior)\")\n            return False\n        else:\n            print_status('readline', \"yes pyreadline-\"+pyreadline.release.version)\n            return True\n    else:\n        print_status('readline', \"yes\")\n        return True\n", "path": "setupext/setupext.py"}], "after_files": [{"content": "# encoding: utf-8\nfrom __future__ import print_function\n\n__docformat__ = \"restructuredtext en\"\n\n#-------------------------------------------------------------------------------\n#  Copyright (C) 2008  The IPython Development Team\n#\n#  Distributed under the terms of the BSD License.  The full license is in\n#  the file COPYING, distributed as part of this software.\n#-------------------------------------------------------------------------------\n\n#-------------------------------------------------------------------------------\n# Imports\n#-------------------------------------------------------------------------------\n\nimport sys, os\nfrom textwrap import fill\n\ndisplay_status=True\n\ndef check_display(f):\n    \"\"\"decorator to allow display methods to be muted by mod.display_status\"\"\"\n    def maybe_display(*args, **kwargs):\n        if display_status:\n            return f(*args, **kwargs)\n    return maybe_display\n\n@check_display\ndef print_line(char='='):\n    print(char * 76)\n\n@check_display\ndef print_status(package, status):\n    initial_indent = \"%22s: \" % package\n    indent = ' ' * 24\n    print(fill(str(status), width=76,\n               initial_indent=initial_indent,\n               subsequent_indent=indent))\n\n@check_display\ndef print_message(message):\n    indent = ' ' * 24 + \"* \"\n    print(fill(str(message), width=76,\n               initial_indent=indent,\n               subsequent_indent=indent))\n\n@check_display\ndef print_raw(section):\n    print(section)\n\n#-------------------------------------------------------------------------------\n# Tests for specific packages\n#-------------------------------------------------------------------------------\n\ndef check_for_ipython():\n    try:\n        import IPython\n    except ImportError:\n        print_status(\"IPython\", \"Not found\")\n        return False\n    else:\n        print_status(\"IPython\", IPython.__version__)\n        return True\n\ndef check_for_sphinx():\n    try:\n        import sphinx\n    except ImportError:\n        print_status('sphinx', \"Not found (required for building documentation)\")\n        return False\n    else:\n        print_status('sphinx', sphinx.__version__)\n        return True\n\ndef check_for_pygments():\n    try:\n        import pygments\n    except ImportError:\n        print_status('pygments', \"Not found (required for syntax highlighting documentation)\")\n        return False\n    else:\n        print_status('pygments', pygments.__version__)\n        return True\n\ndef check_for_nose():\n    try:\n        import nose\n    except ImportError:\n        print_status('nose', \"Not found (required for running the test suite)\")\n        return False\n    else:\n        print_status('nose', nose.__version__)\n        return True\n\ndef check_for_pexpect():\n    try:\n        import pexpect\n    except ImportError:\n        print_status(\"pexpect\", \"no (required for running standalone doctests)\")\n        return False\n    else:\n        print_status(\"pexpect\", pexpect.__version__)\n        return True\n\ndef check_for_httplib2():\n    try:\n        import httplib2\n    except ImportError:\n        print_status(\"httplib2\", \"no (required for blocking http clients)\")\n        return False\n    else:\n        print_status(\"httplib2\",\"yes\")\n        return True\n\ndef check_for_sqlalchemy():\n    try:\n        import sqlalchemy\n    except ImportError:\n        print_status(\"sqlalchemy\", \"no (required for the ipython1 notebook)\")\n        return False\n    else:\n        print_status(\"sqlalchemy\",\"yes\")\n        return True\n\ndef check_for_simplejson():\n    try:\n        import simplejson\n    except ImportError:\n        print_status(\"simplejson\", \"no (required for the ipython1 notebook)\")\n        return False\n    else:\n        print_status(\"simplejson\",\"yes\")\n        return True\n\ndef check_for_pyzmq():\n    try:\n        import zmq\n    except ImportError:\n        print_status('pyzmq', \"no (required for qtconsole, notebook, and parallel computing capabilities)\")\n        return False\n    else:\n        # pyzmq 2.1.10 adds pyzmq_version_info funtion for returning\n        # version as a tuple\n        if hasattr(zmq, 'pyzmq_version_info'):\n            if zmq.pyzmq_version_info() >= (2,1,4):\n                print_status(\"pyzmq\", zmq.__version__)\n                return True\n            else:\n                # this branch can never occur, at least until we update our\n                # pyzmq dependency beyond 2.1.10\n                return False\n        # this is necessarily earlier than 2.1.10, so string comparison is\n        # okay\n        if zmq.__version__ < '2.1.4':\n            print_status('pyzmq', \"no (have %s, but require >= 2.1.4 for\"\n            \" qtconsole and parallel computing capabilities)\"%zmq.__version__)\n            return False\n        else:\n            print_status(\"pyzmq\", zmq.__version__)\n            return True\n\ndef check_for_readline():\n    from distutils.version import LooseVersion\n    try:\n        import readline\n    except ImportError:\n        try:\n            import pyreadline\n            vs = pyreadline.release.version\n        except (ImportError, AttributeError):\n            print_status('readline', \"no (required for good interactive behavior)\")\n            return False\n        if LooseVersion(vs).version >= [1,7,1]:\n            print_status('readline', \"yes pyreadline-\" + vs)\n            return True\n        else:\n            print_status('readline', \"no pyreadline-%s < 1.7.1\" % vs)\n            return False\n    else:\n        print_status('readline', \"yes\")\n        return True\n", "path": "setupext/setupext.py"}]}