Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Address code review feedback
  • Loading branch information
Paul Monson
Paul Monson committed Apr 22, 2019
commit 77d776efcc3234ede100576cb0a0a7501804afab
6 changes: 5 additions & 1 deletion Doc/library/platform.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,15 @@ Windows Platform
values include but are not limited to ``'Enterprise'``, ``'IoTUAP'``,
``'ServerStandard'``, and ``'nanoserver'``.

.. versionadded:: 3.8

.. function:: win32_is_iot()

Returns True if the windows edition returned by win32_edition is recognized
Returns True if the windows edition returned by win32_edition is recognized
as an IoT edition.

Comment thread
paulmon marked this conversation as resolved.
.. versionadded:: 3.8


Mac OS Platform
---------------
Expand Down
10 changes: 1 addition & 9 deletions Lib/distutils/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,15 +450,7 @@ def _init_nt():
# XXX hmmm.. a normal install puts include files here
g['INCLUDEPY'] = get_python_inc(plat_specific=0)

# if cross-compiling replace hardcoded platform-specific EXT_SUFFIX
# with an EXT_SUFFIX that matches the target platform
if get_platform() == get_host_platform():
g['EXT_SUFFIX'] = _imp.extension_suffixes()[0]
else:
plat_tag = get_platform().replace('-', '_')
host_plat_tag = get_host_platform().replace('-', '_')
g['EXT_SUFFIX'] = _imp.extension_suffixes()[0].replace(host_plat_tag, plat_tag)

g['EXT_SUFFIX'] = _imp.extension_suffixes()[0]
g['EXE'] = ".exe"
g['VERSION'] = get_python_version().replace(".", "")
g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
Expand Down
18 changes: 5 additions & 13 deletions Lib/distutils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from distutils import log
from distutils.errors import DistutilsByteCompileError

def get_host_platform ():
def get_host_platform():
"""Return a string that identifies the current platform. This is used mainly to
distinguish platform-specific build directories and platform-specific built
distributions. Typically includes the OS name and version and the
Expand Down Expand Up @@ -92,25 +92,17 @@ def get_host_platform ():

return "%s-%s-%s" % (osname, release, machine)

# get_host_platform ()

def get_platform ():
def get_platform():
TARGET_TO_PLAT = {
'x86' : 'win32',
'x64' : 'win-amd64',
'arm' : 'win-arm32',
}

targetPlatformFromEnvironment = os.environ.get('VSCMD_ARG_TGT_ARCH')

if targetPlatformFromEnvironment != None and targetPlatformFromEnvironment in TARGET_TO_PLAT:
targetPlatform = TARGET_TO_PLAT[targetPlatformFromEnvironment]
if os.name == 'nt':

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's only define TARGET_TO_PLAT for Windows as well. Even though it's static, it still gets constructed on each call and it doesn't have any meaning on other OS's.

return TARGET_TO_PLAT.get(os.environ.get('VSCMD_ARG_TGT_ARCH')) or get_host_platform()
else:
targetPlatform = get_host_platform()

return targetPlatform

# get_platform ()
return get_host_platform()

def convert_path (pathname):
"""Return 'pathname' as a name that will work on the native filesystem,
Expand Down
10 changes: 3 additions & 7 deletions Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,12 @@ def win32_edition():
except ImportError:
from _winreg import OpenKeyEx, QueryValueEx, CloseKey, HKEY_LOCAL_MACHINE

key = None
try:
key = OpenKeyEx(HKEY_LOCAL_MACHINE,
r'SOFTWARE\Microsoft\Windows NT\CurrentVersion')
return QueryValueEx(key, 'EditionId')[0]
with OpenKeyEx(HKEY_LOCAL_MACHINE,
r'SOFTWARE\Microsoft\Windows NT\CurrentVersion') as key:
return QueryValueEx(key, 'EditionId')[0]
except OSError:
pass
finally:
if key:
CloseKey(key)

return None

Expand Down
27 changes: 6 additions & 21 deletions Lib/test/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def check(input, expect):

# On small versions of Windows like Windows IoT or Windows Nano Server not all codepages are present
def is_code_page_present(cp):
from ctypes import POINTER, WINFUNCTYPE, windll, WinError, Structure
from ctypes import POINTER, WINFUNCTYPE, windll, WinError, Structure, WinDLL
from ctypes.wintypes import BOOL, UINT, BYTE, WCHAR, UINT, DWORD

MAX_LEADBYTES = 12 # 5 ranges, 2 bytes ea., 0 term.
Expand All @@ -44,22 +44,9 @@ class CPINFOEXW(ctypes.Structure):
("CodePageName", WCHAR*MAX_PATH)]

prototype = WINFUNCTYPE(BOOL, UINT, DWORD, POINTER(CPINFOEXW))
GetCPInfoEx = prototype(("GetCPInfoExW", windll.kernel32))

def errcheck(result, func, args):
if not result:
from ctypes import WinError
raise OSError(2, "code page not found")
return args

from ctypes import WinError
try:
GetCPInfoEx.errcheck = errcheck
info = CPINFOEXW()
GetCPInfoEx(cp,0, info)
return True
except OSError:
return False
GetCPInfoEx = prototype(("GetCPInfoExW", WinDLL("kernel32")))
info = CPINFOEXW()
return GetCPInfoEx(cp, 0, info)

class Queue(object):
"""
Expand Down Expand Up @@ -3120,12 +3107,10 @@ def test_code_page_decode_flags(self):
# A missing codepage causes an OSError exception
# so check for the codepage before decoding
if is_code_page_present(cp):
if support.verbose:
sys.stdout.write(" testing cp={}\n".format(cp))
self.assertEqual(codecs.code_page_decode(cp, b'abc'), ('abc', 3))
self.assertEqual(codecs.code_page_decode(cp, b'abc'), ('abc', 3), f'cp{cp}')
else:
if support.verbose:
sys.stdout.write(" skipping cp={}\n".format(cp))
print(f" skipping cp={cp}")
self.assertEqual(codecs.code_page_decode(42, b'abc'),
('\uf061\uf062\uf063', 3))

Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ def tearDown(self):
mimetypes.types_map.clear()
mimetypes.types_map.update(self.original_types_map)

@unittest.skipIf(win32_edition() in ('NanoServer', 'WindowsCoreHeadless', 'IoTEdgeOS'), "mime types registry keys not available on NanoServer")
@unittest.skipIf(win32_edition() in ('NanoServer', 'WindowsCoreHeadless', 'IoTEdgeOS'),
"MIME types registry keys unavailable")
def test_registry_parsing(self):
# the original, minimum contents of the MIME database in the
# Windows registry is undocumented AFAIK.
Expand Down