Skip to content

Commit 2dacb1c

Browse files
authored
Merge pull request #19329 from QuLogic/fix-system-qhull
Fix building against system qhull
2 parents 76f355b + a62201a commit 2dacb1c

File tree

2 files changed

+37
-27
lines changed

2 files changed

+37
-27
lines changed

setup.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
from distutils.dist import Distribution
4848

4949
import setupext
50-
from setupext import (
51-
get_and_extract_tarball, print_raw, print_status, LOCAL_QHULL_VERSION)
50+
from setupext import print_raw, print_status
5251

5352
# Get the version from versioneer
5453
import versioneer
@@ -61,6 +60,7 @@
6160
setupext.Python(),
6261
setupext.Platform(),
6362
setupext.FreeType(),
63+
setupext.Qhull(),
6464
setupext.SampleData(),
6565
setupext.Tests(),
6666
setupext.BackendMacOSX(),
@@ -86,18 +86,8 @@ def __init__(self, dist):
8686
"'python setup.py test'. Please run 'pytest'.")
8787

8888

89-
def _download_qhull():
90-
toplevel = get_and_extract_tarball(
91-
urls=["http://www.qhull.org/download/qhull-2020-src-8.0.2.tgz"],
92-
sha="b5c2d7eb833278881b952c8a52d20179eab87766b00b865000469a45c1838b7e",
93-
dirname=f"qhull-{LOCAL_QHULL_VERSION}",
94-
)
95-
shutil.copyfile(toplevel / "COPYING.txt", "LICENSE/LICENSE_QHULL")
96-
97-
9889
class BuildExtraLibraries(BuildExtCommand):
9990
def finalize_options(self):
100-
_download_qhull()
10191
self.distribution.ext_modules[:] = [
10292
ext
10393
for package in good_packages

setupext.py

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def get_extensions(self):
384384
])
385385
add_numpy_flags(ext)
386386
add_libagg_flags_and_sources(ext)
387-
FreeType().add_flags(ext)
387+
FreeType.add_flags(ext)
388388
yield ext
389389
# c_internal_utils
390390
ext = Extension(
@@ -412,7 +412,7 @@ def get_extensions(self):
412412
"src/mplutils.cpp",
413413
"src/py_converters.cpp",
414414
])
415-
FreeType().add_flags(ext)
415+
FreeType.add_flags(ext)
416416
add_numpy_flags(ext)
417417
add_libagg_flags(ext)
418418
yield ext
@@ -441,7 +441,7 @@ def get_extensions(self):
441441
"matplotlib._qhull", ["src/qhull_wrap.c"],
442442
define_macros=[("MPL_DEVNULL", os.devnull)])
443443
add_numpy_flags(ext)
444-
add_qhull_flags(ext)
444+
Qhull.add_flags(ext)
445445
yield ext
446446
# tkagg
447447
ext = Extension(
@@ -550,17 +550,6 @@ def add_libagg_flags_and_sources(ext):
550550
os.path.join("extern", "agg24-svn", "src", x) for x in agg_sources)
551551

552552

553-
def add_qhull_flags(ext):
554-
if options.get("system_qhull"):
555-
ext.libraries.append("qhull")
556-
else:
557-
qhull_path = Path(f'build/qhull-{LOCAL_QHULL_VERSION}/src')
558-
ext.include_dirs.insert(0, str(qhull_path))
559-
ext.sources.extend(map(str, sorted(qhull_path.glob('libqhull_r/*.c'))))
560-
if sysconfig.get_config_var("LIBM") == "-lm":
561-
ext.libraries.extend("m")
562-
563-
564553
# First compile checkdep_freetype2.c, which aborts the compilation either
565554
# with "foo.h: No such file or directory" if the header is not found, or an
566555
# appropriate error message if the header indicates a too-old version.
@@ -569,7 +558,8 @@ def add_qhull_flags(ext):
569558
class FreeType(SetupPackage):
570559
name = "freetype"
571560

572-
def add_flags(self, ext):
561+
@classmethod
562+
def add_flags(cls, ext):
573563
ext.sources.insert(0, 'src/checkdep_freetype2.c')
574564
if options.get('system_freetype'):
575565
pkg_config_setup_extension(
@@ -686,6 +676,36 @@ def do_custom_build(self, env):
686676
shutil.copy2(lib_path, src_path / "objs/.libs/libfreetype.lib")
687677

688678

679+
class Qhull(SetupPackage):
680+
name = "qhull"
681+
_extensions_to_update = []
682+
683+
@classmethod
684+
def add_flags(cls, ext):
685+
if options.get("system_qhull"):
686+
ext.libraries.append("qhull_r")
687+
else:
688+
cls._extensions_to_update.append(ext)
689+
690+
def do_custom_build(self, env):
691+
if options.get('system_qhull'):
692+
return
693+
694+
toplevel = get_and_extract_tarball(
695+
urls=["http://www.qhull.org/download/qhull-2020-src-8.0.2.tgz"],
696+
sha="b5c2d7eb833278881b952c8a52d20179eab87766b00b865000469a45c1838b7e",
697+
dirname=f"qhull-{LOCAL_QHULL_VERSION}",
698+
)
699+
shutil.copyfile(toplevel / "COPYING.txt", "LICENSE/LICENSE_QHULL")
700+
701+
for ext in self._extensions_to_update:
702+
qhull_path = Path(f'build/qhull-{LOCAL_QHULL_VERSION}/src')
703+
ext.include_dirs.insert(0, str(qhull_path))
704+
ext.sources.extend(map(str, sorted(qhull_path.glob('libqhull_r/*.c'))))
705+
if sysconfig.get_config_var("LIBM") == "-lm":
706+
ext.libraries.extend("m")
707+
708+
689709
class BackendMacOSX(OptionalPackage):
690710
config_category = 'gui_support'
691711
name = 'macosx'

0 commit comments

Comments
 (0)