11import os
22import subprocess
3+ import sys
4+ from typing import TYPE_CHECKING
5+
36from jinja2 import Template
4- try :
7+
8+ if TYPE_CHECKING or sys .version_info > (3 , 8 , 0 ):
59 from importlib import resources as importlib_resources
6- except ImportError :
7- # python<= 3.8
10+ else :
11+ # python <= 3.8
812 import importlib_resources
13+
914import yaml
1015
11- from mache .machine_info import discover_machine , MachineInfo
16+ from mache .machine_info import MachineInfo , discover_machine
1217from mache .version import __version__
1318
1419
@@ -99,7 +104,7 @@ def make_spack_env(spack_path, env_name, spack_specs, compiler, mpi,
99104 path = \
100105 importlib_resources .files ('mache.spack' ) / shell_filename
101106 try :
102- with open (path ) as fp :
107+ with open (str ( path ) ) as fp :
103108 template = Template (fp .read ())
104109 except FileNotFoundError :
105110 # there's nothing to add, which is fine
@@ -112,7 +117,7 @@ def make_spack_env(spack_path, env_name, spack_specs, compiler, mpi,
112117
113118 path = \
114119 importlib_resources .files ('mache.spack' ) / 'build_spack_env.template'
115- with open (path ) as fp :
120+ with open (str ( path ) ) as fp :
116121 template = Template (fp .read ())
117122 if tmpdir is not None :
118123 modules = f'{ modules } \n ' \
@@ -219,7 +224,7 @@ def get_spack_script(spack_path, env_name, compiler, mpi, shell, machine=None,
219224 path = \
220225 importlib_resources .files ('mache.spack' ) / shell_filename
221226 try :
222- with open (path ) as fp :
227+ with open (str ( path ) ) as fp :
223228 template = Template (fp .read ())
224229 except FileNotFoundError :
225230 # there's nothing to add, which is fine
@@ -321,7 +326,7 @@ def get_modules_env_vars_and_mpi_compilers(machine, compiler, mpi, shell,
321326 path = \
322327 importlib_resources .files ('mache.spack' ) / shell_filename
323328 try :
324- with open (path ) as fp :
329+ with open (str ( path ) ) as fp :
325330 template = Template (fp .read ())
326331 except FileNotFoundError :
327332 # there's nothing to add, which is fine
@@ -345,7 +350,7 @@ def _get_yaml_data(machine, compiler, mpi, include_e3sm_lapack,
345350 path = \
346351 importlib_resources .files ('mache.spack' ) / template_filename
347352 try :
348- with open (path ) as fp :
353+ with open (str ( path ) ) as fp :
349354 template = Template (fp .read ())
350355 except FileNotFoundError :
351356 raise ValueError (f'Spack template not available for { compiler } '
@@ -373,9 +378,9 @@ def _get_modules(yaml_string):
373378 for mod in item ['modules' ]:
374379 mods .append (f'module load { mod } ' )
375380
376- mods = '\n ' .join (mods )
381+ mods_str = '\n ' .join (mods )
377382
378- return mods
383+ return mods_str
379384
380385
381386def _get_mpi_compilers (machine , compiler , mpi , cray_compilers ):
0 commit comments