Repository: Kinto/kinto

Issue:
kinto start fails: no module named functools32
```
kinto start
Starting subprocess with file monitor
2015-11-29 10:12:24,821 INFO  [venusian][MainThread] kinto 1.9.0 starting. 
Traceback (most recent call last):
  File "/var/www/kinto.leplat.re/venv/bin/kinto", line 9, in <module>
    load_entry_point('kinto==1.9.0', 'console_scripts', 'kinto')()
  File "/var/www/kinto.leplat.re/venv/local/lib/python2.7/site-packages/kinto/__main__.py", line 55, in main
    pserve.main(pserve_argv)
  File "/var/www/kinto.leplat.re/venv/local/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 60, in main
    return command.run()
  File "/var/www/kinto.leplat.re/venv/local/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 366, in run
    global_conf=vars)
  File "/var/www/kinto.leplat.re/venv/local/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 401, in loadapp
    return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
  File "/var/www/kinto.leplat.re/venv/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 247, in loadapp
    return loadobj(APP, uri, name=name, **kw)
  File "/var/www/kinto.leplat.re/venv/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 272, in loadobj
    return context.create()
  File "/var/www/kinto.leplat.re/venv/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 710, in create
    return self.object_type.invoke(self)
  File "/var/www/kinto.leplat.re/venv/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 146, in invoke
    return fix_call(context.object, context.global_conf, **context.local_conf)
  File "/var/www/kinto.leplat.re/venv/local/lib/python2.7/site-packages/paste/deploy/util.py", line 55, in fix_call
    val = callable(*args, **kw)
  File "/var/www/kinto.leplat.re/venv/local/lib/python2.7/site-packages/kinto/__init__.py", line 77, in main
    config.scan("kinto.views", **kwargs)
  File "/var/www/kinto.leplat.re/venv/local/lib/python2.7/site-packages/pyramid/config/__init__.py", line 974, in scan
    ignore=ignore)
  File "/var/www/kinto.leplat.re/venv/local/lib/python2.7/site-packages/venusian/__init__.py", line 205, in scan
    __import__(modname)
  File "/var/www/kinto.leplat.re/venv/local/lib/python2.7/site-packages/kinto/views/buckets.py", line 12, in <module>
    from kinto.views.collections import Collection
  File "/var/www/kinto.leplat.re/venv/local/lib/python2.7/site-packages/kinto/views/collections.py", line 2, in <module>
    import jsonschema
  File "/var/www/kinto.leplat.re/venv/local/lib/python2.7/site-packages/jsonschema/__init__.py", line 12, in <module>
    from jsonschema.exceptions import (
  File "/var/www/kinto.leplat.re/venv/local/lib/python2.7/site-packages/jsonschema/exceptions.py", line 6, in <module>
    from jsonschema import _utils
  File "/var/www/kinto.leplat.re/venv/local/lib/python2.7/site-packages/jsonschema/_utils.py", line 6, in <module>
    from jsonschema.compat import str_types, MutableMapping, urlsplit
  File "/var/www/kinto.leplat.re/venv/local/lib/python2.7/site-packages/jsonschema/compat.py", line 39, in <module>
    from functools32 import lru_cache
ImportError: No module named functools32
```



Discussion:
However, `functools32` is for Python 2.7 only, so I get this exception when I try to `pip install kinto` on Python 3.5:

``` pytb
$ pip install kinto
Collecting kinto
  Downloading kinto-1.11.0-py2.py3-none-any.whl (47kB)
    100% |████████████████████████████████| 49kB 1.3MB/s 
Collecting cliquet<3,>=2.15 (from kinto)
  Downloading cliquet-2.15.0-cp2.cp3-none-any.whl (315kB)
    100% |████████████████████████████████| 315kB 1.1MB/s 
Collecting jsonschema (from kinto)
  Downloading jsonschema-2.5.1-py2.py3-none-any.whl
Collecting functools32 (from kinto)
  Downloading functools32-3.2.3-2.tar.gz
    Complete output from command python setup.py egg_info:
    This backport is for Python 2.7 only
```

I've just got the exact same problem locally, with python 3.4. Not sure why this is included since [it should be included for python < 3 only](https://github.com/Kinto/kinto/blob/master/setup.py#L25-L28).

Oh great catch. We should use extra_requires there.

Could reproduce:

```
virtualenv .venv34 --python=python3.4
Running virtualenv with interpreter /usr/bin/python3.4
Using base prefix '/usr'
New python executable in .venv34/bin/python3.4
Also creating executable in .venv34/bin/python
Installing setuptools, pip...done.
$ source .venv34/bin/activate

$  pip install kinto
Downloading/unpacking kinto
  Downloading kinto-1.11.0-py2.py3-none-any.whl (47kB): 47kB downloaded
  Storing download in cache at /home/mathieu/Downloads/pip/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fpy2.py3%2Fk%2Fkinto%2Fkinto-1.11.0-py2.py3-none-any.whl
Downloading/unpacking waitress (from kinto)
  Using download cache from /home/mathieu/Downloads/pip/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Fw%2Fwaitress%2Fwaitress-0.8.10.tar.gz
  Running setup.py (path:/tmp/pip-build-8iw7z7ci/waitress/setup.py) egg_info for package waitress

Downloading/unpacking jsonschema (from kinto)
  Using download cache from /home/mathieu/Downloads/pip/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fpy2.py3%2Fj%2Fjsonschema%2Fjsonschema-2.5.1-py2.py3-none-any.whl
Downloading/unpacking cliquet<3,>=2.15 (from kinto)
  Using download cache from /home/mathieu/Downloads/pip/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fcp2.cp3%2Fc%2Fcliquet%2Fcliquet-2.15.0-cp2.cp3-none-any.whl
Downloading/unpacking functools32 (from kinto)
  Using download cache from /home/mathieu/Downloads/pip/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Ff%2Ffunctools32%2Ffunctools32-3.2.3-2.tar.gz
  Running setup.py (path:/tmp/pip-build-8iw7z7ci/functools32/setup.py) egg_info for package functools32
    This backport is for Python 2.7 only.
    Complete output from command python setup.py egg_info:
    This backport is for Python 2.7 only.
```

This was related the universal wheel published on Pypi.

Until we find a proper fix for this, we replaced the wheel by python sources (`.tar.gz`) on Pypi.


Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -22,11 +22,6 @@ def read_file(filename):
     'jsonschema',
 ]
 
-if sys.version_info < (3,):
-    REQUIREMENTS.extend([
-        'functools32',  # not installed by jsonschema with old pip versions.
-    ])
-
 POSTGRESQL_REQUIREMENTS = REQUIREMENTS + [
     'cliquet[postgresql]>=2.15,<3'
 ]
@@ -81,6 +76,7 @@ def read_file(filename):
           'postgresql': POSTGRESQL_REQUIREMENTS,
           'monitoring': MONITORING_REQUIREMENTS,
           'fxa': FXA_REQUIREMENTS,
+          ":python_version=='2.7'": ["functools32"],
       },
       test_suite="kinto.tests",
       entry_points=ENTRY_POINTS,


Test patch: