-
Notifications
You must be signed in to change notification settings - Fork 9
/
constants.py
142 lines (118 loc) · 4.79 KB
/
constants.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#
# Copyright 2013-2022 Ghent University
#
# This file is part of EasyBuild,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
# with support of Ghent University (http://ugent.be/hpc),
# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
# Flemish Research Foundation (FWO) (http://www.fwo.be/en)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# https://github.com/easybuilders/easybuild
#
# EasyBuild is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation v2.
#
# EasyBuild is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with EasyBuild. If not, see <http://www.gnu.org/licenses/>.
#
"""
Easyconfig constants module that provides all constants that can
be used within an Easyconfig file.
:author: Stijn De Weirdt (Ghent University)
:author: Kenneth Hoste (Ghent University)
"""
import os
import sys
import platform
# from systemtools import KNOWN_ARCH_CONSTANTS, get_os_name, get_os_type, get_os_version
try:
import distro
HAVE_DISTRO = True
except ImportError as err:
sys.stderr.write("Failed to import 'distro' Python module: %s".format(err))
sys.exit()
EXTERNAL_MODULE_MARKER = 'EXTERNAL_MODULE'
# from easybuild.tools.systemtools import get_os_type, KNOWN_ARCH_CONSTANTS
KNOWN_ARCH_CONSTANTS = ('aarch64', 'ppc64le', 'riscv64', 'x86_64')
def get_os_version():
"""Determine system version."""
os_version = None
if not os_version and HAVE_DISTRO:
os_version = distro.version()
return os_version
def get_os_name():
"""
Determine system name, e.g., 'redhat' (generic), 'centos', 'debian', 'fedora', 'suse', 'ubuntu',
'red hat enterprise linux server', 'SL' (Scientific Linux), 'opensuse', ...
"""
os_name = None
# platform.linux_distribution was removed in Python 3.8,
# see https://docs.python.org/2/library/platform.html#platform.linux_distribution
if hasattr(platform, 'linux_distribution'):
# platform.linux_distribution is more useful, but only available since Python 2.6
# this allows to differentiate between Fedora, CentOS, RHEL and Scientific Linux (Rocks is just CentOS)
os_name = platform.linux_distribution()[0].strip()
# take into account that on some OSs, platform.distribution returns an empty string as OS name,
# for example on OpenSUSE Leap 15.2
if not os_name and HAVE_DISTRO:
# distro package is the recommended alternative to platform.linux_distribution,
# see https://pypi.org/project/distro
os_name = distro.name()
if not os_name and os.path.exists(ETC_OS_RELEASE):
os_release_txt = read_file(ETC_OS_RELEASE)
name_regex = re.compile('^NAME="?(?P<name>[^"\n]+)"?$', re.M)
res = name_regex.search(os_release_txt)
if res:
os_name = res.group('name')
os_name_map = {
'red hat enterprise linux server': 'RHEL',
'red hat enterprise linux': 'RHEL', # RHEL8 has no server/client
'scientific linux sl': 'SL',
'scientific linux': 'SL',
'suse linux enterprise server': 'SLES',
}
if os_name:
return os_name_map.get(os_name.lower(), os_name)
else:
return UNKNOWN
def get_os_type():
"""Determine system type, e.g., 'Linux', 'Darwin', 'Java'."""
os_type = platform.system()
if len(os_type) > 0:
return os_type
else:
raise SystemToolsException("Failed to determine system name using platform.system().")
def _get_arch_constant():
"""
Get value for ARCH constant.
"""
arch = platform.uname()[4]
# macOS on Arm produces 'arm64' rather than 'aarch64'
if arch == 'arm64':
arch = 'aarch64'
if arch not in KNOWN_ARCH_CONSTANTS:
sys.stderr.write("Using unknown value for ARCH constant: %s", arch)
return arch
# constants that can be used in easyconfig
EASYCONFIG_CONSTANTS = {
'ARCH': _get_arch_constant(),
'EXTERNAL_MODULE': EXTERNAL_MODULE_MARKER,
'HOME': os.path.expanduser('~'),
'OS_TYPE': get_os_type(),
'OS_NAME': get_os_name(),
'OS_VERSION': get_os_version(),
'SYS_PYTHON_VERSION': platform.python_version(),
'SYSTEM': "System toolchain",
'OS_PKG_IBVERBS_DEV': ('libibverbs-dev', 'libibverbs-devel', 'rdma-core-devel'),
'OS_PKG_OPENSSL_BIN': ('openssl'),
'OS_PKG_OPENSSL_LIB': ('libssl', 'libopenssl'),
'OS_PKG_OPENSSL_DEV': ('openssl-devel', 'libssl-dev', 'libopenssl-devel'),
'OS_PKG_PAM_DEV': ('pam-devel', 'libpam0g-dev'),
}