Issue: workaround for issue 820 
Author: dhaase-de
State: closed
Created: 2016-06-01 06:32:10

For me, issue #820 wasn't really solved yet - I run Debian 8 (stable) on several machines, and it comes with Cython 0.21.1. Because I want to keep program versions on my machines in sync, I tend to not install newer versions manually. This commit proposes a workaround for issue #820 which disables Cython support for Cython versions below 0.22.1.


Is this the right check? I had been operating on the assumption that if Cython was present but too old, that peewee would raise an exception.


Yes, I believe this is the right check.

Currently, `peewee` can't even be installed under vanilla Debian 8 with Python 3.4.2 and Cython 0.21.1 installed:

**via pip:**

``` bash
$ pip3 install peewee
Downloading/unpacking peewee
  Downloading peewee-2.8.1.tar.gz (474kB): 474kB downloaded
  Running setup.py (path:/tmp/pip-build-oy3l4ssv/peewee/setup.py) egg_info for package peewee
    /tmp/pip-build-oy3l4ssv/peewee/setup.py:17: UserWarning: Your Cython appears to be an older version. You may need to upgrade Cython in order to build the peewee C extensions.
      warnings.warn('Your Cython appears to be an older version. You may '

Installing collected packages: peewee
  Running setup.py install for peewee
    cythoning playhouse/_speedups.pyx to playhouse/_speedups.c
    building 'playhouse._speedups' extension
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.4m -c playhouse/_speedups.c -o build/temp.linux-x86_64-3.4/playhouse/_speedups.o
    playhouse/_speedups.c:1:2: error: #error Do not use this file, it is the result of a failed Cython compilation.
     #error Do not use this file, it is the result of a failed Cython compilation.
      ^
    /tmp/pip-build-oy3l4ssv/peewee/setup.py:17: UserWarning: Your Cython appears to be an older version. You may need to upgrade Cython in order to build the peewee C extensions.
      warnings.warn('Your Cython appears to be an older version. You may '

    Error compiling Cython file:
    ------------------------------------------------------------
    ...
        cdef:
            set model_set = set(models)
            set seen = set()
            list accum = []

        for model in sorted(model_set, key=_sort_key, reverse=True):
                                                   ^
    ------------------------------------------------------------

    playhouse/_speedups.pyx:318:48: Cannot convert 'tuple (object)' to Python object
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    Complete output from command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip-build-oy3l4ssv/peewee/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-8z0qr59j-record/install-record.txt --single-version-externally-managed --compile:
    running install

running build

running build_py

creating build

creating build/lib.linux-x86_64-3.4

copying peewee.py -> build/lib.linux-x86_64-3.4

copying pwiz.py -> build/lib.linux-x86_64-3.4

creating build/lib.linux-x86_64-3.4/playhouse

copying playhouse/dataset.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/sqlcipher_ext.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/apsw_ext.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/signals.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/shortcuts.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/__init__.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/kv.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/test_utils.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/sqlite_udf.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/flask_utils.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/hybrid.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/migrate.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/db_url.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/csv_utils.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/pool.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/reflection.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/djpeewee.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/read_slave.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/berkeleydb.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/csv_loader.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/postgres_ext.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/fields.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/sqlite_ext.py -> build/lib.linux-x86_64-3.4/playhouse

copying playhouse/gfk.py -> build/lib.linux-x86_64-3.4/playhouse

running build_ext

cythoning playhouse/_speedups.pyx to playhouse/_speedups.c

building 'playhouse._speedups' extension

creating build/temp.linux-x86_64-3.4

creating build/temp.linux-x86_64-3.4/playhouse

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.4m -c playhouse/_speedups.c -o build/temp.linux-x86_64-3.4/playhouse/_speedups.o

playhouse/_speedups.c:1:2: error: #error Do not use this file, it is the result of a failed Cython compilation.

 #error Do not use this file, it is the result of a failed Cython compilation.

  ^

/tmp/pip-build-oy3l4ssv/peewee/setup.py:17: UserWarning: Your Cython appears to be an older version. You may need to upgrade Cython in order to build the peewee C extensions.

  warnings.warn('Your Cython appears to be an older version. You may '



Error compiling Cython file:

------------------------------------------------------------

...

    cdef:

        set model_set = set(models)

        set seen = set()

        list accum = []



    for model in sorted(model_set, key=_sort_key, reverse=True):

                                               ^

------------------------------------------------------------



playhouse/_speedups.pyx:318:48: Cannot convert 'tuple (object)' to Python object

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip-build-oy3l4ssv/peewee/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-8z0qr59j-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip-build-oy3l4ssv/peewee
Storing debug log for failure in /home/dh/.pip/pip.log
```

**via install.py**

``` bash
$ python3 setup.py install --user
setup.py:17: UserWarning: Your Cython appears to be an older version. You may need to upgrade Cython in order to build the peewee C extensions.
  warnings.warn('Your Cython appears to be an older version. You may '
running install
running build
running build_py
creating build/lib.linux-x86_64-3.4
copying peewee.py -> build/lib.linux-x86_64-3.4
copying pwiz.py -> build/lib.linux-x86_64-3.4
creating build/lib.linux-x86_64-3.4/playhouse
copying playhouse/dataset.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/sqlcipher_ext.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/apsw_ext.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/signals.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/shortcuts.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/__init__.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/kv.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/test_utils.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/sqlite_udf.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/flask_utils.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/hybrid.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/migrate.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/db_url.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/csv_utils.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/pool.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/reflection.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/djpeewee.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/read_slave.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/berkeleydb.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/csv_loader.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/postgres_ext.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/fields.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/sqlite_ext.py -> build/lib.linux-x86_64-3.4/playhouse
copying playhouse/gfk.py -> build/lib.linux-x86_64-3.4/playhouse
running build_ext
cythoning playhouse/_speedups.pyx to playhouse/_speedups.c

Error compiling Cython file:
------------------------------------------------------------
...
    cdef:
        set model_set = set(models)
        set seen = set()
        list accum = []

    for model in sorted(model_set, key=_sort_key, reverse=True):
                                               ^
------------------------------------------------------------

playhouse/_speedups.pyx:330:48: Cannot convert 'tuple (object)' to Python object
building 'playhouse._speedups' extension
creating build/temp.linux-x86_64-3.4
creating build/temp.linux-x86_64-3.4/playhouse
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.4m -c playhouse/_speedups.c -o build/temp.linux-x86_64-3.4/playhouse/_speedups.o
playhouse/_speedups.c:1:2: error: #error Do not use this file, it is the result of a failed Cython compilation.
 #error Do not use this file, it is the result of a failed Cython compilation.
  ^
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
```

So `peewee` dosn't even get to the point of raising an exception. The installation fails during Cython compilation.

And here is the result after the proposed fix:

``` bash
$ python3 setup.py install --user
setup.py:19: UserWarning: Your Cython appears to be an older version. You may need to upgrade Cython in order to build the peewee C extensions. For now, Cython support is disabled.
  warnings.warn('Your Cython appears to be an older version. You may '
running install
running build
running build_py
running build_scripts
running install_lib
running install_scripts
changing mode of /home/dh/.local/bin/pwiz.py to 755
running install_egg_info
Writing /home/dh/.local/lib/python3.4/site-packages/peewee-2.8.1.egg-info
```


I see...Maybe you can make the warning state clearly that even though you have Cython, the extensions are **not** being built?


Ok, there are now two warning messages (Cython not installed, Cython too old) which clearly state that Cython extensions will not be built.


Noice. Thanks!