Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a146fea

Browse files
author
Thomas Heller
committed
Fix SF#983164.
Patch from Mark Hammond: bdist_wininst attempts to use the correct MSVC runtime for the current version of Python. This doesn't work correctly when --target-version is set. In that case, bdist_wininst still uses the *current* sys.version (ie, 2.4) rather than the version specified as --target-version. Thus, the msvc7 runtime based executable stub is *always* used. This patch "hard-codes" knowledge of earlier Python versions, providing the correct result when Python 2.4 is used to build Python 2.3 and earlier distributions. Remove the short variant (-v) of the --target-version command line options, it conflicts with the --verbose/-v standard distutils switch.
1 parent 5124b4a commit a146fea

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

Lib/distutils/command/bdist_wininst.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class bdist_wininst (Command):
2424
('keep-temp', 'k',
2525
"keep the pseudo-installation tree around after " +
2626
"creating the distribution archive"),
27-
('target-version=', 'v',
27+
('target-version=', None,
2828
"require a specific python version" +
2929
" on the target system"),
3030
('no-target-compile', 'c',
@@ -265,10 +265,34 @@ def create_exe (self, arcname, fullname, bitmap=None):
265265

266266
def get_exe_bytes (self):
267267
from distutils.msvccompiler import get_build_version
268+
# If a target-version other than the current version has been
269+
# specified, then using the MSVC version from *this* build is no good.
270+
# Without actually finding and executing the target version and parsing
271+
# its sys.version, we just hard-code our knowledge of old versions.
272+
# NOTE: Possible alternative is to allow "--target-version" to
273+
# specify a Python executable rather than a simple version string.
274+
# We can then execute this program to obtain any info we need, such
275+
# as the real sys.version string for the build.
276+
cur_version = get_python_version()
277+
if self.target_version and self.target_version != cur_version:
278+
# If the target version is *later* than us, then we assume they
279+
# use what we use
280+
# string compares seem wrong, but are what sysconfig.py itself uses
281+
if self.target_version > cur_version:
282+
bv = get_build_version()
283+
else:
284+
if self.target_version < "2.4":
285+
bv = "6"
286+
else:
287+
bv = "7.1"
288+
else:
289+
# for current version - use authoritative check.
290+
bv = get_build_version()
291+
268292
# wininst-x.y.exe is in the same directory as this file
269293
directory = os.path.dirname(__file__)
270294
# we must use a wininst-x.y.exe built with the same C compiler
271295
# used for python. XXX What about mingw, borland, and so on?
272-
filename = os.path.join(directory, "wininst-%s.exe" % get_build_version())
296+
filename = os.path.join(directory, "wininst-%s.exe" % bv)
273297
return open(filename, "rb").read()
274298
# class bdist_wininst

0 commit comments

Comments
 (0)