Drop Python 2 support from _cmsgpack (#376)

This commit is contained in:
Inada Naoki 2019-11-28 20:23:34 +09:00 committed by GitHub
parent b458e9a6a2
commit 891f2d8743
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 55 deletions

View file

@ -6,7 +6,6 @@ python:
# Available Python (PyPy) can be listed by: # Available Python (PyPy) can be listed by:
# #
# $ aws s3 ls s3://travis-python-archives/binaries/ubuntu/16.04/x86_64/ # $ aws s3 ls s3://travis-python-archives/binaries/ubuntu/16.04/x86_64/
- "2.7"
- "3.4" - "3.4"
- "3.5" - "3.5"
- "3.6" - "3.6"
@ -41,7 +40,14 @@ matrix:
- pip install -e . - pip install -e .
script: script:
- pytest -v test - pytest -v test
- name: "Python 2 (fallback)"
python: "2.7"
install:
- pip install -U pip
- pip install -U pytest
- pip install .
script:
- pytest -v test
install: install:
- pip install -U pip - pip install -U pip

View file

@ -76,10 +76,18 @@ Install
$ pip install msgpack $ pip install msgpack
PyPy Pure Python implementation
^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
The extension module in msgpack (``msgpack._cmsgpack``) does not support
Python 2 and PyPy.
But msgpack provides a pure Python implementation (``msgpack.fallback``)
for PyPy and Python 2.
Since the [pip](https://pip.pypa.io/) uses the pure Python implementation,
Python 2 support will not be dropped in foreseeable feature.
msgpack provides a pure Python implementation. PyPy can use this.
Windows Windows
^^^^^^^ ^^^^^^^
@ -88,12 +96,6 @@ When you can't use a binary distribution, you need to install Visual Studio
or Windows SDK on Windows. or Windows SDK on Windows.
Without extension, using pure Python implementation on CPython runs slowly. Without extension, using pure Python implementation on CPython runs slowly.
For Python 2.7, `Microsoft Visual C++ Compiler for Python 2.7 <https://www.microsoft.com/en-us/download/details.aspx?id=44266>`_
is recommended solution.
For Python 3.5, `Microsoft Visual Studio 2015 <https://www.visualstudio.com/en-us/products/vs-2015-product-editions.aspx>`_
Community Edition or Express Edition can be used to build extension module.
How to use How to use
---------- ----------

View file

@ -3,6 +3,4 @@ PYTHON_VERSIONS=(
cp37-cp37m cp37-cp37m
cp36-cp36m cp36-cp36m
cp35-cp35m cp35-cp35m
cp27-cp27m
cp27-cp27mu
) )

View file

@ -2,6 +2,8 @@
from ._version import version from ._version import version
from .exceptions import * from .exceptions import *
import os
import sys
from collections import namedtuple from collections import namedtuple
@ -17,8 +19,7 @@ class ExtType(namedtuple('ExtType', 'code data')):
return super(ExtType, cls).__new__(cls, code, data) return super(ExtType, cls).__new__(cls, code, data)
import os if os.environ.get('MSGPACK_PUREPYTHON') or sys.version_info[0] == 2:
if os.environ.get('MSGPACK_PUREPYTHON'):
from .fallback import Packer, unpackb, Unpacker from .fallback import Packer, unpackb, Unpacker
else: else:
try: try:

View file

@ -130,10 +130,7 @@ cdef class Packer(object):
self._bencoding = encoding self._bencoding = encoding
if encoding is None: if encoding is None:
if PY_MAJOR_VERSION < 3:
self.encoding = 'utf-8' self.encoding = 'utf-8'
else:
self.encoding = NULL
else: else:
self.encoding = self._bencoding self.encoding = self._bencoding

View file

@ -1,28 +1,8 @@
#include "Python.h" #include "Python.h"
/* cython does not support this preprocessor check => write it in raw C */ /* cython does not support this preprocessor check => write it in raw C */
#if PY_MAJOR_VERSION == 2
static PyObject *
buff_to_buff(char *buff, Py_ssize_t size)
{
return PyBuffer_FromMemory(buff, size);
}
#elif (PY_MAJOR_VERSION == 3) && (PY_MINOR_VERSION >= 3)
static PyObject * static PyObject *
buff_to_buff(char *buff, Py_ssize_t size) buff_to_buff(char *buff, Py_ssize_t size)
{ {
return PyMemoryView_FromMemory(buff, size, PyBUF_READ); return PyMemoryView_FromMemory(buff, size, PyBUF_READ);
} }
#else
static PyObject *
buff_to_buff(char *buff, Py_ssize_t size)
{
Py_buffer pybuf;
if (PyBuffer_FillInfo(&pybuf, NULL, buff, size, 1, PyBUF_FULL_RO) == -1) {
return NULL;
}
return PyMemoryView_FromBuffer(&pybuf);
}
#endif

View file

@ -5,13 +5,12 @@ import struct
import warnings import warnings
if sys.version_info[0] == 2: PY2 = sys.version_info[0] == 2
PY2 = True if PY2:
int_types = (int, long) int_types = (int, long)
def dict_iteritems(d): def dict_iteritems(d):
return d.iteritems() return d.iteritems()
else: else:
PY2 = False
int_types = int int_types = int
unicode = str unicode = str
xrange = range xrange = range

View file

@ -273,11 +273,7 @@ static inline int unpack_callback_ext(unpack_user* u, const char* base, const ch
return -1; return -1;
} }
// length also includes the typecode, so the actual data is length-1 // length also includes the typecode, so the actual data is length-1
#if PY_MAJOR_VERSION == 2
py = PyObject_CallFunction(u->ext_hook, "(is#)", (int)typecode, pos, (Py_ssize_t)length-1);
#else
py = PyObject_CallFunction(u->ext_hook, "(iy#)", (int)typecode, pos, (Py_ssize_t)length-1); py = PyObject_CallFunction(u->ext_hook, "(iy#)", (int)typecode, pos, (Py_ssize_t)length-1);
#endif
if (!py) if (!py)
return -1; return -1;
*o = py; *o = py;

View file

@ -9,6 +9,11 @@ from setuptools import setup, Extension
from distutils.command.build_ext import build_ext from distutils.command.build_ext import build_ext
PYPY = hasattr(sys, "pypy_version_info")
PY2 = sys.version_info[0] == 2
# for building transitional package. # for building transitional package.
TRANSITIONAL = False TRANSITIONAL = False
@ -64,14 +69,11 @@ version_str = '.'.join(str(x) for x in version[:3])
if len(version) > 3 and version[3] != 'final': if len(version) > 3 and version[3] != 'final':
version_str += version[3] version_str += version[3]
# take care of extension modules. # Cython is required for sdist
if have_cython:
class Sdist(sdist): class Sdist(sdist):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
cythonize('msgpack/_cmsgpack.pyx') cythonize('msgpack/_cmsgpack.pyx')
sdist.__init__(self, *args, **kwargs) sdist.__init__(self, *args, **kwargs)
else:
Sdist = sdist
libraries = [] libraries = []
if sys.platform == 'win32': if sys.platform == 'win32':
@ -83,7 +85,7 @@ else:
macros = [('__LITTLE_ENDIAN__', '1')] macros = [('__LITTLE_ENDIAN__', '1')]
ext_modules = [] ext_modules = []
if not hasattr(sys, 'pypy_version_info'): if not PYPY and not PY2:
ext_modules.append(Extension('msgpack._cmsgpack', ext_modules.append(Extension('msgpack._cmsgpack',
sources=['msgpack/_cmsgpack.cpp'], sources=['msgpack/_cmsgpack.cpp'],
libraries=libraries, libraries=libraries,