From 29efd9665f77be50f317d0d39472a1f2e867bbe0 Mon Sep 17 00:00:00 2001
From: Mario Melara <maamelara@gmail.com>
Date: Thu, 9 Feb 2017 15:49:04 -0800
Subject: [PATCH] Add crayos version detection

---
 lib/spack/spack/operating_systems/cnl.py | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/lib/spack/spack/operating_systems/cnl.py b/lib/spack/spack/operating_systems/cnl.py
index 7acab1cbcb..164f435bf2 100644
--- a/lib/spack/spack/operating_systems/cnl.py
+++ b/lib/spack/spack/operating_systems/cnl.py
@@ -27,6 +27,7 @@
 from spack.architecture import OperatingSystem
 from spack.util.executable import *
 import spack.spec
+import spack.version
 from spack.util.multiproc import parmap
 import spack.compilers
 
@@ -39,13 +40,22 @@ class Cnl(OperatingSystem):
     updated to indicate that OS has been upgraded (or downgraded)
     """
 
+    def detect_crayos_version(self):
+        modulecmd = which("modulecmd")
+        modulecmd.add_default_arg("python")
+        output = modulecmd("avail", "PrgEnv-intel", output=str, error=str)
+        matches = re.findall(r'PrgEnv-intel/(\d+).\d+.\d+', output)
+        version_set = set(matches) # 
+        recent_version = max(version_set)
+        return spack.version.Version(recent_version)
+
     def __init__(self):
-        name = 'CNL'
-        version = '10'
+        name = 'cnl'
+        version = self.detect_crayos_version()
         super(Cnl, self).__init__(name, version)
 
     def __str__(self):
-        return self.name
+        return self.name + str(self.version)
 
     def find_compilers(self, *paths):
         types = spack.compilers.all_compiler_types()
-- 
GitLab