1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#!/usr/bin/env python
import os
import re
import platform
import sys
import sysconfig
from setuptools import find_packages, setup
from setuptools.command.build_ext import build_ext
base_dir = os.path.dirname(os.path.abspath(__file__))
long_description = (
open("README.rst").read() + '\n\n' + open("HISTORY.rst").read()
)
with open(os.path.join(base_dir, "src", "brotlicffi", "__init__.py")) as f:
__version__ = re.search(r"__version__ = \"([^\"]+)\"", f.read()).group(1)
class BuildClibBeforeExt(build_ext):
""" Setuptools `develop` command (used by `pip install -e .`) only calls
`build_ext`, unlike `install` which calls `build` and all its related
sub-commands. Linking the CFFI extension with the libbrotli static library
fails since the `build_clib` command is not called in the former case.
This custom `build_ext` class ensures that `build_clib` command is run
before the CFFI extension module is compiled.
https://github.com/pypa/pip/issues/4523
"""
def get_source_files(self):
filenames = build_ext.get_source_files(self)
filenames.extend(depends)
return filenames
def run(self):
self.run_command("build_clib")
build_ext.run(self)
depends = []
libraries = []
USE_SHARED_BROTLI = os.environ.get("USE_SHARED_BROTLI")
if USE_SHARED_BROTLI != "1":
sources = []
for root, _, filenames in os.walk("libbrotli/c"):
root_parts = os.path.split(root)
if "fuzz" in root_parts or "tools" in root_parts:
continue
for filename in filenames:
relpath = os.path.relpath(os.path.join(root, filename), base_dir)
if filename.endswith(".h"):
depends.append(relpath)
elif filename.endswith(".c"):
sources.append(relpath)
libraries = [
("libbrotli", {
"include_dirs": [
"libbrotli/c/include",
"libbrotli/c/common",
"libbrotli/c",
"src/brotlicffi"
],
"depends": depends,
"sources": sources,
}),
]
cmdclass = {'build_ext': BuildClibBeforeExt}
if sys.version_info > (3,) and platform.python_implementation() == "CPython":
try:
import wheel.bdist_wheel
except ImportError:
pass
else:
# the limited API is only supported on GIL builds as of Python 3.14
if not bool(sysconfig.get_config_var("Py_GIL_DISABLED")):
class BDistWheel(wheel.bdist_wheel.bdist_wheel):
def finalize_options(self):
self.py_limited_api = "cp3{}".format(sys.version_info[1])
wheel.bdist_wheel.bdist_wheel.finalize_options(self)
cmdclass['bdist_wheel'] = BDistWheel
setup(
name="brotlicffi",
version=__version__,
description="Python CFFI bindings to the Brotli library",
long_description=long_description,
url="https://github.com/python-hyper/brotlicffi",
license="MIT",
author="Cory Benfield",
author_email="cory@lukasa.co.uk",
setup_requires=[
"cffi>=1.0.0; python_version<'3.13'",
"cffi>=1.17.0; python_version>='3.13'",
],
install_requires=[
"cffi>=1.0.0; python_version<'3.13'",
"cffi>=1.17.0; python_version>='3.13'",
],
python_requires=">=3.8",
cffi_modules=["src/brotlicffi/_build.py:ffi"],
packages=find_packages('src'),
package_dir={'': 'src'},
ext_package="brotlicffi",
libraries=libraries,
zip_safe=False,
cmdclass=cmdclass,
classifiers=[
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Programming Language :: Python :: Free Threading :: 2 - Beta",
]
)
|