Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
0a665b2a
Commit
0a665b2a
authored
Sep 05, 2020
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Plain Diff
Merge
https://github.com/pypa/distutils
into master
parents
03d36b9e
2888d3c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
1 deletion
+45
-1
setuptools/_distutils/_msvccompiler.py
setuptools/_distutils/_msvccompiler.py
+25
-1
setuptools/_distutils/tests/test_msvccompiler.py
setuptools/_distutils/tests/test_msvccompiler.py
+20
-0
No files found.
setuptools/_distutils/_msvccompiler.py
View file @
0a665b2a
...
...
@@ -16,6 +16,8 @@ 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
...
...
@@ -504,7 +506,29 @@ 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
warnings
.
warn
(
"Fallback spawn triggered. Please update distutils monkeypatch."
)
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
...
...
setuptools/_distutils/tests/test_msvccompiler.py
View file @
0a665b2a
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment