Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix building against system qhull #19329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
from distutils.dist import Distribution

import setupext
from setupext import (
get_and_extract_tarball, print_raw, print_status, LOCAL_QHULL_VERSION)
from setupext import print_raw, print_status

# Get the version from versioneer
import versioneer
Expand All @@ -61,6 +60,7 @@
setupext.Python(),
setupext.Platform(),
setupext.FreeType(),
setupext.Qhull(),
setupext.SampleData(),
setupext.Tests(),
setupext.BackendMacOSX(),
Expand All @@ -86,18 +86,8 @@ def __init__(self, dist):
"'python setup.py test'. Please run 'pytest'.")


def _download_qhull():
toplevel = get_and_extract_tarball(
urls=["http://www.qhull.org/download/qhull-2020-src-8.0.2.tgz"],
sha="b5c2d7eb833278881b952c8a52d20179eab87766b00b865000469a45c1838b7e",
dirname=f"qhull-{LOCAL_QHULL_VERSION}",
)
shutil.copyfile(toplevel / "COPYING.txt", "LICENSE/LICENSE_QHULL")


class BuildExtraLibraries(BuildExtCommand):
def finalize_options(self):
_download_qhull()
self.distribution.ext_modules[:] = [
ext
for package in good_packages
Expand Down
50 changes: 35 additions & 15 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def get_extensions(self):
])
add_numpy_flags(ext)
add_libagg_flags_and_sources(ext)
FreeType().add_flags(ext)
FreeType.add_flags(ext)
yield ext
# c_internal_utils
ext = Extension(
Expand Down Expand Up @@ -412,7 +412,7 @@ def get_extensions(self):
"src/mplutils.cpp",
"src/py_converters.cpp",
])
FreeType().add_flags(ext)
FreeType.add_flags(ext)
add_numpy_flags(ext)
add_libagg_flags(ext)
yield ext
Expand Down Expand Up @@ -441,7 +441,7 @@ def get_extensions(self):
"matplotlib._qhull", ["src/qhull_wrap.c"],
define_macros=[("MPL_DEVNULL", os.devnull)])
add_numpy_flags(ext)
add_qhull_flags(ext)
Qhull.add_flags(ext)
yield ext
# tkagg
ext = Extension(
Expand Down Expand Up @@ -550,17 +550,6 @@ def add_libagg_flags_and_sources(ext):
os.path.join("extern", "agg24-svn", "src", x) for x in agg_sources)


def add_qhull_flags(ext):
if options.get("system_qhull"):
ext.libraries.append("qhull")
else:
qhull_path = Path(f'build/qhull-{LOCAL_QHULL_VERSION}/src')
ext.include_dirs.insert(0, str(qhull_path))
ext.sources.extend(map(str, sorted(qhull_path.glob('libqhull_r/*.c'))))
if sysconfig.get_config_var("LIBM") == "-lm":
ext.libraries.extend("m")


# First compile checkdep_freetype2.c, which aborts the compilation either
# with "foo.h: No such file or directory" if the header is not found, or an
# appropriate error message if the header indicates a too-old version.
Expand All @@ -569,7 +558,8 @@ def add_qhull_flags(ext):
class FreeType(SetupPackage):
name = "freetype"

def add_flags(self, ext):
@classmethod
def add_flags(cls, ext):
ext.sources.insert(0, 'src/checkdep_freetype2.c')
if options.get('system_freetype'):
pkg_config_setup_extension(
Expand Down Expand Up @@ -686,6 +676,36 @@ def do_custom_build(self, env):
shutil.copy2(lib_path, src_path / "objs/.libs/libfreetype.lib")


class Qhull(SetupPackage):
name = "qhull"
_extensions_to_update = []

@classmethod
def add_flags(cls, ext):
if options.get("system_qhull"):
ext.libraries.append("qhull_r")
else:
cls._extensions_to_update.append(ext)

def do_custom_build(self, env):
if options.get('system_qhull'):
return

toplevel = get_and_extract_tarball(
urls=["http://www.qhull.org/download/qhull-2020-src-8.0.2.tgz"],
sha="b5c2d7eb833278881b952c8a52d20179eab87766b00b865000469a45c1838b7e",
dirname=f"qhull-{LOCAL_QHULL_VERSION}",
)
shutil.copyfile(toplevel / "COPYING.txt", "LICENSE/LICENSE_QHULL")

for ext in self._extensions_to_update:
qhull_path = Path(f'build/qhull-{LOCAL_QHULL_VERSION}/src')
ext.include_dirs.insert(0, str(qhull_path))
ext.sources.extend(map(str, sorted(qhull_path.glob('libqhull_r/*.c'))))
if sysconfig.get_config_var("LIBM") == "-lm":
ext.libraries.extend("m")


class BackendMacOSX(OptionalPackage):
config_category = 'gui_support'
name = 'macosx'
Expand Down