Skip to content
Snippets Groups Projects
Commit a94a19f2 authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony
Browse files

Add environment module to wrap around platform Refs #6007

Gives more readable access to things like checking for windows/linux/mac
etc
parent d749e08c
No related branches found
No related tags found
No related merge requests found
"""
Defines a set functions for interrogating the current enviroment.
The standard platform module doesn't have simple things like is_windows(),
is_linux(). The set of functions defined here should make it clearer what is going
on when they are used.
"""
import platform as _platform
import sys as _sys
def is_windows():
"""
Returns True if the current platform is Windows (regardless of version/32- or 64-bit etc)
"""
return _sys.platform == "win32"
def is_mac():
"""
Returns True if the current platform is Mac (regardless of version/32- or 64-bit etc)
"""
return _sys.platform == "darwin"
def is_linux():
"""
Returns True if the current platform is OS X (regardless of version/32- or 64-bit etc)
Variant on is_apple
"""
return _sys.platform.startswith("linux")
def is_32bit():
"""
Returns True if the current platform is 32-bit
"""
if is_mac():
# See Python documentation on platform module for why this is different
return _sys.maxsize == 2**31 - 1 # Max size of integer
else:
bits = _platform.architecture()[0]
return bits == '32bit'
def is_64bit():
"""
Returns True if the current platform is 64-bit
"""
if is_mac():
# See Python documentation on platform module for why this is different
return _sys.maxsize > 2**32
else:
bits = _platform.architecture()[0]
return bits == '64bit'
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment