blacken all files.

This commit is contained in:
Inada Naoki 2019-12-05 18:53:49 +09:00
parent 10e5e39ff9
commit bc8c86203a
3 changed files with 159 additions and 144 deletions

View file

@ -1,6 +1,8 @@
from msgpack import fallback from msgpack import fallback
try: try:
from msgpack import _unpacker, _packer from msgpack import _unpacker, _packer
has_ext = True has_ext = True
except ImportError: except ImportError:
has_ext = False has_ext = False
@ -9,7 +11,7 @@ import timeit
def profile(name, func): def profile(name, func):
times = timeit.repeat(func, number=1000, repeat=4) times = timeit.repeat(func, number=1000, repeat=4)
times = ', '.join(["%8f" % t for t in times]) times = ", ".join(["%8f" % t for t in times])
print("%-30s %40s" % (name, times)) print("%-30s %40s" % (name, times))
@ -18,17 +20,19 @@ def simple(name, data):
packer = _packer.Packer() packer = _packer.Packer()
profile("packing %s (ext)" % name, lambda: packer.pack(data)) profile("packing %s (ext)" % name, lambda: packer.pack(data))
packer = fallback.Packer() packer = fallback.Packer()
profile('packing %s (fallback)' % name, lambda: packer.pack(data)) profile("packing %s (fallback)" % name, lambda: packer.pack(data))
data = packer.pack(data) data = packer.pack(data)
if has_ext: if has_ext:
profile('unpacking %s (ext)' % name, lambda: _unpacker.unpackb(data)) profile("unpacking %s (ext)" % name, lambda: _unpacker.unpackb(data))
profile('unpacking %s (fallback)' % name, lambda: fallback.unpackb(data)) profile("unpacking %s (fallback)" % name, lambda: fallback.unpackb(data))
def main(): def main():
simple("integers", [7] * 10000) simple("integers", [7] * 10000)
simple("bytes", [b'x'*n for n in range(100)]*10) simple("bytes", [b"x" * n for n in range(100)] * 10)
simple("lists", [[]] * 10000) simple("lists", [[]] * 10000)
simple("dicts", [{}] * 10000) simple("dicts", [{}] * 10000)
main() main()

View file

@ -25,23 +25,23 @@ import sys, os
# Add any Sphinx extension module names here, as strings. They can be extensions # Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode'] extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode"]
# Add any paths that contain templates here, relative to this directory. # Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates'] templates_path = ["_templates"]
# The suffix of source filenames. # The suffix of source filenames.
source_suffix = '.rst' source_suffix = ".rst"
# The encoding of source files. # The encoding of source files.
# source_encoding = 'utf-8-sig' # source_encoding = 'utf-8-sig'
# The master toctree document. # The master toctree document.
master_doc = 'index' master_doc = "index"
# General information about the project. # General information about the project.
project = u'msgpack' project = u"msgpack"
copyright = u'2013, INADA Naoki' copyright = u"2013, INADA Naoki"
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the # |version| and |release|, also used in various other places throughout the
@ -49,7 +49,7 @@ copyright = u'2013, INADA Naoki'
# #
# The short X.Y version. # The short X.Y version.
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
version = release = '0.5' version = release = "0.5"
# The language for content autogenerated by Sphinx. Refer to documentation # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.
@ -64,7 +64,7 @@ today_fmt = "%Y-%m-%d"
# List of patterns, relative to source directory, that match files and # List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files. # directories to ignore when looking for source files.
exclude_patterns = ['_build'] exclude_patterns = ["_build"]
# The reST default role (used for this markup: `text`) to use for all documents. # The reST default role (used for this markup: `text`) to use for all documents.
# default_role = None # default_role = None
@ -81,7 +81,7 @@ exclude_patterns = ['_build']
# show_authors = False # show_authors = False
# The name of the Pygments (syntax highlighting) style to use. # The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx' pygments_style = "sphinx"
# A list of ignored prefixes for module index sorting. # A list of ignored prefixes for module index sorting.
# modindex_common_prefix = [] # modindex_common_prefix = []
@ -91,7 +91,7 @@ pygments_style = 'sphinx'
# The theme to use for HTML and HTML Help pages. See the documentation for # The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes. # a list of builtin themes.
html_theme = 'sphinxdoc' html_theme = "sphinxdoc"
# Theme options are theme-specific and customize the look and feel of a theme # Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the # further. For a list of options available for each theme, see the
@ -120,7 +120,7 @@ html_theme = 'sphinxdoc'
# Add any paths that contain custom static files (such as style sheets) here, # Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files, # relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css". # so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static'] html_static_path = ["_static"]
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format. # using the given strftime format.
@ -164,7 +164,7 @@ html_static_path = ['_static']
# html_file_suffix = None # html_file_suffix = None
# Output file base name for HTML help builder. # Output file base name for HTML help builder.
htmlhelp_basename = 'msgpackdoc' htmlhelp_basename = "msgpackdoc"
# -- Options for LaTeX output -------------------------------------------------- # -- Options for LaTeX output --------------------------------------------------
@ -172,10 +172,8 @@ htmlhelp_basename = 'msgpackdoc'
latex_elements = { latex_elements = {
# The paper size ('letterpaper' or 'a4paper'). # The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper', #'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt'). # The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt', #'pointsize': '10pt',
# Additional stuff for the LaTeX preamble. # Additional stuff for the LaTeX preamble.
#'preamble': '', #'preamble': '',
} }
@ -183,8 +181,7 @@ latex_elements = {
# Grouping the document tree into LaTeX files. List of tuples # Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]). # (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [ latex_documents = [
('index', 'msgpack.tex', u'msgpack Documentation', ("index", "msgpack.tex", u"msgpack Documentation", u"Author", "manual"),
u'Author', 'manual'),
] ]
# The name of an image file (relative to this directory) to place at the top of # The name of an image file (relative to this directory) to place at the top of
@ -212,10 +209,7 @@ latex_documents = [
# One entry per manual page. List of tuples # One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section). # (source start file, name, description, authors, manual section).
man_pages = [ man_pages = [("index", "msgpack", u"msgpack Documentation", [u"Author"], 1)]
('index', 'msgpack', u'msgpack Documentation',
[u'Author'], 1)
]
# If true, show URL addresses after external links. # If true, show URL addresses after external links.
# man_show_urls = False # man_show_urls = False
@ -227,9 +221,15 @@ man_pages = [
# (source start file, target name, title, author, # (source start file, target name, title, author,
# dir menu entry, description, category) # dir menu entry, description, category)
texinfo_documents = [ texinfo_documents = [
('index', 'msgpack', u'msgpack Documentation', (
u'Author', 'msgpack', 'One line description of project.', "index",
'Miscellaneous'), "msgpack",
u"msgpack Documentation",
u"Author",
"msgpack",
"One line description of project.",
"Miscellaneous",
),
] ]
# Documents to append as an appendix to all manuals. # Documents to append as an appendix to all manuals.
@ -245,10 +245,10 @@ texinfo_documents = [
# -- Options for Epub output --------------------------------------------------- # -- Options for Epub output ---------------------------------------------------
# Bibliographic Dublin Core info. # Bibliographic Dublin Core info.
epub_title = u'msgpack' epub_title = u"msgpack"
epub_author = u'Author' epub_author = u"Author"
epub_publisher = u'Author' epub_publisher = u"Author"
epub_copyright = u'2013, Author' epub_copyright = u"2013, Author"
# The language of the text. It defaults to the language option # The language of the text. It defaults to the language option
# or en if the language is not set. # or en if the language is not set.

View file

@ -17,11 +17,14 @@ PY2 = sys.version_info[0] == 2
# for building transitional package. # for building transitional package.
TRANSITIONAL = False TRANSITIONAL = False
class NoCython(Exception): class NoCython(Exception):
pass pass
try: try:
import Cython.Compiler.Main as cython_compiler import Cython.Compiler.Main as cython_compiler
have_cython = True have_cython = True
except ImportError: except ImportError:
have_cython = False have_cython = False
@ -31,16 +34,19 @@ def cythonize(src):
sys.stderr.write("cythonize: %r\n" % (src,)) sys.stderr.write("cythonize: %r\n" % (src,))
cython_compiler.compile([src], cplus=True) cython_compiler.compile([src], cplus=True)
def ensure_source(src): def ensure_source(src):
pyx = os.path.splitext(src)[0] + '.pyx' pyx = os.path.splitext(src)[0] + ".pyx"
if not os.path.exists(src): if not os.path.exists(src):
if not have_cython: if not have_cython:
raise NoCython raise NoCython
cythonize(pyx) cythonize(pyx)
elif (os.path.exists(pyx) and elif (
os.stat(src).st_mtime < os.stat(pyx).st_mtime and os.path.exists(pyx)
have_cython): and os.stat(src).st_mtime < os.stat(pyx).st_mtime
and have_cython
):
cythonize(pyx) cythonize(pyx)
return src return src
@ -63,77 +69,82 @@ class BuildExt(build_ext):
print(e) print(e)
exec(open('msgpack/_version.py').read()) exec(open("msgpack/_version.py").read())
version_str = '.'.join(str(x) for x in version[:3]) 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]
# Cython is required for sdist # Cython is required for sdist
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)
libraries = []
if sys.platform == 'win32':
libraries.append('ws2_32')
if sys.byteorder == 'big': libraries = []
macros = [('__BIG_ENDIAN__', '1')] if sys.platform == "win32":
libraries.append("ws2_32")
if sys.byteorder == "big":
macros = [("__BIG_ENDIAN__", "1")]
else: else:
macros = [('__LITTLE_ENDIAN__', '1')] macros = [("__LITTLE_ENDIAN__", "1")]
ext_modules = [] ext_modules = []
if not PYPY and not PY2: if not PYPY and not PY2:
ext_modules.append(Extension('msgpack._cmsgpack', ext_modules.append(
sources=['msgpack/_cmsgpack.cpp'], Extension(
"msgpack._cmsgpack",
sources=["msgpack/_cmsgpack.cpp"],
libraries=libraries, libraries=libraries,
include_dirs=['.'], include_dirs=["."],
define_macros=macros, define_macros=macros,
)) )
)
del libraries, macros del libraries, macros
desc = 'MessagePack (de)serializer.' desc = "MessagePack (de)serializer."
with io.open('README.rst', encoding='utf-8') as f: with io.open("README.rst", encoding="utf-8") as f:
long_desc = f.read() long_desc = f.read()
del f del f
name = 'msgpack' name = "msgpack"
if TRANSITIONAL: if TRANSITIONAL:
name = 'msgpack-python' name = "msgpack-python"
long_desc = "This package is deprecated. Install msgpack instead." long_desc = "This package is deprecated. Install msgpack instead."
setup(name=name, setup(
author='INADA Naoki', name=name,
author_email='songofacandy@gmail.com', author="INADA Naoki",
author_email="songofacandy@gmail.com",
version=version_str, version=version_str,
cmdclass={'build_ext': BuildExt, 'sdist': Sdist}, cmdclass={"build_ext": BuildExt, "sdist": Sdist},
ext_modules=ext_modules, ext_modules=ext_modules,
packages=['msgpack'], packages=["msgpack"],
description=desc, description=desc,
long_description=long_desc, long_description=long_desc,
long_description_content_type="text/x-rst", long_description_content_type="text/x-rst",
url='https://msgpack.org/', url="https://msgpack.org/",
project_urls={ project_urls={
'Documentation': 'https://msgpack-python.readthedocs.io/', "Documentation": "https://msgpack-python.readthedocs.io/",
'Source': 'https://github.com/msgpack/msgpack-python', "Source": "https://github.com/msgpack/msgpack-python",
'Tracker': 'https://github.com/msgpack/msgpack-python/issues', "Tracker": "https://github.com/msgpack/msgpack-python/issues",
}, },
license='Apache 2.0', license="Apache 2.0",
classifiers=[ classifiers=[
'Programming Language :: Python :: 2', "Programming Language :: Python :: 2",
'Programming Language :: Python :: 2.7', "Programming Language :: Python :: 2.7",
'Programming Language :: Python :: 3', "Programming Language :: Python :: 3",
'Programming Language :: Python :: 3.5', "Programming Language :: Python :: 3.5",
'Programming Language :: Python :: 3.6', "Programming Language :: Python :: 3.6",
'Programming Language :: Python :: 3.7', "Programming Language :: Python :: 3.7",
'Programming Language :: Python :: 3.8', "Programming Language :: Python :: 3.8",
'Programming Language :: Python :: Implementation :: CPython', "Programming Language :: Python :: Implementation :: CPython",
'Programming Language :: Python :: Implementation :: PyPy', "Programming Language :: Python :: Implementation :: PyPy",
'Intended Audience :: Developers', "Intended Audience :: Developers",
'License :: OSI Approved :: Apache Software License', "License :: OSI Approved :: Apache Software License",
], ],
) )