Repository: ipython/ipython

Issue:
Unable to 'pip install ipython' with PyPy 2.6.1 on OS X
Attempting to `pip install ipython` with PyPy 2.6.1 on OS X fails due to being unable to install gnureadline:

```
Failed to build gnureadline
Installing collected packages: decorator, path.py, pickleshare, simplegeneric, ipython-genutils, traitlets, pexpect, appnope, gnureadline, ipython
  Running setup.py install for gnureadline
    Complete output from command /Users/rouge8/.virtualenvs/tmp-62491ef39875e400/bin/python -c "import setuptools, tokenize;__file__='/private/var/folders/tv/tqsxmfzd7l5_5ys1jq3496hr0000gp/T/pip-build-MSyBT_/gnureadline/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/tv/tqsxmfzd7l5_5ys1jq3496hr0000gp/T/pip-Yzq13m-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/rouge8/.virtualenvs/tmp-62491ef39875e400/include/site/python2.7/gnureadline:
    running install
    running build
    running build_py
    running egg_info
    writing gnureadline.egg-info/PKG-INFO
    writing dependency_links to gnureadline.egg-info/dependency_links.txt
    writing top-level names to gnureadline.egg-info/top_level.txt
    warning: manifest_maker: standard file '-c' not found

    reading manifest file 'gnureadline.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    writing manifest file 'gnureadline.egg-info/SOURCES.txt'
    warning: build_py: byte-compiling is disabled, skipping.

    running build_ext
    building 'gnureadline' extension
    cc -arch x86_64 -O2 -fPIC -Wimplicit -DHAVE_RL_CALLBACK -DHAVE_RL_CATCH_SIGNAL -DHAVE_RL_COMPLETION_APPEND_CHARACTER -DHAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK -DHAVE_RL_COMPLETION_MATCHES -DHAVE_RL_COMPLETION_SUPPRESS_APPEND -DHAVE_RL_PRE_INPUT_HOOK -I. -I/Users/rouge8/.virtualenvs/tmp-62491ef39875e400/include -c Modules/2.x/readline.c -o build/temp.macosx-10.10-x86_64-2.7/Modules/2.x/readline.o
    Modules/2.x/readline.c:1057:21: error: use of undeclared identifier 'PyOS_InputHook'
        rl_event_hook = PyOS_InputHook;
                        ^
    Modules/2.x/readline.c:1170:5: error: use of undeclared identifier 'PyOS_ReadlineFunctionPointer'
        PyOS_ReadlineFunctionPointer = call_readline;
        ^
    2 errors generated.
    error: command 'cc' failed with exit status 1
```

Python version:

``` sh
$ python --version
Python 2.7.10 (f3ad1e1e1d6215e20d34bb65ab85ff9188c9f559, Sep 01 2015, 06:26:30)
[PyPy 2.6.1 with GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]
```

I was able to work around this by installing all of the IPython dependencies except for gnureadline and then running `pip install --no-deps ipython`, but obviously that's not ideal. :/



Discussion:
I know what's up here, but in fixing it I found a bug in setuptools' implementation of environment markers (of course). I'll open an Issue on setuptools to deal with this, and figure out what the best workaround in IPython should be.


Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -200,9 +200,11 @@ def run(self):
 # Platform-specific dependencies:
 # This is the correct way to specify these,
 # but requires pip >= 6. pip < 6 ignores these.
+
 extras_require.update({
     ':sys_platform != "win32"': ['pexpect'],
-    ':sys_platform == "darwin"': ['appnope', 'gnureadline'],
+    ':sys_platform == "darwin"': ['appnope'],
+    ':sys_platform == "darwin" and platform_python_implementation == "CPython"': ['gnureadline'],
     'terminal:sys_platform == "win32"': ['pyreadline>=2'],
     'test:python_version == "2.7"': ['mock'],
 })
@@ -213,12 +215,30 @@ def run(self):
         extras_require['test'].append('mock')
 
     if sys.platform == 'darwin':
-        install_requires.extend(['appnope', 'gnureadline'])
+        install_requires.extend(['appnope'])
+        have_readline = False
+        try:
+            import readline
+        except ImportError:
+            pass
+        else:
+            if 'libedit' not in readline.__doc__:
+                have_readline = True
+        if not have_readline:
+            install_requires.extend(['gnureadline'])
 
     if sys.platform.startswith('win'):
         extras_require['terminal'].append('pyreadline>=2.0')
     else:
         install_requires.append('pexpect')
+    
+    # workaround pypa/setuptools#147, where setuptools misspells
+    # platform_python_implementation as python_implementation
+    if 'setuptools' in sys.modules:
+        for key in list(extras_require):
+            if 'platform_python_implementation' in key:
+                new_key = key.replace('platform_python_implementation', 'python_implementation')
+                extras_require[new_key] = extras_require.pop(key)
 
 everything = set()
 for key, deps in extras_require.items():


Test patch: