summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorInada Naoki <songofacandy@gmail.com>2019-11-28 20:23:34 +0900
committerGitHub <noreply@github.com>2019-11-28 20:23:34 +0900
commit891f2d8743857bb75204f96b0469cb2ec90c7f79 (patch)
tree8d5de9611eef84e3643f1f907e5f4a954b8e25fc
parentb458e9a6a2cf69e483fa5994d227382c6a01f3c4 (diff)
downloadmsgpack-python-891f2d8743857bb75204f96b0469cb2ec90c7f79.tar.gz
Drop Python 2 support from _cmsgpack (#376)
-rw-r--r--.travis.yml10
-rw-r--r--README.rst20
-rw-r--r--docker/shared.env2
-rw-r--r--msgpack/__init__.py5
-rw-r--r--msgpack/_packer.pyx5
-rw-r--r--msgpack/buff_converter.h20
-rw-r--r--msgpack/fallback.py5
-rw-r--r--msgpack/unpack.h4
-rwxr-xr-xsetup.py20
9 files changed, 36 insertions, 55 deletions
diff --git a/.travis.yml b/.travis.yml
index c80bb37..7b298af 100644
--- a/.travis.yml
+++ b/.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
diff --git a/README.rst b/README.rst
index 94a4bb2..82b6c02 100644
--- a/README.rst
+++ b/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
----------
diff --git a/docker/shared.env b/docker/shared.env
index b5772e3..17abdd8 100644
--- a/docker/shared.env
+++ b/docker/shared.env
@@ -3,6 +3,4 @@ PYTHON_VERSIONS=(
cp37-cp37m
cp36-cp36m
cp35-cp35m
- cp27-cp27m
- cp27-cp27mu
)
diff --git a/msgpack/__init__.py b/msgpack/__init__.py
index 4ad9c1a..4112a16 100644
--- a/msgpack/__init__.py
+++ b/msgpack/__init__.py
@@ -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:
diff --git a/msgpack/_packer.pyx b/msgpack/_packer.pyx
index 2f4d120..e620914 100644
--- a/msgpack/_packer.pyx
+++ b/msgpack/_packer.pyx
@@ -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
+ self.encoding = 'utf-8'
else:
self.encoding = self._bencoding
diff --git a/msgpack/buff_converter.h b/msgpack/buff_converter.h
index bc7227a..86b4196 100644
--- a/msgpack/buff_converter.h
+++ b/msgpack/buff_converter.h
@@ -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
diff --git a/msgpack/fallback.py b/msgpack/fallback.py
index 3836e83..1ed6e77 100644
--- a/msgpack/fallback.py
+++ b/msgpack/fallback.py
@@ -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
diff --git a/msgpack/unpack.h b/msgpack/unpack.h
index 85dbbed..bbce91c 100644
--- a/msgpack/unpack.h
+++ b/msgpack/unpack.h
@@ -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;
diff --git a/setup.py b/setup.py
index 8b8d7a0..77b81c6 100755
--- a/setup.py
+++ b/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:
- class Sdist(sdist):
- def __init__(self, *args, **kwargs):
- cythonize('msgpack/_cmsgpack.pyx')
- sdist.__init__(self, *args, **kwargs)
-else:
- Sdist = sdist
+# Cython is required for sdist
+class Sdist(sdist):
+ def __init__(self, *args, **kwargs):
+ cythonize('msgpack/_cmsgpack.pyx')
+ sdist.__init__(self, *args, **kwargs)
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,