Added conditional Cython extension build step in setup.py and created speedups for some renderers.

This commit is contained in:
Omer Katz 2015-02-03 14:56:29 +02:00
parent 2580466ffc
commit 748f2fc533
3 changed files with 37 additions and 6 deletions

View File

View File

@ -0,0 +1,23 @@
#!/usr/bin/env python
# coding: utf-8
cimport cython
@cython.locals(media_type=unicode, format=unicode, charset=unicode, render_style=unicode)
cdef class BaseRenderer(object):
"""
All renderers should extend this class, setting the `media_type`
and `format` attributes, and override the `.render()` method.
"""
@cython.locals(indent=int, separators=tuple)
cpdef object render(self, dict data, accepted_media_type=?, renderer_context=?)
@cython.locals(compact=bool, ensure_ascii=bool, charset=unicode)
cdef class JSONRenderer(BaseRenderer):
@cython.locals(base_media_type=unicode, params=dict)
cpdef int get_indent(self, unicode accepted_media_type, dict renderer_context)
@cython.locals(callback_parameter=unicode, default_callback=unicode)
cdef class JSONPRenderer(JSONRenderer):
cpdef unicode get_callback(self, dict renderer_context)

View File

@ -1,12 +1,21 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from setuptools import setup
from setuptools.command.test import test as TestCommand
try:
from Cython.Build import cythonize
except ImportError:
ext_modules = None
else:
from setuptools import Extension
ext_modules = cythonize(Extension('speedups', ['rest_framework/renderers.py',
'rest_framework/__init__.py']))
import re
import os
import sys
from setuptools import setup
def get_version(package):
"""
@ -43,7 +52,6 @@ def get_package_data(package):
version = get_version('rest_framework')
if sys.argv[-1] == 'publish':
if os.system("pip freeze | grep wheel"):
print("wheel not installed.\nUse `pip install wheel`.\nExiting.")
@ -55,7 +63,6 @@ if sys.argv[-1] == 'publish':
print(" git push --tags")
sys.exit()
setup(
name='djangorestframework',
version=version,
@ -68,6 +75,7 @@ setup(
package_data=get_package_data('rest_framework'),
install_requires=[],
zip_safe=False,
ext_modules=ext_modules,
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',