Skip to content

Commit 472d8fb

Browse files
committed
ENH: improve resiliency in distutils.build_ext.finalize_options
1 parent 9cc2f5c commit 472d8fb

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

newsfragments/5083.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed a bug where calling ``build_ext.finalize_options`` more than once would
2+
raise an exception.

setuptools/_distutils/command/build_ext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def finalize_options(self) -> None: # noqa: C901
276276
if self.undef:
277277
self.undef = self.undef.split(',')
278278

279-
if self.swig_opts is None:
279+
if not self.swig_opts:
280280
self.swig_opts = []
281281
else:
282282
self.swig_opts = self.swig_opts.split(' ')

setuptools/tests/test_build_ext.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,17 @@ def C(file):
178178
assert example_stub.startswith(f"{build_lib}/mypkg/__pycache__/ext1")
179179
assert example_stub.endswith(".pyc")
180180

181+
def test_finalize_options_multiple_call(self):
182+
"""
183+
Regression test. Check that calling build_ext.finalize_options
184+
more than once doesn't raise an exception.
185+
"""
186+
extension = Extension('spam.eggs', ['eggs.c'], py_limited_api=True)
187+
dist = Distribution(dict(ext_modules=[extension]))
188+
cmd = build_ext(dist)
189+
cmd.finalize_options()
190+
cmd.finalize_options()
191+
181192

182193
class TestBuildExtInplace:
183194
def get_build_ext_cmd(self, optional: bool, **opts) -> build_ext:

0 commit comments

Comments
 (0)