@@ -194,7 +194,7 @@ def get_special_folder_path(path_name):
194
194
0 , csidl , False
195
195
)
196
196
raise ValueError (
197
- "%s is an unknown path ID" % ( path_name ,)
197
+ f" { path_name } is an unknown path ID"
198
198
)
199
199
200
200
@@ -225,7 +225,7 @@ def create_winpython_start_menu_folder(current=True):
225
225
shutil .rmtree (path , onerror = onerror )
226
226
except WindowsError :
227
227
print (
228
- "Directory %s could not be removed" % path ,
228
+ f "Directory { path } could not be removed" ,
229
229
file = sys .stderr ,
230
230
)
231
231
else :
@@ -371,13 +371,13 @@ def python_query(cmd, path):
371
371
"""Execute Python command using the Python interpreter located in *path*"""
372
372
the_exe = get_python_executable (path )
373
373
# 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 ]
376
376
377
377
def python_execmodule (cmd , path ):
378
378
"""Execute Python command using the Python interpreter located in *path*"""
379
379
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 )
381
381
382
382
383
383
def get_python_infos (path ):
@@ -389,8 +389,8 @@ def get_python_infos(path):
389
389
)
390
390
arch = {'True' : 64 , 'False' : 32 }.get (is_64 , None )
391
391
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
+ ,
394
394
path ,
395
395
)
396
396
if re .match (r'([0-9]*)\.([0-9]*)' , ver ) is None :
@@ -403,9 +403,8 @@ def get_python_long_version(path):
403
403
"""Return long version (X.Y.Z) for the Python distribution located in
404
404
*path*"""
405
405
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
+ ,
409
408
path ,
410
409
)
411
410
if (
@@ -634,10 +633,10 @@ def extract_exe(fname, targetdir=None, verbose=False):
634
633
targetdir = _create_temp_dir ()
635
634
extract = '7z.exe'
636
635
assert is_program_installed (extract ), (
637
- "Required program '%s ' was not found" % extract
636
+ f "Required program '{ extract } ' was not found"
638
637
)
639
638
bname = Path (fname ).name
640
- args = ['x' , '-o%s' % targetdir , '-aos' , bname ]
639
+ args = ['x' , f '-o{ targetdir } ' , '-aos' , bname ]
641
640
if verbose :
642
641
retcode = subprocess .call (
643
642
[extract ] + args , cwd = str (Path (fname ).parent )
@@ -653,8 +652,7 @@ def extract_exe(fname, targetdir=None, verbose=False):
653
652
retcode = p .returncode
654
653
if retcode != 0 :
655
654
raise RuntimeError (
656
- "Failed to extract %s (return code: %d)"
657
- % (fname , retcode )
655
+ f"Failed to extract { fname } (return code: { retcode } )"
658
656
)
659
657
return targetdir
660
658
@@ -676,7 +674,7 @@ def extract_archive(fname, targetdir=None, verbose=False):
676
674
obj = tarfile .open (fname , mode = 'r:gz' )
677
675
else :
678
676
raise RuntimeError (
679
- "Unsupported archive filename %s" % fname
677
+ f "Unsupported archive filename { fname } "
680
678
)
681
679
obj .extractall (path = targetdir )
682
680
return targetdir
@@ -727,7 +725,7 @@ def build_wininst(
727
725
archstr = (
728
726
'win32' if architecture == 32 else 'win-amd64'
729
727
)
730
- cmd += ['--plat-name=%s' % archstr ]
728
+ cmd += [f '--plat-name={ archstr } ' ]
731
729
cmd += [installer ]
732
730
# root = a tmp dir in windows\tmp,
733
731
if verbose :
@@ -769,8 +767,7 @@ def build_wininst(
769
767
break
770
768
else :
771
769
raise RuntimeError (
772
- "Build failed: not a pure Python package? %s"
773
- % distdir
770
+ f"Build failed: not a pure Python package? { distdir } "
774
771
)
775
772
src_fname = str (Path (distdir ) / distname )
776
773
if copy_to is None :
@@ -781,8 +778,7 @@ def build_wininst(
781
778
if verbose :
782
779
print (
783
780
(
784
- "Move: %s --> %s"
785
- % (src_fname , (dst_fname ))
781
+ f"Move: { src_fname } --> { dst_fname } "
786
782
)
787
783
)
788
784
# remove tempo dir 'root' no more needed
@@ -821,14 +817,14 @@ def direct_pip_install(
821
817
stderr = subprocess .PIPE ,
822
818
)
823
819
stdout , stderr = p .communicate ()
824
- the_log = "%s" % stdout + "\n %s" % stderr
820
+ the_log = f" { stdout } " + f "\n { stderr } "
825
821
826
822
if (
827
823
' not find ' in the_log
828
824
or ' not found ' in the_log
829
825
):
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 } " )
832
828
raise RuntimeError
833
829
p .stdout .close ()
834
830
p .stderr .close ()
@@ -837,7 +833,7 @@ def direct_pip_install(
837
833
return src_fname
838
834
else :
839
835
if verbose :
840
- print ("Installed %s" % src_fname )
836
+ print (f "Installed { src_fname } " )
841
837
return src_fname
842
838
843
839
@@ -877,7 +873,7 @@ def do_script(
877
873
p .stdout .close ()
878
874
p .stderr .close ()
879
875
if verbose :
880
- print ("Executed " % cmd )
876
+ print ("Executed " , cmd )
881
877
return 'ok'
882
878
883
879
0 commit comments