On 7/9/19, Steve Barnes GadgetSteve@live.co.uk wrote:
Currently the py[w] command will launch the latest python by default however I feel that this discourages the testing of pre-releases & release candidates as once they are installed they will become the default. What I would like is for the default to be the highest version number of a full release but the user to be able to specify a specific version even if it is a pre-release.
With the existing launcher, if we install a pre-release candidate, we can set the PY_PYTHON environment variable to make the launcher default to a preferred stable release.
To modify the launcher to detect a "final" build, we can check the file version from the PE image's FIXEDFILEINFO . It consists of four 16-bit values: PY_MAJOR_VERSION, PY_MINOR_VERSION, FIELD3, PYTHON_API_VERSION. What we want is FIELD3, which is the upper WORD in the least significant DWORD (i.e. dwFileVersionLS >> 16). FIELD3 is computed as
micro * 1000 + levelnum * 10 + serial
where levelnum is
alpha: 10 beta: 11 candidate: 12 final: 15
and serial is 0-9. The executable is a "final" release if FIELD3 modulo 1000 is at least 150. Here's a quick ctypes example with Python 3.7.3:
version = ctypes.WinDLL('version', use_last_error=True) szBlock = version.GetFileVersionInfoSizeW(sys.executable, None) block = (ctypes.c_char * szBlock)() version.GetFileVersionInfoW(sys.executable, 0, szBlock, block)
pinfo = ctypes.POINTER(ctypes.c_ulong)() szInfo = ctypes.c_ulong() version.VerQueryValueW(block, '\', ctypes.byref(pinfo), ctypes.byref(szInfo))
>>> (pinfo >> 16) % 1000 150
>>> sys.version_info sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)