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
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def initialize_options(self):
# same command object, so make sure not to override previously
# set options.
if getattr(self, '_initialized', False):
self.compiler = None
return

super().initialize_options()
Expand Down
29 changes: 29 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import runpy
import unittest
from pathlib import Path
from unittest import mock

from setuptools import Distribution, Extension
from setuptools._distutils.ccompiler import new_compiler


class TestBuildExt(unittest.TestCase):
def test_reinitialized_command_uses_fresh_compiler(self):
setup_py = Path(__file__).parents[1] / "setup.py"
with mock.patch("setuptools.setup") as setup:
runpy.run_path(str(setup_py))

build_ext = setup.call_args.kwargs["cmdclass"]["build_ext"]
distribution = Distribution({
"cmdclass": {"build_ext": build_ext},
"ext_modules": [Extension("test", ["test.c"])],
})
command = distribution.get_command_obj("build_ext")
command.ensure_finalized()
command.compiler = new_compiler()

distribution.reinitialize_command("build_ext")
command.build_extensions = mock.Mock()
command.run()

command.build_extensions.assert_called_once_with()