@@ -231,7 +231,7 @@ def make_extension(name, files, *args, **kwargs):
231
231
Any additional arguments are passed to the
232
232
`distutils.core.Extension` constructor.
233
233
"""
234
- ext = DelayedExtension (name , files , * args , ** kwargs )
234
+ ext = Extension (name , files , * args , ** kwargs )
235
235
for dir in get_base_dirs ():
236
236
include_dir = os .path .join (dir , 'include' )
237
237
if os .path .exists (include_dir ):
@@ -241,7 +241,6 @@ def make_extension(name, files, *args, **kwargs):
241
241
if os .path .exists (lib_dir ):
242
242
ext .library_dirs .append (lib_dir )
243
243
ext .include_dirs .append ('.' )
244
-
245
244
return ext
246
245
247
246
@@ -800,77 +799,9 @@ def get_namespace_packages(self):
800
799
return ['mpl_toolkits' ]
801
800
802
801
803
- class DelayedExtension (Extension , object ):
804
- """
805
- A distutils Extension subclass where some of its members
806
- may have delayed computation until reaching the build phase.
807
-
808
- This is so we can, for example, get the Numpy include dirs
809
- after pip has installed Numpy for us if it wasn't already
810
- on the system.
811
- """
812
- def __init__ (self , * args , ** kwargs ):
813
- super ().__init__ (* args , ** kwargs )
814
- self ._finalized = False
815
- self ._hooks = {}
816
-
817
- def add_hook (self , member , func ):
818
- """
819
- Add a hook to dynamically compute a member.
820
-
821
- Parameters
822
- ----------
823
- member : string
824
- The name of the member
825
-
826
- func : callable
827
- The function to call to get dynamically-computed values
828
- for the member.
829
- """
830
- self ._hooks [member ] = func
831
-
832
- def finalize (self ):
833
- self ._finalized = True
834
-
835
- class DelayedMember (property ):
836
- def __init__ (self , name ):
837
- self ._name = name
838
-
839
- def __get__ (self , obj , objtype = None ):
840
- result = getattr (obj , '_' + self ._name , [])
841
-
842
- if obj ._finalized :
843
- if self ._name in obj ._hooks :
844
- result = obj ._hooks [self ._name ]() + result
845
-
846
- return result
847
-
848
- def __set__ (self , obj , value ):
849
- setattr (obj , '_' + self ._name , value )
850
-
851
- include_dirs = DelayedMember ('include_dirs' )
852
-
853
-
854
802
class Numpy (SetupPackage ):
855
803
name = "numpy"
856
804
857
- @staticmethod
858
- def include_dirs_hook ():
859
- if hasattr (builtins , '__NUMPY_SETUP__' ):
860
- del builtins .__NUMPY_SETUP__
861
- import numpy
862
- importlib .reload (numpy )
863
-
864
- ext = Extension ('test' , [])
865
- ext .include_dirs .append (numpy .get_include ())
866
- if not has_include_file (
867
- ext .include_dirs , os .path .join ("numpy" , "arrayobject.h" )):
868
- warnings .warn (
869
- "The C headers for numpy could not be found. "
870
- "You may need to install the development package" )
871
-
872
- return [numpy .get_include ()]
873
-
874
805
def check (self ):
875
806
min_version = extract_versions ()['__version__numpy__' ]
876
807
try :
@@ -886,16 +817,14 @@ def check(self):
886
817
return 'version %s' % numpy .__version__
887
818
888
819
def add_flags (self , ext ):
820
+ import numpy as np
821
+ ext .include_dirs .append (np .get_include ())
889
822
# Ensure that PY_ARRAY_UNIQUE_SYMBOL is uniquely defined for
890
823
# each extension
891
824
array_api_name = 'MPL_' + ext .name .replace ('.' , '_' ) + '_ARRAY_API'
892
-
893
825
ext .define_macros .append (('PY_ARRAY_UNIQUE_SYMBOL' , array_api_name ))
894
- ext .add_hook ('include_dirs' , self .include_dirs_hook )
895
-
896
826
ext .define_macros .append (('NPY_NO_DEPRECATED_API' ,
897
827
'NPY_1_7_API_VERSION' ))
898
-
899
828
# Allow NumPy's printf format specifiers in C++.
900
829
ext .define_macros .append (('__STDC_FORMAT_MACROS' , 1 ))
901
830
@@ -910,32 +839,23 @@ class LibAgg(SetupPackage):
910
839
name = 'libagg'
911
840
912
841
def check (self ):
913
- self .__class__ .found_external = True
914
- try :
915
- return self ._check_for_pkg_config (
916
- 'libagg' , 'agg2/agg_basics.h' , min_version = 'PATCH' )
917
- except CheckFailed as e :
918
- self .__class__ .found_external = False
919
- return str (e ) + ' Using local copy.'
842
+ return 'requires patched version; using local copy.'
920
843
921
844
def add_flags (self , ext , add_sources = True ):
922
- if self .found_external :
923
- pkg_config .setup_extension (ext , 'libagg' )
924
- else :
925
- ext .include_dirs .insert (0 , 'extern/agg24-svn/include' )
926
- if add_sources :
927
- agg_sources = [
928
- 'agg_bezier_arc.cpp' ,
929
- 'agg_curves.cpp' ,
930
- 'agg_image_filters.cpp' ,
931
- 'agg_trans_affine.cpp' ,
932
- 'agg_vcgen_contour.cpp' ,
933
- 'agg_vcgen_dash.cpp' ,
934
- 'agg_vcgen_stroke.cpp' ,
935
- 'agg_vpgen_segmentator.cpp'
936
- ]
937
- ext .sources .extend (
938
- os .path .join ('extern' , 'agg24-svn' , 'src' , x ) for x in agg_sources )
845
+ ext .include_dirs .insert (0 , 'extern/agg24-svn/include' )
846
+ if add_sources :
847
+ agg_sources = [
848
+ 'agg_bezier_arc.cpp' ,
849
+ 'agg_curves.cpp' ,
850
+ 'agg_image_filters.cpp' ,
851
+ 'agg_trans_affine.cpp' ,
852
+ 'agg_vcgen_contour.cpp' ,
853
+ 'agg_vcgen_dash.cpp' ,
854
+ 'agg_vcgen_stroke.cpp' ,
855
+ 'agg_vpgen_segmentator.cpp'
856
+ ]
857
+ ext .sources .extend (
858
+ os .path .join ('extern' , 'agg24-svn' , 'src' , x ) for x in agg_sources )
939
859
940
860
941
861
class FreeType (SetupPackage ):
@@ -1211,7 +1131,14 @@ def get_extension(self):
1211
1131
pkg_config .setup_extension (
1212
1132
ext , 'libpng' , default_libraries = ['png' , 'z' ],
1213
1133
alt_exec = 'libpng-config --ldflags' )
1214
- Numpy ().add_flags (ext )
1134
+ # We call this twice: once early, to check whether png exists (from
1135
+ # _check_for_pkg_config), and once late, to build the real extension.
1136
+ # Only at the second time is numpy guaranteed to be installed, so don't
1137
+ # error out if it isn't the first time.
1138
+ try :
1139
+ Numpy ().add_flags (ext )
1140
+ except ImportError :
1141
+ pass
1215
1142
return ext
1216
1143
1217
1144
@@ -1224,7 +1151,6 @@ def check(self):
1224
1151
return self ._check_for_pkg_config (
1225
1152
'libqhull' , 'libqhull/qhull_a.h' , min_version = '2015.2' )
1226
1153
except CheckFailed as e :
1227
- self .__class__ .found_pkgconfig = False
1228
1154
self .__class__ .found_external = False
1229
1155
return str (e ) + ' Using local copy.'
1230
1156
0 commit comments