summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew W Elble <aweits@rit.edu>2022-01-05 13:22:43 -0500
committerGitHub <noreply@github.com>2022-01-05 10:22:43 -0800
commita4f0fbafbb7e60fb056e1bea8de924c9c2286e61 (patch)
tree35e67e99994d8c4cacf2d8faef5fe451fc38b619 /lib
parent52cfd179177412ec772c820dc5e345d17cb83bd1 (diff)
downloadspack-a4f0fbafbb7e60fb056e1bea8de924c9c2286e61.tar.gz
spack-a4f0fbafbb7e60fb056e1bea8de924c9c2286e61.tar.bz2
spack-a4f0fbafbb7e60fb056e1bea8de924c9c2286e61.tar.xz
spack-a4f0fbafbb7e60fb056e1bea8de924c9c2286e61.zip
Add function to determine Linux kernel version (#27855)
This reports the kernel version (vs. the distro version) on Linux and returns a valid Version (stripping characters like '+' which may be present for custom-built kernels).
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/operating_systems/linux_distro.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/spack/spack/operating_systems/linux_distro.py b/lib/spack/spack/operating_systems/linux_distro.py
index 8bb2aa7749..c03e85ccba 100644
--- a/lib/spack/spack/operating_systems/linux_distro.py
+++ b/lib/spack/spack/operating_systems/linux_distro.py
@@ -2,11 +2,31 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+import platform as py_platform
import re
+from spack.version import Version
+
from ._operating_system import OperatingSystem
+def kernel_version():
+ """Return the kernel version as a Version object.
+ Note that the kernel version is distinct from OS and/or
+ distribution versions. For instance:
+ >>> external.distro.id()
+ 'centos'
+ >>> external.distro.version()
+ '7'
+ >>> platform.release()
+ '5.10.84+'
+ """
+ # Strip '+' characters just in case we're running a
+ # version built from git/etc
+ clean_version = re.sub(r'\+', r'', py_platform.release())
+ return Version(clean_version)
+
+
class LinuxDistro(OperatingSystem):
""" This class will represent the autodetected operating system
for a Linux System. Since there are many different flavors of