mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-19 20:03:16 +00:00
Drop Python 2 support from _cmsgpack (#376)
This commit is contained in:
parent
b458e9a6a2
commit
891f2d8743
9 changed files with 36 additions and 55 deletions
10
.travis.yml
10
.travis.yml
|
@ -6,7 +6,6 @@ python:
|
|||
# Available Python (PyPy) can be listed by:
|
||||
#
|
||||
# $ aws s3 ls s3://travis-python-archives/binaries/ubuntu/16.04/x86_64/
|
||||
- "2.7"
|
||||
- "3.4"
|
||||
- "3.5"
|
||||
- "3.6"
|
||||
|
@ -41,7 +40,14 @@ matrix:
|
|||
- pip install -e .
|
||||
script:
|
||||
- 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:
|
||||
- pip install -U pip
|
||||
|
|
20
README.rst
20
README.rst
|
@ -76,10 +76,18 @@ Install
|
|||
|
||||
$ 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
|
||||
^^^^^^^
|
||||
|
@ -88,12 +96,6 @@ When you can't use a binary distribution, you need to install Visual Studio
|
|||
or Windows SDK on Windows.
|
||||
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
|
||||
----------
|
||||
|
|
|
@ -3,6 +3,4 @@ PYTHON_VERSIONS=(
|
|||
cp37-cp37m
|
||||
cp36-cp36m
|
||||
cp35-cp35m
|
||||
cp27-cp27m
|
||||
cp27-cp27mu
|
||||
)
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
from ._version import version
|
||||
from .exceptions import *
|
||||
|
||||
import os
|
||||
import sys
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
|
@ -17,8 +19,7 @@ class ExtType(namedtuple('ExtType', 'code data')):
|
|||
return super(ExtType, cls).__new__(cls, code, data)
|
||||
|
||||
|
||||
import os
|
||||
if os.environ.get('MSGPACK_PUREPYTHON'):
|
||||
if os.environ.get('MSGPACK_PUREPYTHON') or sys.version_info[0] == 2:
|
||||
from .fallback import Packer, unpackb, Unpacker
|
||||
else:
|
||||
try:
|
||||
|
|
|
@ -130,10 +130,7 @@ cdef class Packer(object):
|
|||
|
||||
self._bencoding = encoding
|
||||
if encoding is None:
|
||||
if PY_MAJOR_VERSION < 3:
|
||||
self.encoding = 'utf-8'
|
||||
else:
|
||||
self.encoding = NULL
|
||||
else:
|
||||
self.encoding = self._bencoding
|
||||
|
||||
|
|
|
@ -1,28 +1,8 @@
|
|||
#include "Python.h"
|
||||
|
||||
/* 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 *
|
||||
buff_to_buff(char *buff, Py_ssize_t size)
|
||||
{
|
||||
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
|
||||
|
|
|
@ -5,13 +5,12 @@ import struct
|
|||
import warnings
|
||||
|
||||
|
||||
if sys.version_info[0] == 2:
|
||||
PY2 = True
|
||||
PY2 = sys.version_info[0] == 2
|
||||
if PY2:
|
||||
int_types = (int, long)
|
||||
def dict_iteritems(d):
|
||||
return d.iteritems()
|
||||
else:
|
||||
PY2 = False
|
||||
int_types = int
|
||||
unicode = str
|
||||
xrange = range
|
||||
|
|
|
@ -273,11 +273,7 @@ static inline int unpack_callback_ext(unpack_user* u, const char* base, const ch
|
|||
return -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);
|
||||
#endif
|
||||
if (!py)
|
||||
return -1;
|
||||
*o = py;
|
||||
|
|
12
setup.py
12
setup.py
|
@ -9,6 +9,11 @@ from setuptools import setup, Extension
|
|||
|
||||
from distutils.command.build_ext import build_ext
|
||||
|
||||
|
||||
PYPY = hasattr(sys, "pypy_version_info")
|
||||
PY2 = sys.version_info[0] == 2
|
||||
|
||||
|
||||
# for building transitional package.
|
||||
TRANSITIONAL = False
|
||||
|
||||
|
@ -64,14 +69,11 @@ version_str = '.'.join(str(x) for x in version[:3])
|
|||
if len(version) > 3 and version[3] != 'final':
|
||||
version_str += version[3]
|
||||
|
||||
# take care of extension modules.
|
||||
if have_cython:
|
||||
# Cython is required for sdist
|
||||
class Sdist(sdist):
|
||||
def __init__(self, *args, **kwargs):
|
||||
cythonize('msgpack/_cmsgpack.pyx')
|
||||
sdist.__init__(self, *args, **kwargs)
|
||||
else:
|
||||
Sdist = sdist
|
||||
|
||||
libraries = []
|
||||
if sys.platform == 'win32':
|
||||
|
@ -83,7 +85,7 @@ else:
|
|||
macros = [('__LITTLE_ENDIAN__', '1')]
|
||||
|
||||
ext_modules = []
|
||||
if not hasattr(sys, 'pypy_version_info'):
|
||||
if not PYPY and not PY2:
|
||||
ext_modules.append(Extension('msgpack._cmsgpack',
|
||||
sources=['msgpack/_cmsgpack.cpp'],
|
||||
libraries=libraries,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue