Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,16 +422,21 @@ def _win32_ver(version, csd, ptype):
# Fall back to a combination of sys.getwindowsversion and "ver"
try:
from sys import getwindowsversion
from _winapi import IsWindowsDesktop
except ImportError:
return version, csd, ptype, True

winver = getwindowsversion()
is_client = (getattr(winver, 'product_type', 1) == 1)
try:
version = _syscmd_ver()[2]
major, minor, build = map(int, version.split('.'))
except ValueError:
major, minor, build = winver.platform_version or winver[:3]
if IsWindowsDesktop():
try:
version = _syscmd_ver()[2]
major, minor, build = map(int, version.split('.'))
except ValueError:
major, minor, build = winver.platform_version or winver[:3]
version = '{0}.{1}.{2}'.format(major, minor, build)
else:
major, minor, build = winver[:3]
version = '{0}.{1}.{2}'.format(major, minor, build)

# getwindowsversion() reflect the compatibility mode Python is
Expand Down
18 changes: 18 additions & 0 deletions Modules/_winapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -3175,6 +3175,23 @@ _winapi_GetTickCount64_impl(PyObject *module)
return PyLong_FromUnsignedLongLong(ticks);
}

/*[clinic input]
_winapi.IsWindowsDesktop

Return TRUE for Windows desktop build or FALSE for UWP build.
[clinic start generated code]*/

static PyObject *
_winapi_IsWindowsDesktop_impl(PyObject *module)
/*[clinic end generated code: output=6c1a044078bba5fd input=cf5bd7f013ba4bff]*/
{
#ifdef MS_WINDOWS_DESKTOP
return PyBool_FromLong(TRUE);
#else
return PyBool_FromLong(FALSE);
#endif
}


static PyMethodDef winapi_functions[] = {
_WINAPI_CLOSEHANDLE_METHODDEF
Expand Down Expand Up @@ -3228,6 +3245,7 @@ static PyMethodDef winapi_functions[] = {
_WINAPI_COPYFILE2_METHODDEF
_WINAPI_GETPROCESSMEMORYINFO_METHODDEF
_WINAPI_GETTICKCOUNT64_METHODDEF
_WINAPI_ISWINDOWSDESKTOP_METHODDEF
{NULL, NULL}
};

Expand Down
20 changes: 19 additions & 1 deletion Modules/clinic/_winapi.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading