Skip to content

Instantly share code, notes, and snippets.

@sethmlarson
Created September 2, 2021 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sethmlarson/cb35db612d80136da7a523a14d8fc1d4 to your computer and use it in GitHub Desktop.
Save sethmlarson/cb35db612d80136da7a523a14d8fc1d4 to your computer and use it in GitHub Desktop.
Diff between brotlipy 0.7.0 tag and the source for building the abi3 compatible wheels
diff --git a/setup.py b/setup.py
index f804932..12ae724 100644
--- a/setup.py
+++ b/setup.py
@@ -1,11 +1,43 @@
#!/usr/bin/env python
+import platform
+import sys
from setuptools import find_packages, setup
+from setuptools.command.build_ext import build_ext
long_description = (
open("README.rst").read() + '\n\n' + open("HISTORY.rst").read()
)
+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 run(self):
+ self.run_command("build_clib")
+ build_ext.run(self)
+
+
+cmdclass = {'build_ext': BuildClibBeforeExt}
+if sys.version_info > (3,) and platform.python_implementation() == "CPython":
+ try:
+ import wheel.bdist_wheel
+ except ImportError:
+ pass
+ else:
+ 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="brotlipy",
version="0.7.0",
@@ -27,6 +59,7 @@ setup(
extras_require={
':python_version == "2.7" or python_version == "3.3"': ['enum34>=1.0.4, <2'],
},
+ cmdclass=cmdclass,
cffi_modules=["src/brotli/build.py:ffi"],
@@ -70,7 +103,6 @@ setup(
],
zip_safe=False,
classifiers=[
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment