[Distutils] Wheels and console script entry point wrappers (Was: Replacing pip.exe with a Python script)
Steve.Dower at microsoft.com
Fri Jul 19 21:48:03 CEST 2013
> From: Oscar Benjamin
> I don't know whether or not you intend to have wrappers also work for
> Python 2.7 (in a third-party package perhaps) but there is a slightly
> subtle point to watch out for when non-ASCII characters in sys.argv
> come into play.
> Python 2.x uses GetCommandLineA and 3.x uses GetCommandLineW. A
> wrapper to launch 2.x should use GetCommandLineA and CreateProcessA to
> ensure that the 8-bit argument strings are passed through unaltered.
> To launch 3.x it should use the W versions. If not then the MSVC
> runtime (or the OS?) will convert between the 8-bit and 16-bit
> encodings using its own lossy routines.
The launcher should always use GetCommandLineW, because the command line is already stored in a 16-bit encoding. GetCommandLineA will decode to an 8-bit encoding using some code page/settings (I can probably find out exactly which ones, but I don't know/care off the top of my head), and CreateProcessA will convert back using (hopefully) the same code page.
There is never any point passing data between *A APIs in Windows, because they are just doing the conversion in the background. All you gain is that the launcher will corrupt the command line before python.exe gets a chance to.
More information about the Distutils-SIG