do not install cython as build dependency (#610)

User can not cythonize during `pip install msgpack`.
So remove cython from build dependency.

If user need to use another Cython, user should download sdist, unzip,
manually cythonize, and `pip install .`.
This commit is contained in:
Inada Naoki 2024-05-07 22:01:54 +09:00 committed by GitHub
parent 9cea8b6da2
commit 0b1c47b06b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 1 additions and 50 deletions

View file

@ -3,52 +3,9 @@ import os
import sys
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext
from setuptools.command.sdist import sdist
PYPY = hasattr(sys, "pypy_version_info")
class NoCython(Exception):
pass
try:
import Cython.Compiler.Main as cython_compiler
have_cython = True
except ImportError:
have_cython = False
def cythonize(src):
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])
def ensure_source(src):
pyx = os.path.splitext(src)[0] + ".pyx"
if not os.path.exists(src) or have_cython and os.stat(src).st_mtime < os.stat(pyx).st_mtime:
cythonize(pyx)
class BuildExt(build_ext):
def build_extension(self, ext):
for src in ext.sources:
ensure_source(src)
return build_ext.build_extension(self, ext)
# Cython is required for sdist
class Sdist(sdist):
def __init__(self, *args, **kwargs):
cythonize("msgpack/_cmsgpack.pyx")
sdist.__init__(self, *args, **kwargs)
libraries = []
macros = []
ext_modules = []
@ -69,9 +26,7 @@ if not PYPY and not os.environ.get("MSGPACK_PUREPYTHON"):
)
del libraries, macros
setup(
cmdclass={"build_ext": BuildExt, "sdist": Sdist},
ext_modules=ext_modules,
packages=["msgpack"],
)