Skip to content

Commit 4595b98

Browse files
committed
BUG: fix a bug where calling distutils.build_ext.finalize_options more than once would raise an exception
1 parent 9cc2f5c commit 4595b98

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,10 @@ 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:
280-
self.swig_opts = []
281-
else:
279+
if isinstance(self.swig_opts, str):
282280
self.swig_opts = self.swig_opts.split(' ')
281+
elif self.swig_opts is None:
282+
self.swig_opts = []
283283

284284
# Finally add the user include and library directories if requested
285285
if self.user:

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'])
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)