forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment.py
56 lines (50 loc) · 1.76 KB
/
environment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
"""
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'