1
+ from distutils .command .install import install
2
+ from distutils .dist import Distribution as DistDistribution
1
3
from setuptools .dist import Distribution
2
4
3
5
@@ -18,10 +20,33 @@ def get_command_class(self, command):
18
20
Distribution .get_command_class = get_command_class
19
21
20
22
# use custom has_ext_modules
21
- Distribution .orig_has_ext_modules = Distribution .has_ext_modules
23
+ DistDistribution .orig_has_ext_modules = DistDistribution .has_ext_modules
22
24
23
25
def has_ext_modules (self ):
24
26
return (self .ext_modules and len (self .ext_modules ) > 0 or
25
27
self .rust_extensions and len (self .rust_extensions ) > 0 )
26
28
27
- Distribution .has_ext_modules = has_ext_modules
29
+ DistDistribution .has_ext_modules = has_ext_modules
30
+
31
+ # this is required because, install directly access distribution's
32
+ # ext_modules attr to check if dist has ext modules
33
+ install .orig_finalize_options = install .finalize_options
34
+
35
+ def finalize_options (self ):
36
+ ext_modules = self .distribution .ext_modules
37
+
38
+ # all ext modules
39
+ mods = []
40
+ if self .distribution .ext_modules :
41
+ mods .extend (self .distribution .ext_modules )
42
+ if self .distribution .rust_extensions :
43
+ mods .extend (self .distribution .rust_extensions )
44
+
45
+ self .distribution .ext_modules = mods
46
+
47
+ self .orig_finalize_options ()
48
+
49
+ # restore ext_modules
50
+ self .distribution .ext_modules = ext_modules
51
+
52
+ install .finalize_options = finalize_options
0 commit comments