@@ -319,7 +319,7 @@ def make_extension(name, files, *args, **kwargs):
319
319
Any additional arguments are passed to the
320
320
`distutils.core.Extension` constructor.
321
321
"""
322
- ext = DelayedExtension (name , files , * args , ** kwargs )
322
+ ext = Extension (name , files , * args , ** kwargs )
323
323
for dir in get_base_dirs ():
324
324
include_dir = os .path .join (dir , 'include' )
325
325
if os .path .exists (include_dir ):
@@ -329,7 +329,6 @@ def make_extension(name, files, *args, **kwargs):
329
329
if os .path .exists (lib_dir ):
330
330
ext .library_dirs .append (lib_dir )
331
331
ext .include_dirs .append ('.' )
332
-
333
332
return ext
334
333
335
334
@@ -789,79 +788,12 @@ def get_package_data(self):
789
788
}
790
789
791
790
792
- class DelayedExtension (Extension , object ):
793
- """
794
- A distutils Extension subclass where some of its members
795
- may have delayed computation until reaching the build phase.
796
-
797
- This is so we can, for example, get the Numpy include dirs
798
- after pip has installed Numpy for us if it wasn't already
799
- on the system.
800
- """
801
- def __init__ (self , * args , ** kwargs ):
802
- super ().__init__ (* args , ** kwargs )
803
- self ._finalized = False
804
- self ._hooks = {}
805
-
806
- def add_hook (self , member , func ):
807
- """
808
- Add a hook to dynamically compute a member.
809
-
810
- Parameters
811
- ----------
812
- member : string
813
- The name of the member
814
-
815
- func : callable
816
- The function to call to get dynamically-computed values
817
- for the member.
818
- """
819
- self ._hooks [member ] = func
820
-
821
- def finalize (self ):
822
- self ._finalized = True
823
-
824
- class DelayedMember (property ):
825
- def __init__ (self , name ):
826
- self ._name = name
827
-
828
- def __get__ (self , obj , objtype = None ):
829
- result = getattr (obj , '_' + self ._name , [])
830
-
831
- if obj ._finalized :
832
- if self ._name in obj ._hooks :
833
- result = obj ._hooks [self ._name ]() + result
834
-
835
- return result
836
-
837
- def __set__ (self , obj , value ):
838
- setattr (obj , '_' + self ._name , value )
839
-
840
- include_dirs = DelayedMember ('include_dirs' )
841
-
842
-
843
791
class Numpy (SetupPackage ):
844
792
name = "numpy"
845
793
846
- @staticmethod
847
- def include_dirs_hook ():
848
- if hasattr (builtins , '__NUMPY_SETUP__' ):
849
- del builtins .__NUMPY_SETUP__
850
- import numpy
851
- importlib .reload (numpy )
852
-
853
- ext = Extension ('test' , [])
854
- ext .include_dirs .append (numpy .get_include ())
855
- if not has_include_file (
856
- ext .include_dirs , os .path .join ("numpy" , "arrayobject.h" )):
857
- _log .warning (
858
- "The C headers for numpy could not be found. "
859
- "You may need to install the development package" )
860
-
861
- return [numpy .get_include ()]
862
-
863
794
def add_flags (self , ext ):
864
- ext .add_hook ('include_dirs' , self .include_dirs_hook )
795
+ import numpy as np
796
+ ext .include_dirs .append (np .get_include ())
865
797
ext .define_macros .extend ([
866
798
# Ensure that PY_ARRAY_UNIQUE_SYMBOL is uniquely defined for each
867
799
# extension.
0 commit comments