diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2020-08-02 09:47:47 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-02 09:47:47 -0400 |
commit | 51b75e95de717a7d37bd1915a104a9e830fe5651 (patch) | |
tree | 76c7bf9f09dbcd9f78ff34e9c01c111d00e952f5 | |
parent | 30de1af5460998284435dc8ec63dc259f1ef96de (diff) | |
parent | 616e129944d87e578fe02146f07f72603a4c0124 (diff) | |
download | external_python_setuptools-51b75e95de717a7d37bd1915a104a9e830fe5651.tar.gz external_python_setuptools-51b75e95de717a7d37bd1915a104a9e830fe5651.tar.bz2 external_python_setuptools-51b75e95de717a7d37bd1915a104a9e830fe5651.zip |
Merge pull request #8 from pypa/bugfix/tests-for-msvc-spawn
Bugfix/tests for msvc spawn
-rw-r--r-- | distutils/_msvccompiler.py | 6 | ||||
-rw-r--r-- | distutils/ccompiler.py | 4 | ||||
-rw-r--r-- | distutils/tests/test_msvccompiler.py | 37 |
3 files changed, 43 insertions, 4 deletions
diff --git a/distutils/_msvccompiler.py b/distutils/_msvccompiler.py index 0e98692e..2d56ee0a 100644 --- a/distutils/_msvccompiler.py +++ b/distutils/_msvccompiler.py @@ -15,7 +15,9 @@ for older versions in distutils.msvc9compiler and distutils.msvccompiler. import os import subprocess -import winreg +import contextlib +with contextlib.suppress(ImportError): + import winreg from distutils.errors import DistutilsExecError, DistutilsPlatformError, \ CompileError, LibError, LinkError @@ -501,7 +503,7 @@ class MSVCCompiler(CCompiler) : log.debug("skipping %s (up-to-date)", output_filename) def spawn(self, cmd): - env = dict(os.environ, path=self._paths) + env = dict(os.environ, PATH=self._paths) return super().spawn(cmd, env=env) # -- Miscellaneous methods ----------------------------------------- diff --git a/distutils/ccompiler.py b/distutils/ccompiler.py index b5ef143e..57bb94e8 100644 --- a/distutils/ccompiler.py +++ b/distutils/ccompiler.py @@ -906,8 +906,8 @@ int main (int argc, char **argv) { def execute(self, func, args, msg=None, level=1): execute(func, args, msg, self.dry_run) - def spawn(self, cmd): - spawn(cmd, dry_run=self.dry_run) + def spawn(self, cmd, **kwargs): + spawn(cmd, dry_run=self.dry_run, **kwargs) def move_file(self, src, dst): return move_file(src, dst, dry_run=self.dry_run) diff --git a/distutils/tests/test_msvccompiler.py b/distutils/tests/test_msvccompiler.py index b518d6a7..88d912b1 100644 --- a/distutils/tests/test_msvccompiler.py +++ b/distutils/tests/test_msvccompiler.py @@ -2,6 +2,7 @@ import sys import unittest import os +import threading from distutils.errors import DistutilsPlatformError from distutils.tests import support @@ -74,6 +75,42 @@ class msvccompilerTestCase(support.TempdirManager, else: raise unittest.SkipTest("VS 2015 is not installed") + +class CheckThread(threading.Thread): + exc_info = None + + def run(self): + try: + super().run() + except Exception: + self.exc_info = sys.exc_info() + + def __bool__(self): + return not self.exc_info + + +class TestSpawn(unittest.TestCase): + def test_concurrent_safe(self): + """ + Concurrent calls to spawn should have consistent results. + """ + import distutils._msvccompiler as _msvccompiler + compiler = _msvccompiler.MSVCCompiler() + compiler._paths = "expected" + inner_cmd = 'import os; assert os.environ["PATH"] == "expected"' + command = ['python', '-c', inner_cmd] + + threads = [ + CheckThread(target=compiler.spawn, args=[command]) + for n in range(100) + ] + for thread in threads: + thread.start() + for thread in threads: + thread.join() + assert all(threads) + + def test_suite(): return unittest.makeSuite(msvccompilerTestCase) |