8000 Drop Python 2 support from _cmsgpack (#376) · ossdev07/msgpack-python@891f2d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 891f2d8

Browse files
authored
Drop Python 2 support from _cmsgpack (msgpack#376)
1 parent b458e9a commit 891f2d8

File tree

9 files changed

+36
-55
lines changed

9 files changed

+36
-55
lines changed

.travis.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ python:
66
# Available Python (PyPy) can be listed by:
77
#
88
# $ aws s3 ls s3://travis-python-archives/binaries/ubuntu/16.04/x86_64/
9-
- "2.7"
109
- "3.4"
1110
- "3.5"
1211
- "3.6"
@@ -41,7 +40,14 @@ matrix:
4140
- pip install -e .
4241
script:
4342
- pytest -v test
44-
43+
- name: "Python 2 (fallback)"
44+
python: "2.7"
45+
install:
46+
- pip install -U pip
47+
- pip install -U pytest
48+
- pip install .
49+
script:
50+
- pytest -v test
4551

4652
install:
4753
- pip install -U pip

README.rst

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,18 @@ Install
7676

7777
$ pip install msgpack
7878

79-
PyPy
80-
^^^^
79+
Pure Python implementation
80+
^^^^^^^^^^^^^^^^^^^^^^^^^^
81+
82+
The extension module in msgpack (``msgpack._cmsgpack``) does not support
83+
Python 2 and PyPy.
84+
85+
But msgpack provides a pure Python implementation (``msgpack.fallback``)
86+
for PyPy and Python 2.
87+
88+
Since the [pip](https://pip.pypa.io/) uses the pure Python implementation,
89+
Python 2 support will not be dropped in foreseeable feature.
8190

82-
msgpack provides a pure Python implementation. PyPy can use this.
8391

8492
Windows
8593
^^^^^^^
@@ -88,12 +96,6 @@ When you can't use a binary distribution, you need to install Visual Studio
8896
or Windows SDK on Windows.
8997
Without extension, using pure Python implementation on CPython runs slowly.
9098

91-
For Python 2.7, `Microsoft Visual C++ Compiler for Python 2.7 <https://www.microsoft.com/en-us/download/details.aspx?id=44266>`_
92-
is recommended solution.
93-
94-
For Python 3.5, `Microsoft Visual Studio 2015 <https://www.visualstudio.com/en-us/products/vs-2015-product-editions.aspx>`_
95-
Community Edition or Express Edition can be used to build extension module.
96-
9799

98100
How to use
99101
----------

docker/shared.env

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@ PYTHON_VERSIONS=(
33
cp37-cp37m
44
cp36-cp36m
55
cp35-cp35m
6-
cp27-cp27m
7-
cp27-cp27mu
86
)

msgpack/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from ._version import version
33
from .exceptions import *
44

5+
import os
6+
import sys
57
from collections import namedtuple
68

79

@@ -17,8 +19,7 @@ def __new__(cls, code, data):
1719
return super(ExtType, cls).__new__(cls, code, data)
1820

1921

20-
import os
21-
if os.environ.get('MSGPACK_PUREPYTHON'):
22+
if os.environ.get('MSGPACK_PUREPYTHON') or sys.version_info[0] == 2:
2223
from .fallback import Packer, unpackb, Unpacker
2324
else:
2425
try:

msgpack/_packer.pyx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,7 @@ cdef class Packer(object):
130130

131131
self._bencoding = encoding
132132
if encoding is None:
133-
if PY_MAJOR_VERSION < 3:
134-
self.encoding = 'utf-8'
135-
else:
136-
self.encoding = NULL
133+
self.encoding = 'utf-8'
137134
else:
138135
self.encoding = self._bencoding
139136

msgpack/buff_converter.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,8 @@
11
#include "Python.h"
22

33
/* cython does not support this preprocessor check => write it in raw C */
4-
#if PY_MAJOR_VERSION == 2
5-
static PyObject *
6-
buff_to_buff(char *buff, Py_ssize_t size)
7-
{
8-
return PyBuffer_FromMemory(buff, size);
9-
}
10-
11-
#elif (PY_MAJOR_VERSION == 3) && (PY_MINOR_VERSION >= 3)
124
static PyObject *
135
buff_to_buff(char *buff, Py_ssize_t size)
146
{
157
return PyMemoryView_FromMemory(buff, size, PyBUF_READ);
168
}
17-
#else
18-
static PyObject *
19-
buff_to_buff(char *buff, Py_ssize_t size)
20-
{
21-
Py_buffer pybuf;
22-
if (PyBuffer_FillInfo(&pybuf, NULL, buff, size, 1, PyBUF_FULL_RO) == -1) {
23-
return NULL;
24-
}
25-
26-
return PyMemoryView_FromBuffer(&pybuf);
27-
}
28-
#endif

msgpack/fallback.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
import warnings
66

77

8-
if sys.version_info[0] == 2:
9-
PY2 = True
8+
PY2 = sys.version_info[0] == 2
9+
if PY2:
1010
int_types = (int, long)
1111
def dict_iteritems(d):
1212
return d.iteritems()
1313
else:
14-
PY2 = False
1514
int_types = int
1615
unicode = str
1716
xrange = range

msgpack/unpack.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,7 @@ static inline int unpack_callback_ext(unpack_user* u, const char* base, const ch
273273
return -1;
274274
}
275275
// length also includes the typecode, so the actual data is length-1
276-
#if PY_MAJOR_VERSION == 2
277-
py = PyObject_CallFunction(u->ext_hook, "(is#)", (int)typecode, pos, (Py_ssize_t)length-1);
278-
#else
279276
py = PyObject_CallFunction(u->ext_hook, "(iy#)", (int)typecode, pos, (Py_ssize_t)length-1);
280-
#endif
281277
if (!py)
282278
return -1;
283279
*o = py;

setup.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
from distutils.command.build_ext import build_ext
1111

12+
13+
PYPY = hasattr(sys, "pypy_version_info")
14+
PY2 = sys.version_info[0] == 2
15+
16+
1217
# for building transitional package.
1318
TRANSITIONAL = False
1419

@@ -64,14 +69,11 @@ def build_extension(self, ext):
6469
if len(version) > 3 and version[3] != 'final':
6570
version_str += version[3]
6671

67-
# take care of extension modules.
68-
if have_cython:
69-
class Sdist(sdist):
70-
def __init__(self, *args, **kwargs):
71-
cythonize('msgpack/_cmsgpack.pyx')
72-
sdist.__init__(self, *args, **kwargs)
73-
else:
74-
Sdist = sdist
72+
# Cython is required for sdist
73+
class Sdist(sdist):
74+
def __init__(self, *args, **kwargs):
75+
cythonize('msgpack/_cmsgpack.pyx')
76+
sdist.__init__(self, *args, **kwargs)
7577

7678
libraries = []
7779
if sys.platform == 'win32':
@@ -83,7 +85,7 @@ def __init__(self, *args, **kwargs):
8385
macros = [('__LITTLE_ENDIAN__', '1')]
8486

8587
ext_modules = []
86-
if not hasattr(sys, 'pypy_version_info'):
88+
if not PYPY and not PY2:
8789
ext_modules.append(Extension('msgpack._cmsgpack',
8890
sources=['msgpack/_cmsgpack.cpp'],
8991
libraries=libraries,

0 commit comments

Comments
 (0)
0