Skip to content

Commit cb50b20

Browse files
authored
Update setuptools and black (#498)
* Use setuptools * Use black==22.1.0
1 parent 89ea577 commit cb50b20

13 files changed

+83
-84
lines changed

.github/workflows/black.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
architecture: 'x64'
1818

1919
- name: Checkout
20-
uses: actions/checkout@v1
20+
uses: actions/checkout@v2
2121

2222
- name: Black Code Formatter
2323
run: |
24-
pip install black
25-
black --diff --check msgpack/ test/ setup.py
24+
pip install black==22.1.0
25+
black -S --diff --check msgpack/ test/ setup.py

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ all: cython
44

55
.PHONY: black
66
black:
7-
black msgpack/ test/ setup.py
7+
black -S msgpack/ test/ setup.py
88

99
.PHONY: cython
1010
cython:

msgpack/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# coding: utf-8
2-
from ._version import version
32
from .exceptions import *
43
from .ext import ExtType, Timestamp
54

65
import os
76
import sys
87

98

9+
version = (1, 0, 4, 'dev')
10+
__version__ = "1.0.4dev"
11+
12+
1013
if os.environ.get("MSGPACK_PUREPYTHON") or sys.version_info[0] == 2:
1114
from .fallback import Packer, unpackb, Unpacker
1215
else:

msgpack/_version.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

msgpack/ext.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(self, seconds, nanoseconds=0):
5959
raise TypeError("seconds must be an interger")
6060
if not isinstance(nanoseconds, int_types):
6161
raise TypeError("nanoseconds must be an integer")
62-
if not (0 <= nanoseconds < 10 ** 9):
62+
if not (0 <= nanoseconds < 10**9):
6363
raise ValueError(
6464
"nanoseconds must be a non-negative integer less than 999999999."
6565
)
@@ -143,7 +143,7 @@ def from_unix(unix_sec):
143143
:type unix_float: int or float.
144144
"""
145145
seconds = int(unix_sec // 1)
146-
nanoseconds = int((unix_sec % 1) * 10 ** 9)
146+
nanoseconds = int((unix_sec % 1) * 10**9)
147147
return Timestamp(seconds, nanoseconds)
148148

149149
def to_unix(self):
@@ -161,15 +161,15 @@ def from_unix_nano(unix_ns):
161161
:param int unix_ns: Posix timestamp in nanoseconds.
162162
:rtype: Timestamp
163163
"""
164-
return Timestamp(*divmod(unix_ns, 10 ** 9))
164+
return Timestamp(*divmod(unix_ns, 10**9))
165165

166166
def to_unix_nano(self):
167167
"""Get the timestamp as a unixtime in nanoseconds.
168168
169169
:returns: posix timestamp in nanoseconds
170170
:rtype: int
171171
"""
172-
return self.seconds * 10 ** 9 + self.nanoseconds
172+
return self.seconds * 10**9 + self.nanoseconds
173173

174174
def to_datetime(self):
175175
"""Get the timestamp as a UTC datetime.

msgpack/fallback.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def __init__(
318318
self._buf_checkpoint = 0
319319

320320
if not max_buffer_size:
321-
max_buffer_size = 2 ** 31 - 1
321+
max_buffer_size = 2**31 - 1
322322
if max_str_len == -1:
323323
max_str_len = max_buffer_size
324324
if max_bin_len == -1:
@@ -800,20 +800,20 @@ def _pack(
800800
raise OverflowError("Integer value out of range")
801801
if check(obj, (bytes, bytearray)):
802802
n = len(obj)
803-
if n >= 2 ** 32:
803+
if n >= 2**32:
804804
raise ValueError("%s is too large" % type(obj).__name__)
805805
self._pack_bin_header(n)
806806
return self._buffer.write(obj)
807807
if check(obj, unicode):
808808
obj = obj.encode("utf-8", self._unicode_errors)
809809
n = len(obj)
810-
if n >= 2 ** 32:
810+
if n >= 2**32:
811811
raise ValueError("String is too large")
812812
self._pack_raw_header(n)
813813
return self._buffer.write(obj)
814814
if check(obj, memoryview):
815815
n = len(obj) * obj.itemsize
816-
if n >= 2 ** 32:
816+
if n >= 2**32:
817817
raise ValueError("Memoryview is too large")
818818
self._pack_bin_header(n)
819819
return self._buffer.write(obj)
@@ -895,7 +895,7 @@ def pack_map_pairs(self, pairs):
895895
return ret
896896

897897
def pack_array_header(self, n):
898-
if n >= 2 ** 32:
898+
if n >= 2**32:
899899
raise ValueError
900900
self._pack_array_header(n)
901901
if self._autoreset:
@@ -904,7 +904,7 @@ def pack_array_header(self, n):
904904
return ret
905905

906906
def pack_map_header(self, n):
907-
if n >= 2 ** 32:
907+
if n >= 2**32:
908908
raise ValueError
909909
self._pack_map_header(n)
910910
if self._autoreset:

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# Also declared in pyproject.toml, if updating here please also update there
22
Cython~=0.29.13
3+
4+
# dev only tools. no need to add pyproject
5+
black==22.1.0

setup.cfg

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[metadata]
2+
name = msgpack
3+
#version = attr: msgpack.__version__
4+
version = attr: msgpack.version
5+
license = Apache 2.0
6+
author = Inada Naoki
7+
author_email = [email protected]
8+
description = MessagePack serializer
9+
long_description = file: README.md
10+
long_description_content_type = text/markdown
11+
url = https://msgpack.org/
12+
13+
project_urls =
14+
Documentation = https://msgpack-python.readthedocs.io/
15+
Source = https://github.com/msgpack/msgpack-python
16+
Tracker = https://github.com/msgpack/msgpack-python/issues
17+
18+
classifiers =
19+
Programming Language :: Python :: 3
20+
Programming Language :: Python :: 3.6
21+
Programming Language :: Python :: 3.7
22+
Programming Language :: Python :: 3.8
23+
Programming Language :: Python :: 3.9
24+
Programming Language :: Python :: 3.10
25+
Programming Language :: Python :: Implementation :: CPython
26+
Programming Language :: Python :: Implementation :: PyPy
27+
Intended Audience :: Developers
28+
License :: OSI Approved :: Apache Software License
29+
30+
[flake8]
31+
max_line_length = 100
32+

setup.py

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
import os
55
import sys
66
from glob import glob
7-
from distutils.command.sdist import sdist
87
from setuptools import setup, Extension
9-
10-
from distutils.command.build_ext import build_ext
8+
from setuptools.command.build_ext import build_ext
9+
from setuptools.command.sdist import sdist
1110

1211

1312
PYPY = hasattr(sys, "pypy_version_info")
@@ -65,12 +64,6 @@ def build_extension(self, ext):
6564
print(e)
6665

6766

68-
exec(open("msgpack/_version.py").read())
69-
70-
version_str = ".".join(str(x) for x in version[:3])
71-
if len(version) > 3 and version[3] != "final":
72-
version_str += version[3]
73-
7467
# Cython is required for sdist
7568
class Sdist(sdist):
7669
def __init__(self, *args, **kwargs):
@@ -99,39 +92,8 @@ def __init__(self, *args, **kwargs):
9992
del libraries, macros
10093

10194

102-
desc = "MessagePack (de)serializer."
103-
with io.open("README.md", encoding="utf-8") as f:
104-
long_desc = f.read()
105-
del f
106-
10795
setup(
108-
name="msgpack",
109-
author="Inada Naoki",
110-
author_email="[email protected]",
111-
version=version_str,
11296
cmdclass={"build_ext": BuildExt, "sdist": Sdist},
11397
ext_modules=ext_modules,
11498
packages=["msgpack"],
115-
description=desc,
116-
long_description=long_desc,
117-
long_description_content_type="text/markdown",
118-
url="https://msgpack.org/",
119-
project_urls={
120-
"Documentation": "https://msgpack-python.readthedocs.io/",
121-
"Source": "https://github.com/msgpack/msgpack-python",
122-
"Tracker": "https://github.com/msgpack/msgpack-python/issues",
123-
},
124-
license="Apache 2.0",
125-
classifiers=[
126-
"Programming Language :: Python :: 3",
127-
"Programming Language :: Python :: 3.6",
128-
"Programming Language :: Python :: 3.7",
129-
"Programming Language :: Python :: 3.8",
130-
"Programming Language :: Python :: 3.9",
131-
"Programming Language :: Python :: 3.10",
132-
"Programming Language :: Python :: Implementation :: CPython",
133-
"Programming Language :: Python :: Implementation :: PyPy",
134-
"Intended Audience :: Developers",
135-
"License :: OSI Approved :: Apache Software License",
136-
],
13799
)

test/test_limits.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,29 @@
1616

1717

1818
def test_integer():
19-
x = -(2 ** 63)
19+
x = -(2**63)
2020
assert unpackb(packb(x)) == x
2121
with pytest.raises(PackOverflowError):
2222
packb(x - 1)
2323

24-
x = 2 ** 64 - 1
24+
x = 2**64 - 1
2525
assert unpackb(packb(x)) == x
2626
with pytest.raises(PackOverflowError):
2727
packb(x + 1)
2828

2929

3030
def test_array_header():
3131
packer = Packer()
32-
packer.pack_array_header(2 ** 32 - 1)
32+
packer.pack_array_header(2**32 - 1)
3333
with pytest.raises(PackValueError):
34-
packer.pack_array_header(2 ** 32)
34+
packer.pack_array_header(2**32)
3535

3636

3737
def test_map_header():
3838
packer = Packer()
39-
packer.pack_map_header(2 ** 32 - 1)
39+
packer.pack_map_header(2**32 - 1)
4040
with pytest.raises(PackValueError):
41-
packer.pack_array_header(2 ** 32)
41+
packer.pack_array_header(2**32)
4242

4343

4444
def test_max_str_len():

test/test_memoryview.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,46 +53,46 @@ def test_fixstr_from_float():
5353

5454

5555
def test_str16_from_byte():
56-
_runtest("B", 2 ** 8, b"\xda", b"\x01\x00", False)
57-
_runtest("B", 2 ** 16 - 1, b"\xda", b"\xff\xff", False)
56+
_runtest("B", 2**8, b"\xda", b"\x01\x00", False)
57+
_runtest("B", 2**16 - 1, b"\xda", b"\xff\xff", False)
5858

5959

6060
def test_str16_from_float():
61-
_runtest("f", 2 ** 8, b"\xda", b"\x01\x00", False)
62-
_runtest("f", 2 ** 16 - 4, b"\xda", b"\xff\xfc", False)
61+
_runtest("f", 2**8, b"\xda", b"\x01\x00", False)
62+
_runtest("f", 2**16 - 4, b"\xda", b"\xff\xfc", False)
6363

6464

6565
def test_str32_from_byte():
66-
_runtest("B", 2 ** 16, b"\xdb", b"\x00\x01\x00\x00", False)
66+
_runtest("B", 2**16, b"\xdb", b"\x00\x01\x00\x00", False)
6767

6868

6969
def test_str32_from_float():
70-
_runtest("f", 2 ** 16, b"\xdb", b"\x00\x01\x00\x00", False)
70+
_runtest("f", 2**16, b"\xdb", b"\x00\x01\x00\x00", False)
7171

7272

7373
def test_bin8_from_byte():
7474
_runtest("B", 1, b"\xc4", b"\x01", True)
75-
_runtest("B", 2 ** 8 - 1, b"\xc4", b"\xff", True)
75+
_runtest("B", 2**8 - 1, b"\xc4", b"\xff", True)
7676

7777

7878
def test_bin8_from_float():
7979
_runtest("f", 4, b"\xc4", b"\x04", True)
80-
_runtest("f", 2 ** 8 - 4, b"\xc4", b"\xfc", True)
80+
_runtest("f", 2**8 - 4, b"\xc4", b"\xfc", True)
8181

8282

8383
def test_bin16_from_byte():
84-
_runtest("B", 2 ** 8, b"\xc5", b"\x01\x00", True)
85-
_runtest("B", 2 ** 16 - 1, b"\xc5", b"\xff\xff", True)
84+
_runtest("B", 2**8, b"\xc5", b"\x01\x00", True)
85+
_runtest("B", 2**16 - 1, b"\xc5", b"\xff\xff", True)
8686

8787

8888
def test_bin16_from_float():
89-
_runtest("f", 2 ** 8, b"\xc5", b"\x01\x00", True)
90-
_runtest("f", 2 ** 16 - 4, b"\xc5", b"\xff\xfc", True)
89+
_runtest("f", 2**8, b"\xc5", b"\x01\x00", True)
90+
_runtest("f", 2**16 - 4, b"\xc5", b"\xff\xfc", True)
9191

9292

9393
def test_bin32_from_byte():
94-
_runtest("B", 2 ** 16, b"\xc6", b"\x00\x01\x00\x00", True)
94+
_runtest("B", 2**16, b"\xc6", b"\x00\x01\x00\x00", True)
9595

9696

9797
def test_bin32_from_float():
98-
_runtest("f", 2 ** 16, b"\xc6", b"\x00\x01\x00\x00", True)
98+
_runtest("f", 2**16, b"\xc6", b"\x00\x01\x00\x00", True)

test/test_sequnpack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ def test_issue124():
118118

119119
def test_unpack_tell():
120120
stream = io.BytesIO()
121-
messages = [2 ** i - 1 for i in range(65)]
122-
messages += [-(2 ** i) for i in range(1, 64)]
121+
messages = [2**i - 1 for i in range(65)]
122+
messages += [-(2**i) for i in range(1, 64)]
123123
messages += [
124124
b"hello",
125125
b"hello" * 1000,

test/test_timestamp.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@
1010

1111
def test_timestamp():
1212
# timestamp32
13-
ts = Timestamp(2 ** 32 - 1)
13+
ts = Timestamp(2**32 - 1)
1414
assert ts.to_bytes() == b"\xff\xff\xff\xff"
1515
packed = msgpack.packb(ts)
1616
assert packed == b"\xd6\xff" + ts.to_bytes()
1717
unpacked = msgpack.unpackb(packed)
1818
assert ts == unpacked
19-
assert ts.seconds == 2 ** 32 - 1 and ts.nanoseconds == 0
19+
assert ts.seconds == 2**32 - 1 and ts.nanoseconds == 0
2020

2121
# timestamp64
22-
ts = Timestamp(2 ** 34 - 1, 999999999)
22+
ts = Timestamp(2**34 - 1, 999999999)
2323
assert ts.to_bytes() == b"\xee\x6b\x27\xff\xff\xff\xff\xff"
2424
packed = msgpack.packb(ts)
2525
assert packed == b"\xd7\xff" + ts.to_bytes()
2626
unpacked = msgpack.unpackb(packed)
2727
assert ts == unpacked
28-
assert ts.seconds == 2 ** 34 - 1 and ts.nanoseconds == 999999999
28+
assert ts.seconds == 2**34 - 1 and ts.nanoseconds == 999999999
2929

3030
# timestamp96
31-
ts = Timestamp(2 ** 63 - 1, 999999999)
31+
ts = Timestamp(2**63 - 1, 999999999)
3232
assert ts.to_bytes() == b"\x3b\x9a\xc9\xff\x7f\xff\xff\xff\xff\xff\xff\xff"
3333
packed = msgpack.packb(ts)
3434
assert packed == b"\xc7\x0c\xff" + ts.to_bytes()
3535
unpacked = msgpack.unpackb(packed)
3636
assert ts == unpacked
37-
assert ts.seconds == 2 ** 63 - 1 and ts.nanoseconds == 999999999
37+
assert ts.seconds == 2**63 - 1 and ts.nanoseconds == 999999999
3838

3939
# negative fractional
4040
ts = Timestamp.from_unix(-2.3) # s: -3, ns: 700000000

0 commit comments

Comments
 (0)