Skip to content

Commit b8a5f9e

Browse files
George Bisbasmloubout
authored andcommitted
docs: Minor fstring changes
1 parent 2e60c2c commit b8a5f9e

1 file changed

Lines changed: 35 additions & 37 deletions

File tree

devito/arch/compiler.py

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def sniff_compiler_version(cc, allow_fail=False):
4545
if allow_fail:
4646
return Version("0")
4747
else:
48-
raise RuntimeError("The `%s` compiler isn't available on this system" % cc)
48+
raise RuntimeError(f"The `{cc}` compiler isn't available on this system")
4949

5050
ver = ver.strip()
5151
if ver.startswith("gcc"):
@@ -190,8 +190,7 @@ def __init__(self, **kwargs):
190190
self.suffix = kwargs.get('suffix')
191191
if not kwargs.get('mpi'):
192192
self.cc = self.CC if self._cpp is False else self.CXX
193-
self.cc = self.cc if self.suffix is None else ('%s-%s' %
194-
(self.cc, self.suffix))
193+
self.cc = self.cc if self.suffix is None else f'{self.cc}-{self.suffix}'
195194
else:
196195
self.cc = self.MPICC if self._cpp is False else self.MPICXX
197196
self.ld = self.cc # Wanted by the superclass
@@ -214,7 +213,7 @@ def __init__(self, **kwargs):
214213
elif platform.system() == "Windows":
215214
self.so_ext = '.dll'
216215
else:
217-
raise NotImplementedError("Unsupported platform %s" % platform)
216+
raise NotImplementedError(f"Unsupported platform {platform}")
218217

219218
self.__init_finalize__(**kwargs)
220219

@@ -291,20 +290,19 @@ def save(self, soname, binary):
291290
"""
292291
sofile = self.get_jit_dir().joinpath(soname).with_suffix(self.so_ext)
293292
if sofile.is_file():
294-
debug("%s: `%s` was not saved in `%s` as it already exists"
295-
% (self, sofile.name, self.get_jit_dir()))
293+
debug(f"{self}: `{sofile.name}` was not saved in `{self.get_jit_dir()}`"
294+
" as it already exists")
296295
else:
297296
makedirs(self.get_jit_dir(), exist_ok=True)
298297
with open(str(sofile), 'wb') as f:
299298
f.write(binary)
300-
debug("%s: `%s` successfully saved in `%s`"
301-
% (self, sofile.name, self.get_jit_dir()))
299+
debug(f"{self}: `{sofile.name}` successfully saved in `{self.get_jit_dir()}`")
302300

303301
def make(self, loc, args):
304302
"""Invoke the ``make`` command from within ``loc`` with arguments ``args``."""
305303
hash_key = sha1((loc + str(args)).encode()).hexdigest()
306-
logfile = path.join(self.get_jit_dir(), "%s.log" % hash_key)
307-
errfile = path.join(self.get_jit_dir(), "%s.err" % hash_key)
304+
logfile = path.join(self.get_jit_dir(), f"{hash_key}.log")
305+
errfile = path.join(self.get_jit_dir(), f"{hash_key}.err")
308306

309307
with change_directory(loc):
310308
with open(logfile, "w") as lf:
@@ -317,12 +315,12 @@ def make(self, loc, args):
317315
try:
318316
check_call(command, stderr=ef, stdout=lf)
319317
except CalledProcessError as e:
320-
raise CompilationError('Command "%s" return error status %d. '
321-
'Unable to compile code.\n'
322-
'Compile log in %s\n'
323-
'Compile errors in %s\n' %
324-
(e.cmd, e.returncode, logfile, errfile))
325-
debug("Make <%s>" % " ".join(args))
318+
raise CompilationError(f'Command "{e.cmd}" return error status'
319+
f'{e.returncode}. '
320+
f'Unable to compile code.\n'
321+
f'Compile log in {logfile}\n'
322+
f'Compile errors in {errfile}\n')
323+
debug(f"Make <{' '.join(args)}>")
326324

327325
def jit_compile(self, soname, code):
328326
"""
@@ -340,7 +338,7 @@ def jit_compile(self, soname, code):
340338
The source code to be JIT compiled.
341339
"""
342340
target = str(self.get_jit_dir().joinpath(soname))
343-
src_file = "%s.%s" % (target, self.src_ext)
341+
src_file = f"{target}.{self.src_ext}"
344342

345343
cache_dir = self.get_codepy_dir().joinpath(soname[:7])
346344
if configuration['jit-backdoor'] is False:
@@ -353,15 +351,15 @@ def jit_compile(self, soname, code):
353351
try:
354352
with open(src_file, 'r') as f:
355353
code = f.read()
356-
code = ''.join([code, '/* Backdoor edit at %s*/ \n' % time.ctime()])
354+
code = f'{code}/* Backdoor edit at {time.ctime()}*/ \n'
357355
# Bypass the devito JIT cache
358356
# Note: can't simply use Python's `mkdtemp()` as, with MPI, different
359357
# ranks would end up creating different cache dirs
360358
cache_dir = cache_dir.joinpath('jit-backdoor')
361359
cache_dir.mkdir(parents=True, exist_ok=True)
362360
except FileNotFoundError:
363-
raise ValueError("Trying to use the JIT backdoor for `%s`, but "
364-
"the file isn't present" % src_file)
361+
raise ValueError(f"Trying to use the JIT backdoor for `{src_file}`, but "
362+
"the file isn't present")
365363

366364
# Should the compilation command be emitted?
367365
debug = configuration['log-level'] == 'DEBUG'
@@ -392,7 +390,7 @@ def __str__(self):
392390
return self.__class__.__name__
393391

394392
def __repr__(self):
395-
return "JITCompiler[%s]" % self.__class__.__name__
393+
return f"JITCompiler[{self.__class__.__name__}]"
396394

397395
def __getstate__(self):
398396
# The superclass would otherwise only return a subset of attributes
@@ -406,7 +404,7 @@ def add_library_dirs(self, dirs, rpath=False):
406404
if rpath:
407405
# Add rpath flag to embed library dir
408406
for d in as_list(dirs):
409-
self.ldflags.append('-Wl,-rpath,%s' % d)
407+
self.ldflags.append(f'-Wl,-rpath,{d}')
410408

411409
def add_libraries(self, libs):
412410
self.libraries = filter_ordered(self.libraries + as_list(libs))
@@ -442,10 +440,10 @@ def __init_finalize__(self, **kwargs):
442440
# -march isn't supported on power architectures, is -mtune needed?
443441
self.cflags = ['-mcpu=native'] + self.cflags
444442
elif isinstance(platform, Graviton):
445-
self.cflags = ['-mcpu=%s' % platform.march] + self.cflags
443+
self.cflags = [f'-mcpu={platform.march}'] + self.cflags
446444
elif isinstance(platform, Cortex):
447-
self.cflags += ['-march=%s' % platform.march]
448-
self.cflags += ['-mtune=%s' % platform.mtune]
445+
self.cflags += [f'-march={platform.march}']
446+
self.cflags += [f'-mtune={platform.mtune}']
449447
else:
450448
self.cflags = ['-march=native'] + self.cflags
451449

@@ -491,7 +489,7 @@ def __init_finalize__(self, **kwargs):
491489
if language in ['C', 'openmp']:
492490
cc = get_nvidia_cc()
493491
if cc:
494-
self.cflags += ['-Xopenmp-target', '-march=sm_%s' % cc]
492+
self.cflags += ['-Xopenmp-target', f'-march=sm_{cc}']
495493
self.ldflags += ['-fopenmp', '-fopenmp-targets=nvptx64-nvidia-cuda']
496494
elif platform is AMDGPUX:
497495
self.cflags.remove('-std=c99')
@@ -501,7 +499,7 @@ def __init_finalize__(self, **kwargs):
501499
self.ldflags += ['-fopenmp',
502500
'-fopenmp-targets=amdgcn-amd-amdhsa',
503501
'-Xopenmp-target=amdgcn-amd-amdhsa']
504-
self.ldflags += ['-march=%s' % platform.march]
502+
self.ldflags += [f'-march={platform.march}']
505503
elif isinstance(platform, AppleArm):
506504
# NOTE:
507505
# Apple Mx supports OpenMP through Apple's LLVM compiler.
@@ -510,9 +508,9 @@ def __init_finalize__(self, **kwargs):
510508
llvmm1 = get_m1_llvm_path(language)
511509
if llvmm1 and language == 'openmp':
512510
mx = platform.march
513-
self.ldflags += ['-mcpu=apple-%s' % mx,
514-
'-fopenmp', '-L%s' % llvmm1['libs']]
515-
self.cflags += ['-Xclang', '-I%s' % llvmm1['include']]
511+
self.ldflags += [f'-mcpu=apple-{mx}',
512+
'-fopenmp', f'-L{llvmm1["libs"]}']
513+
self.cflags += ['-Xclang', f'-I{llvmm1["include"]}']
516514
else:
517515
if platform in [POWER8, POWER9]:
518516
# -march isn't supported on power architectures
@@ -561,7 +559,7 @@ def __init_finalize__(self, **kwargs):
561559
if language in ['C', 'openmp']:
562560
self.ldflags += ['-target', 'x86_64-pc-linux-gnu']
563561
self.ldflags += ['-fopenmp']
564-
self.ldflags += ['--offload-arch=%s' % platform.march]
562+
self.ldflags += [f'--offload-arch={platform.march}']
565563
elif platform in [POWER8, POWER9]:
566564
# It doesn't make much sense to use AOMP on Power, but it should work
567565
self.cflags.append('-mcpu=native')
@@ -774,15 +772,15 @@ def __init_intel_mpi__(self, **kwargs):
774772
# whatever the MPI distro is
775773
mpi_distro = sniff_mpi_distro('mpiexec')
776774
if mpi_distro != 'IntelMPI':
777-
warning("Expected Intel MPI distribution with `%s`, but found `%s`"
778-
% (self.__class__.__name__, mpi_distro))
775+
warning(f"Expected Intel MPI distribution with `{self.__class__.__name__}`,"
776+
f"but found `{mpi_distro}`")
779777

780778
def __init_intel_mpi_flags__(self, **kwargs):
781-
self.cflags.insert(0, '-cc=%s' % self.CC)
779+
self.cflags.insert(0, f'-cc={self.CC}')
782780

783781
def get_version(self):
784782
if configuration['mpi']:
785-
cmd = (self.cc, "-cc=%s" % self.CC, "--version")
783+
cmd = (self.cc, f"-cc={self.CC}", "--version")
786784
else:
787785
cmd = (self.cc, "--version")
788786
result, stdout, stderr = call_capture_output(cmd)
@@ -801,7 +799,7 @@ def __lookup_cmds__(self):
801799
# we try to use `mpiicc` first, while `mpicc` is our fallback, which may
802800
# or may not be an Intel distribution
803801
try:
804-
check_output(["mpiicc", "-cc=%s" % self.CC, "--version"]).decode("utf-8")
802+
check_output(["mpiicc", f"-cc={self.CC}", "--version"]).decode("utf-8")
805803
self.MPICC = 'mpiicc'
806804
self.MPICXX = 'mpicxx'
807805
except FileNotFoundError:
@@ -903,7 +901,7 @@ def __init_finalize__(self, **kwargs):
903901
elif isinstance(platform, IntelDevice):
904902
self.cflags.append('-fsycl-targets=spir64')
905903
else:
906-
raise NotImplementedError("Unsupported platform %s" % platform)
904+
raise NotImplementedError(f"Unsupported platform {platform}")
907905

908906

909907
class CustomCompiler(Compiler):

0 commit comments

Comments
 (0)