MCPcopy
hub / github.com/quantopian/zipline / LazyBuildExtCommandClass

Class LazyBuildExtCommandClass

setup.py:36–78  ·  view source on GitHub ↗

Lazy command class that defers operations requiring Cython and numpy until they've actually been downloaded and installed by setup_requires.

Source from the content-addressed store, hash-verified

34
35
36class LazyBuildExtCommandClass(dict):
37 """
38 Lazy command class that defers operations requiring Cython and numpy until
39 they've actually been downloaded and installed by setup_requires.
40 """
41 def __contains__(self, key):
42 return (
43 key == 'build_ext'
44 or super(LazyBuildExtCommandClass, self).__contains__(key)
45 )
46
47 def __setitem__(self, key, value):
48 if key == 'build_ext':
49 raise AssertionError("build_ext overridden!")
50 super(LazyBuildExtCommandClass, self).__setitem__(key, value)
51
52 def __getitem__(self, key):
53 if key != 'build_ext':
54 return super(LazyBuildExtCommandClass, self).__getitem__(key)
55
56 from Cython.Distutils import build_ext as cython_build_ext
57 import numpy
58
59 # Cython_build_ext isn't a new-style class in Py2.
60 class build_ext(cython_build_ext, object):
61 """
62 Custom build_ext command that lazily adds numpy's include_dir to
63 extensions.
64 """
65 def build_extensions(self):
66 """
67 Lazily append numpy's include directory to Extension includes.
68
69 This is done here rather than at module scope because setup.py
70 may be run before numpy has been installed, in which case
71 importing numpy and calling `numpy.get_include()` will fail.
72 """
73 numpy_incl = numpy.get_include()
74 for ext in self.extensions:
75 ext.include_dirs.append(numpy_incl)
76
77 super(build_ext, self).build_extensions()
78 return build_ext
79
80
81def window_specialization(typename):

Callers 1

setup.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected