From 837fa5cd58e927953183e750d0c429a5e871865f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 1 Sep 2020 21:35:43 -0400 Subject: No longer try to track package changes separately. --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index e619264d..4d9dea51 100644 --- a/README.rst +++ b/README.rst @@ -37,4 +37,4 @@ From the CPython repo, cherry-pick the changes from this project. To Setuptools ------------- -This project also maintains a `clean branch `_ to capture only the code changes to distutils, excluding the ancillary details like packaging and this document. +Simply merge the changes directly into setuptools' repo. -- cgit v1.2.1 From 37fa0e7531fbd240131d498f43436aafd4393149 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 5 Sep 2020 10:45:35 -0400 Subject: Add test capturing failed expectation. Ref pypa/distutils#15. --- distutils/tests/test_msvccompiler.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/distutils/tests/test_msvccompiler.py b/distutils/tests/test_msvccompiler.py index 88d912b1..46a51cd0 100644 --- a/distutils/tests/test_msvccompiler.py +++ b/distutils/tests/test_msvccompiler.py @@ -110,6 +110,26 @@ class TestSpawn(unittest.TestCase): thread.join() assert all(threads) + def test_concurrent_safe_fallback(self): + """ + If CCompiler.spawn has been monkey-patched without support + for an env, it should still execute. + """ + import distutils._msvccompiler as _msvccompiler + from distutils import ccompiler + compiler = _msvccompiler.MSVCCompiler() + compiler._paths = "expected" + + def CCompiler_spawn(self, cmd): + "A spawn without an env argument." + assert os.environ["PATH"] == "expected" + + with unittest.mock.patch.object( + ccompiler.CCompiler, 'spawn', CCompiler_spawn): + compiler.spawn(["n/a"]) + + assert os.environ.get("PATH") != "expected" + def test_suite(): return unittest.makeSuite(msvccompilerTestCase) -- cgit v1.2.1 From 6e92cdabaff71ab2bab3300763101fb8f84c367f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 5 Sep 2020 10:58:55 -0400 Subject: Add fallback for the situation where distutils.ccompiler.CCompiler.spawn has been patched. Fixes pypa/distutils#15. --- distutils/_msvccompiler.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/distutils/_msvccompiler.py b/distutils/_msvccompiler.py index 2d56ee0a..f7efd4eb 100644 --- a/distutils/_msvccompiler.py +++ b/distutils/_msvccompiler.py @@ -16,6 +16,7 @@ for older versions in distutils.msvc9compiler and distutils.msvccompiler. import os import subprocess import contextlib +import unittest.mock with contextlib.suppress(ImportError): import winreg @@ -504,7 +505,27 @@ class MSVCCompiler(CCompiler) : def spawn(self, cmd): env = dict(os.environ, PATH=self._paths) - return super().spawn(cmd, env=env) + with self._fallback_spawn(cmd, env) as fallback: + return super().spawn(cmd, env=env) + return fallback.value + + @contextlib.contextmanager + def _fallback_spawn(self, cmd, env): + """ + Discovered in pypa/distutils#15, some tools monkeypatch the compiler, + so the 'env' kwarg causes a TypeError. Detect this condition and + restore the legacy, unsafe behavior. + """ + bag = type('Bag', (), {})() + try: + yield bag + except TypeError as exc: + if "unexpected keyword argument 'env'" not in str(exc): + raise + else: + return + with unittest.mock.patch('os.environ', env): + bag.value = super().spawn(cmd) # -- Miscellaneous methods ----------------------------------------- # These are all used by the 'gen_lib_options() function, in -- cgit v1.2.1 From 2888d3c08e1c34254f726bc331dc33d419e636dc Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 5 Sep 2020 11:03:35 -0400 Subject: Emit a warning when the fallback spawn was triggered. Ref pypa/distutils#15. --- distutils/_msvccompiler.py | 3 +++ pytest.ini | 1 + 2 files changed, 4 insertions(+) diff --git a/distutils/_msvccompiler.py b/distutils/_msvccompiler.py index f7efd4eb..e9af4cf5 100644 --- a/distutils/_msvccompiler.py +++ b/distutils/_msvccompiler.py @@ -16,6 +16,7 @@ for older versions in distutils.msvc9compiler and distutils.msvccompiler. import os import subprocess import contextlib +import warnings import unittest.mock with contextlib.suppress(ImportError): import winreg @@ -524,6 +525,8 @@ class MSVCCompiler(CCompiler) : raise else: return + warnings.warn( + "Fallback spawn triggered. Please update distutils monkeypatch.") with unittest.mock.patch('os.environ', env): bag.value = super().spawn(cmd) diff --git a/pytest.ini b/pytest.ini index b305356b..dba42e75 100644 --- a/pytest.ini +++ b/pytest.ini @@ -3,3 +3,4 @@ addopts=--doctest-modules filterwarnings= # acknowledge that TestDistribution isn't a test ignore:cannot collect test class 'TestDistribution' + ignore:Fallback spawn triggered -- cgit v1.2.1