Skip to content

Commit ff354d4

Browse files
committed
BUG: fix a bug where calling distutils.build_ext.finalize_options more than once would raise an exception
1 parent 603b94e commit ff354d4

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

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:

distutils/tests/test_build_ext.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,12 @@ def test_finalize_options(self):
320320
cmd.finalize_options()
321321
assert cmd.swig_opts == ['1', '2']
322322

323+
# make sure finalize_options() can be called more than once
324+
# without raising an exception
325+
cmd = self.build_ext(dist)
326+
cmd.finalize_options()
327+
cmd.finalize_options()
328+
323329
def test_check_extensions_list(self):
324330
dist = Distribution()
325331
cmd = self.build_ext(dist)

newsfragments/385.bugfix.rst

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

0 commit comments

Comments
 (0)