Skip to content

Commit af7bd6a

Browse files
committed
modernize to f-string
1 parent b87a913 commit af7bd6a

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

winpython/utils.py

+21-25
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def get_special_folder_path(path_name):
194194
0, csidl, False
195195
)
196196
raise ValueError(
197-
"%s is an unknown path ID" % (path_name,)
197+
f"{path_name} is an unknown path ID"
198198
)
199199

200200

@@ -225,7 +225,7 @@ def create_winpython_start_menu_folder(current=True):
225225
shutil.rmtree(path, onerror=onerror)
226226
except WindowsError:
227227
print(
228-
"Directory %s could not be removed" % path,
228+
f"Directory {path} could not be removed",
229229
file=sys.stderr,
230230
)
231231
else:
@@ -371,13 +371,13 @@ def python_query(cmd, path):
371371
"""Execute Python command using the Python interpreter located in *path*"""
372372
the_exe = get_python_executable(path)
373373
# debug2021-09-12
374-
print('"%s" -c "%s"' % (the_exe, cmd), ' * ', path)
375-
return exec_shell_cmd('"%s" -c "%s"' % (the_exe, cmd), path).splitlines()[0]
374+
print(f'"{the_exe}" -c "{cmd}"', ' * ', path)
375+
return exec_shell_cmd(f'"{the_exe}" -c "{cmd}"', path).splitlines()[0]
376376

377377
def python_execmodule(cmd, path):
378378
"""Execute Python command using the Python interpreter located in *path*"""
379379
the_exe = get_python_executable(path)
380-
exec_shell_cmd('%s -m %s' % (the_exe, cmd), path)
380+
exec_shell_cmd(f'{the_exe} -m {cmd}', path)
381381

382382

383383
def get_python_infos(path):
@@ -389,8 +389,8 @@ def get_python_infos(path):
389389
)
390390
arch = {'True': 64, 'False': 32}.get(is_64, None)
391391
ver = python_query(
392-
"import sys; print('%d.%d' % (sys.version_info.major, "
393-
"sys.version_info.minor))",
392+
"import sys;print(f'{sys.version_info.major}.{sys.version_info.minor}')"
393+
,
394394
path,
395395
)
396396
if re.match(r'([0-9]*)\.([0-9]*)', ver) is None:
@@ -403,9 +403,8 @@ def get_python_long_version(path):
403403
"""Return long version (X.Y.Z) for the Python distribution located in
404404
*path*"""
405405
ver = python_query(
406-
"import sys; print('%d.%d.%d' % "
407-
"(sys.version_info.major, sys.version_info.minor,"
408-
"sys.version_info.micro))",
406+
"import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}')"
407+
,
409408
path,
410409
)
411410
if (
@@ -634,10 +633,10 @@ def extract_exe(fname, targetdir=None, verbose=False):
634633
targetdir = _create_temp_dir()
635634
extract = '7z.exe'
636635
assert is_program_installed(extract), (
637-
"Required program '%s' was not found" % extract
636+
f"Required program '{extract}' was not found"
638637
)
639638
bname = Path(fname).name
640-
args = ['x', '-o%s' % targetdir, '-aos', bname]
639+
args = ['x', f'-o{targetdir}', '-aos', bname]
641640
if verbose:
642641
retcode = subprocess.call(
643642
[extract] + args, cwd=str(Path(fname).parent)
@@ -653,8 +652,7 @@ def extract_exe(fname, targetdir=None, verbose=False):
653652
retcode = p.returncode
654653
if retcode != 0:
655654
raise RuntimeError(
656-
"Failed to extract %s (return code: %d)"
657-
% (fname, retcode)
655+
f"Failed to extract {fname} (return code: {retcode})"
658656
)
659657
return targetdir
660658

@@ -676,7 +674,7 @@ def extract_archive(fname, targetdir=None, verbose=False):
676674
obj = tarfile.open(fname, mode='r:gz')
677675
else:
678676
raise RuntimeError(
679-
"Unsupported archive filename %s" % fname
677+
f"Unsupported archive filename {fname}"
680678
)
681679
obj.extractall(path=targetdir)
682680
return targetdir
@@ -727,7 +725,7 @@ def build_wininst(
727725
archstr = (
728726
'win32' if architecture == 32 else 'win-amd64'
729727
)
730-
cmd += ['--plat-name=%s' % archstr]
728+
cmd += [f'--plat-name={archstr}']
731729
cmd += [installer]
732730
# root = a tmp dir in windows\tmp,
733731
if verbose:
@@ -769,8 +767,7 @@ def build_wininst(
769767
break
770768
else:
771769
raise RuntimeError(
772-
"Build failed: not a pure Python package? %s"
773-
% distdir
770+
f"Build failed: not a pure Python package? {distdir}"
774771
)
775772
src_fname = str(Path(distdir) / distname)
776773
if copy_to is None:
@@ -781,8 +778,7 @@ def build_wininst(
781778
if verbose:
782779
print(
783780
(
784-
"Move: %s --> %s"
785-
% (src_fname, (dst_fname))
781+
f"Move: {src_fname} --> {dst_fname}"
786782
)
787783
)
788784
# remove tempo dir 'root' no more needed
@@ -821,14 +817,14 @@ def direct_pip_install(
821817
stderr=subprocess.PIPE,
822818
)
823819
stdout, stderr = p.communicate()
824-
the_log = "%s" % stdout + "\n %s" % stderr
820+
the_log = f"{stdout}" + f"\n {stderr}"
825821

826822
if (
827823
' not find ' in the_log
828824
or ' not found ' in the_log
829825
):
830-
print("Failed to Install: \n %s \n" % fname)
831-
print("msg: %s" % the_log)
826+
print(f"Failed to Install: \n {fname} \n")
827+
print(f"msg: {the_log}")
832828
raise RuntimeError
833829
p.stdout.close()
834830
p.stderr.close()
@@ -837,7 +833,7 @@ def direct_pip_install(
837833
return src_fname
838834
else:
839835
if verbose:
840-
print("Installed %s" % src_fname)
836+
print(f"Installed {src_fname}")
841837
return src_fname
842838

843839

@@ -877,7 +873,7 @@ def do_script(
877873
p.stdout.close()
878874
p.stderr.close()
879875
if verbose:
880-
print("Executed " % cmd)
876+
print("Executed " , cmd)
881877
return 'ok'
882878

883879

0 commit comments

Comments
 (0)