msgpack-python/setup.py

78 lines
1.7 KiB
Python
Raw Normal View History

2009-06-24 14:33:36 +09:00
#!/usr/bin/env python
2009-06-10 10:45:07 +09:00
import os
import sys
2012-06-27 18:16:59 +09:00
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
from setuptools.command.sdist import sdist
2012-08-19 02:53:16 +09:00
PYPY = hasattr(sys, "pypy_version_info")
class NoCython(Exception):
pass
2019-12-05 18:53:49 +09:00
2010-01-25 20:52:48 +09:00
try:
import Cython.Compiler.Main as cython_compiler
2019-12-05 18:53:49 +09:00
2010-01-25 20:52:48 +09:00
have_cython = True
except ImportError:
have_cython = False
2009-06-08 01:43:50 +09:00
2012-08-19 02:53:16 +09:00
def cythonize(src):
2023-09-28 15:25:10 +09:00
if not have_cython:
raise Exception("Cython is required for building from checkout")
sys.stderr.write(f"cythonize: {src!r}\n")
cython_compiler.compile([src])
2012-08-19 02:53:16 +09:00
2019-12-05 18:53:49 +09:00
2012-08-19 02:53:16 +09:00
def ensure_source(src):
2019-12-05 18:53:49 +09:00
pyx = os.path.splitext(src)[0] + ".pyx"
2012-08-19 02:53:16 +09:00
2023-09-28 15:25:10 +09:00
if not os.path.exists(src) or have_cython and os.stat(src).st_mtime < os.stat(pyx).st_mtime:
2012-08-21 14:56:32 +09:00
cythonize(pyx)
2012-08-19 02:53:16 +09:00
class BuildExt(build_ext):
def build_extension(self, ext):
2023-09-28 15:25:10 +09:00
for src in ext.sources:
ensure_source(src)
return build_ext.build_extension(self, ext)
2012-08-19 02:53:16 +09:00
# Cython is required for sdist
class Sdist(sdist):
def __init__(self, *args, **kwargs):
2019-12-05 18:53:49 +09:00
cythonize("msgpack/_cmsgpack.pyx")
sdist.__init__(self, *args, **kwargs)
2010-01-25 20:52:48 +09:00
2019-12-05 18:53:49 +09:00
libraries = []
macros = []
ext_modules = []
2019-12-05 18:53:49 +09:00
if sys.platform == "win32":
libraries.append("ws2_32")
macros = [("__LITTLE_ENDIAN__", "1")]
if not PYPY and not os.environ.get("MSGPACK_PUREPYTHON"):
2019-12-05 18:53:49 +09:00
ext_modules.append(
Extension(
"msgpack._cmsgpack",
sources=["msgpack/_cmsgpack.c"],
2019-12-05 18:53:49 +09:00
libraries=libraries,
include_dirs=["."],
define_macros=macros,
)
)
2012-12-11 22:15:21 +09:00
del libraries, macros
2010-01-25 20:52:48 +09:00
2009-06-08 01:43:50 +09:00
2019-12-05 18:53:49 +09:00
setup(
cmdclass={"build_ext": BuildExt, "sdist": Sdist},
ext_modules=ext_modules,
packages=["msgpack"],
2018-01-07 01:57:47 +09:00
)