Skip to content

Commit a686ad9

Browse files
committed
fix compatibility with older versions of setuptools
1 parent 17c7f81 commit a686ad9

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@
55
/build
66
/*.egg-info
77
Cargo.lock
8+
/example/build/
9+
/example/dist/
810
/example/extensions/target/
911
/example/*.egg-info

CHANGES.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
CHANGES
22
=======
33

4-
0.4 (2017-xx-xx)
5-
----------------
4+
0.3.1 (2017-03-09)
5+
------------------
66

7+
- Fix compatibility with some old versions of setuptools
78

89

910
0.3 (2017-03-09)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup
22

3-
version = '0.4'
3+
version = '0.3.1'
44

55

66
setup(

setuptools_rust/patch.py

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
Distribution.rust_extensions = ()
1414

1515

16+
orig_has_ext_modules = Distribution.has_ext_modules
17+
1618
def has_ext_modules(self):
1719
return (self.ext_modules and len(self.ext_modules) > 0 or
1820
self.rust_extensions and len(self.rust_extensions) > 0)
@@ -45,14 +47,46 @@ def monkey_run_command(self, cmd):
4547
develop.develop.run_command = monkey_run_command
4648

4749

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"
5552

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())
5658

57-
if has_py36compat:
5859
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

Comments
 (0)