|
13 | 13 | Distribution.rust_extensions = ()
|
14 | 14 |
|
15 | 15 |
|
| 16 | +orig_has_ext_modules = Distribution.has_ext_modules |
| 17 | + |
16 | 18 | def has_ext_modules(self):
|
17 | 19 | return (self.ext_modules and len(self.ext_modules) > 0 or
|
18 | 20 | self.rust_extensions and len(self.rust_extensions) > 0)
|
@@ -45,14 +47,46 @@ def monkey_run_command(self, cmd):
|
45 | 47 | develop.develop.run_command = monkey_run_command
|
46 | 48 |
|
47 | 49 |
|
48 |
| -# monkey patch "sdist_add_defaults" |
49 |
| - |
50 |
| -def _add_defaults_ext(self): |
51 |
| - if (self.distribution.ext_modules and |
52 |
| - len(self.distribution.ext_modules) > 0): |
53 |
| - build_ext = self.get_finalized_command('build_ext') |
54 |
| - self.filelist.extend(build_ext.get_source_files()) |
| 50 | +if has_py36compat: |
| 51 | + # monkey patch "sdist_add_defaults" |
55 | 52 |
|
| 53 | + def _add_defaults_ext(self): |
| 54 | + if (self.distribution.ext_modules and |
| 55 | + len(self.distribution.ext_modules) > 0): |
| 56 | + build_ext = self.get_finalized_command('build_ext') |
| 57 | + self.filelist.extend(build_ext.get_source_files()) |
56 | 58 |
|
57 |
| -if has_py36compat: |
58 | 59 | sdist_add_defaults._add_defaults_ext = _add_defaults_ext
|
| 60 | +else: |
| 61 | + from distutils.command.build_ext import build_ext |
| 62 | + from setuptools.command.bdist_egg import bdist_egg |
| 63 | + |
| 64 | + orig_get_source_files = build_ext.get_source_files |
| 65 | + |
| 66 | + def get_source_files(self): |
| 67 | + if self.extensions: |
| 68 | + return orig_get_source_files(self) |
| 69 | + else: |
| 70 | + return [] |
| 71 | + |
| 72 | + build_ext.get_source_files = get_source_files |
| 73 | + |
| 74 | + orig_get_ext_outputs = bdist_egg.get_ext_outputs |
| 75 | + |
| 76 | + def get_ext_outputs(self): |
| 77 | + Distribution.has_ext_modules = orig_has_ext_modules |
| 78 | + try: |
| 79 | + return orig_get_ext_outputs(self) |
| 80 | + finally: |
| 81 | + Distribution.has_ext_modules = has_ext_modules |
| 82 | + |
| 83 | + |
| 84 | + bdist_egg.get_ext_outputs = get_ext_outputs |
| 85 | + |
| 86 | + orig_run = bdist_egg.run |
| 87 | + |
| 88 | + def run(self): |
| 89 | + self.run_command("build_rust") |
| 90 | + orig_run(self) |
| 91 | + |
| 92 | + bdist_egg.run = run |
0 commit comments