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
3c5cf653
Commit
3c5cf653
authored
Sep 04, 2016
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move msvc patch logic into monkey module.
parent
6a74dc95
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
70 deletions
+79
-70
setuptools/monkey.py
setuptools/monkey.py
+56
-3
setuptools/msvc.py
setuptools/msvc.py
+23
-67
No files found.
setuptools/monkey.py
View file @
3c5cf653
...
...
@@ -4,6 +4,7 @@ Monkey patching of distutils.
import
sys
import
distutils.filelist
import
platform
import
setuptools
...
...
@@ -74,9 +75,7 @@ def patch_all():
setuptools
.
extension
.
Extension
)
# patch MSVC
__import__
(
'setuptools.msvc'
)
setuptools
.
msvc
.
patch_for_specialized_compiler
()
patch_for_msvc_specialized_compiler
()
def
_patch_distribution_metadata_write_pkg_file
():
...
...
@@ -99,3 +98,57 @@ def _patch_distribution_metadata_write_pkg_info():
distutils
.
dist
.
DistributionMetadata
.
write_pkg_info
=
(
setuptools
.
dist
.
write_pkg_info
)
unpatched
=
dict
()
def
patch_for_msvc_specialized_compiler
():
"""
Patch functions in distutils to use standalone Microsoft Visual C++
compilers.
"""
try
:
# Distutil file for MSVC++ 9.0 and upper (Python 2.7 to 3.4)
import
distutils.msvc9compiler
as
msvc9compiler
except
ImportError
:
pass
try
:
# Distutil file for MSVC++ 14.0 and upper (Python 3.5+)
import
distutils._msvccompiler
as
msvc14compiler
except
ImportError
:
pass
if
platform
.
system
()
!=
'Windows'
:
# Compilers only availables on Microsoft Windows
return
unpatched
=
__import__
(
'setuptools.msvc'
).
msvc
.
unpatched
if
unpatched
:
# Already patched
return
try
:
# Patch distutils.msvc9compiler
unpatched
[
'msvc9_find_vcvarsall'
]
=
msvc9compiler
.
find_vcvarsall
msvc9compiler
.
find_vcvarsall
=
msvc9_find_vcvarsall
unpatched
[
'msvc9_query_vcvarsall'
]
=
msvc9compiler
.
query_vcvarsall
msvc9compiler
.
query_vcvarsall
=
msvc9_query_vcvarsall
except
NameError
:
pass
try
:
# Patch distutils._msvccompiler._get_vc_env
unpatched
[
'msvc14_get_vc_env'
]
=
msvc14compiler
.
_get_vc_env
msvc14compiler
.
_get_vc_env
=
msvc14_get_vc_env
except
NameError
:
pass
try
:
# Patch distutils._msvccompiler.gen_lib_options for Numpy
unpatched
[
'msvc14_gen_lib_options'
]
=
msvc14compiler
.
gen_lib_options
msvc14compiler
.
gen_lib_options
=
msvc14_gen_lib_options
except
NameError
:
pass
setuptools/msvc.py
View file @
3c5cf653
"""
This module adds improved support for Microsoft Visual C++ compilers.
Improved support for Microsoft Visual C++ compilers.
Known supported compilers:
--------------------------
Microsoft Visual C++ 9.0:
Microsoft Visual C++ Compiler for Python 2.7 (x86, amd64);
Microsoft Windows SDK 7.0 (x86, x64, ia64);
Microsoft Windows SDK 6.1 (x86, x64, ia64)
Microsoft Visual C++ 10.0:
Microsoft Windows SDK 7.1 (x86, x64, ia64)
Microsoft Visual C++ 14.0:
Microsoft Visual C++ Build Tools 2015 (x86, x64, arm)
"""
import
os
import
sys
import
platform
...
...
@@ -10,6 +24,8 @@ from distutils.version import StrictVersion
from
setuptools.extern.six.moves
import
filterfalse
from
.
import
monkey
if
platform
.
system
()
==
'Windows'
:
from
setuptools.extern.six.moves
import
winreg
safe_env
=
os
.
environ
...
...
@@ -26,70 +42,10 @@ else:
safe_env
=
dict
()
try
:
# Distutil file for MSVC++ 9.0 and upper (Python 2.7 to 3.4)
import
distutils.msvc9compiler
as
msvc9compiler
from
distutils.msvc9compiler
import
Reg
except
ImportError
:
pass
try
:
# Distutil file for MSVC++ 14.0 and upper (Python 3.5+)
import
distutils._msvccompiler
as
msvc14compiler
except
ImportError
:
pass
unpatched
=
dict
()
def
patch_for_specialized_compiler
():
"""
Patch functions in distutils to use standalone Microsoft Visual C++
compilers.
Known supported compilers:
--------------------------
Microsoft Visual C++ 9.0:
Microsoft Visual C++ Compiler for Python 2.7 (x86, amd64);
Microsoft Windows SDK 7.0 (x86, x64, ia64);
Microsoft Windows SDK 6.1 (x86, x64, ia64)
Microsoft Visual C++ 10.0:
Microsoft Windows SDK 7.1 (x86, x64, ia64)
Microsoft Visual C++ 14.0:
Microsoft Visual C++ Build Tools 2015 (x86, x64, arm)
"""
if
platform
.
system
()
!=
'Windows'
:
# Compilers only availables on Microsoft Windows
return
if
unpatched
:
# Already patched
return
try
:
# Patch distutils.msvc9compiler
unpatched
[
'msvc9_find_vcvarsall'
]
=
msvc9compiler
.
find_vcvarsall
msvc9compiler
.
find_vcvarsall
=
msvc9_find_vcvarsall
unpatched
[
'msvc9_query_vcvarsall'
]
=
msvc9compiler
.
query_vcvarsall
msvc9compiler
.
query_vcvarsall
=
msvc9_query_vcvarsall
except
NameError
:
pass
try
:
# Patch distutils._msvccompiler._get_vc_env
unpatched
[
'msvc14_get_vc_env'
]
=
msvc14compiler
.
_get_vc_env
msvc14compiler
.
_get_vc_env
=
msvc14_get_vc_env
except
NameError
:
pass
try
:
# Patch distutils._msvccompiler.gen_lib_options for Numpy
unpatched
[
'msvc14_gen_lib_options'
]
=
msvc14compiler
.
gen_lib_options
msvc14compiler
.
gen_lib_options
=
msvc14_gen_lib_options
except
NameError
:
pass
def
msvc9_find_vcvarsall
(
version
):
"""
...
...
@@ -113,7 +69,6 @@ def msvc9_find_vcvarsall(version):
------
vcvarsall.bat path: str
"""
Reg
=
msvc9compiler
.
Reg
VC_BASE
=
r'Software\
%sMic
rosoft\
De
vDiv\
VCFo
rPython\
%
0.1f'
key
=
VC_BASE
%
(
''
,
version
)
try
:
...
...
@@ -132,7 +87,7 @@ def msvc9_find_vcvarsall(version):
if
os
.
path
.
isfile
(
vcvarsall
):
return
vcvarsall
return
unpatched
[
'msvc9_find_vcvarsall'
](
version
)
return
monkey
.
unpatched
[
'msvc9_find_vcvarsall'
](
version
)
def
msvc9_query_vcvarsall
(
ver
,
arch
=
'x86'
,
*
args
,
**
kwargs
):
...
...
@@ -165,7 +120,8 @@ def msvc9_query_vcvarsall(ver, arch='x86', *args, **kwargs):
"""
# Try to get environement from vcvarsall.bat (Classical way)
try
:
return
unpatched
[
'msvc9_query_vcvarsall'
](
ver
,
arch
,
*
args
,
**
kwargs
)
orig
=
monkey
.
unpatched
[
'msvc9_query_vcvarsall'
]
return
orig
(
ver
,
arch
,
*
args
,
**
kwargs
)
except
distutils
.
errors
.
DistutilsPlatformError
:
# Pass error if Vcvarsall.bat is missing
pass
...
...
@@ -204,7 +160,7 @@ def msvc14_get_vc_env(plat_spec):
"""
# Try to get environment from vcvarsall.bat (Classical way)
try
:
return
unpatched
[
'msvc14_get_vc_env'
](
plat_spec
)
return
monkey
.
unpatched
[
'msvc14_get_vc_env'
](
plat_spec
)
except
distutils
.
errors
.
DistutilsPlatformError
:
# Pass error Vcvarsall.bat is missing
pass
...
...
@@ -227,7 +183,7 @@ def msvc14_gen_lib_options(*args, **kwargs):
import
numpy
as
np
if
StrictVersion
(
np
.
__version__
)
<
StrictVersion
(
'1.11.2'
):
return
np
.
distutils
.
ccompiler
.
gen_lib_options
(
*
args
,
**
kwargs
)
return
unpatched
[
'msvc14_gen_lib_options'
](
*
args
,
**
kwargs
)
return
monkey
.
unpatched
[
'msvc14_gen_lib_options'
](
*
args
,
**
kwargs
)
def
_augment_exception
(
exc
,
version
,
arch
=
''
):
...
...
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