Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions distutils/command/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,14 @@ def finalize_options(self) -> None: # noqa: C901
# specified by the 'define' option will be set to '1'. Multiple
# symbols can be separated with commas.

if self.define:
if isinstance(self.define, str):
defines = self.define.split(',')
self.define = [(symbol, '1') for symbol in defines]

# The option for macros to undefine is also a string from the
# option parsing, but has to be a list. Multiple symbols can also
# be separated with commas here.
if self.undef:
if isinstance(self.undef, str):
self.undef = self.undef.split(',')

if self.swig_opts is None:
Expand Down
10 changes: 10 additions & 0 deletions distutils/tests/test_build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,16 @@ def test_finalize_options(self):
cmd.finalize_options()
assert cmd.swig_opts == ['1', '2']

# Check that calling build_ext.finalize_options after
# define or undef attributes were already set to their final type doesn't raise
cmd = self.build_ext(dist)
cmd.define = [("MY_MACRO", "1")]
cmd.undef = ["EVIL_MACRO"]
cmd.finalize_options()

assert cmd.define == [("MY_MACRO", "1")]
assert cmd.undef == ["EVIL_MACRO"]

def test_check_extensions_list(self):
dist = Distribution()
cmd = self.build_ext(dist)
Expand Down
2 changes: 2 additions & 0 deletions newsfragments/386.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed a bug where calling ``build_ext.finalize_options`` after ``define`` or
``undef`` attributes were already set would raise an exception.