Skip to content

Commit 9b7dabb

Browse files
authored
Merge pull request winpython#1172 from stonebig/master
modernize to f-string
2 parents 7b3044f + e64ad32 commit 9b7dabb

File tree

1 file changed

+21
-33
lines changed

1 file changed

+21
-33
lines changed

winpython/wppm.py

+21-33
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,15 @@ def __init__(self, fname):
126126
self.url = None
127127

128128
def __str__(self):
129-
text = "%s %s" % (self.name, self.version)
129+
text = f"{self.name} {self.version}"
130130
pytext = ""
131131
if self.pyversion is not None:
132-
pytext = " for Python %s" % self.pyversion
132+
pytext = f" for Python {self.pyversion}"
133133
if self.architecture is not None:
134134
if not pytext:
135135
pytext = " for Python"
136-
pytext += " %dbits" % self.architecture
137-
text += "%s\n%s\nWebsite: %s\n[%s]" % (
138-
pytext,
139-
self.description,
140-
self.url,
141-
Path(self.fname).name,
142-
)
136+
pytext += f" {self.architecture}bits"
137+
text += f"{pytext}\n{self.description}\nWebsite: {self.url}\n[{Path(self.fname).name}]"
143138
return text
144139

145140
def is_compatible_with(self, distribution):
@@ -205,7 +200,7 @@ def extract_infos(self):
205200
self.name, self.version = infos
206201
return
207202
raise NotImplementedError(
208-
"Not supported package type %s" % bname
203+
f"Not supported package type {bname}"
209204
)
210205

211206

@@ -227,7 +222,7 @@ def extract_infos(self):
227222
if match is None:
228223
return
229224
self.name = match.groups()[0]
230-
self.logname = '%s-wininst.log' % self.name
225+
self.logname = f'{self.name}-wininst.log'
231226
fd = open(
232227
str(Path(self.distribution.target) / self.logname),
233228
'U',
@@ -285,8 +280,7 @@ def clean_up(self):
285280
shutil.rmtree(path, onerror=utils.onerror)
286281
except WindowsError:
287282
print(
288-
"Directory %s could not be removed"
289-
% path,
283+
f"Directory {path} could not be removed",
290284
file=sys.stderr,
291285
)
292286

@@ -316,7 +310,7 @@ def copy_files(
316310
src = str(Path(srcdir) / t_dname)
317311
dst = str(Path(dstdir) / t_dname)
318312
if self.verbose:
319-
print("mkdir: %s" % dst)
313+
print(f"mkdir: {dst}")
320314
full_dst = str(Path(self.target) / dst)
321315
if not Path(full_dst).exists():
322316
os.mkdir(full_dst)
@@ -330,15 +324,15 @@ def copy_files(
330324
else:
331325
dst = str(Path(dstdir) / t_fname)
332326
if self.verbose:
333-
print("file: %s" % dst)
327+
print(f"file: {dst}")
334328
full_dst = str(Path(self.target) / dst)
335329
shutil.move(src, full_dst)
336330
package.files.append(dst)
337331
name, ext = Path(dst).stem, Path(dst).suffix
338332
if create_bat_files and ext in ('', '.py'):
339333
dst = name + '.bat'
340334
if self.verbose:
341-
print("file: %s" % dst)
335+
print(f"file: {dst}")
342336
full_dst = str(Path(self.target) / dst)
343337
fd = open(full_dst, 'w')
344338
fd.write(
@@ -354,7 +348,7 @@ def create_file(self, package, name, dstdir, contents):
354348
"""Generate data file -- path is relative to distribution root dir"""
355349
dst = str(Path(dstdir) / name)
356350
if self.verbose:
357-
print("create: %s" % dst)
351+
print(f"create: {dst}")
358352
full_dst = str(Path(self.target) / dst)
359353
open(full_dst, 'w').write(contents)
360354
package.files.append(dst)
@@ -386,8 +380,7 @@ def get_installed_packages(self, update=False):
386380
# create pip package list
387381
wppm = [
388382
Package(
389-
'%s-%s-py2.py3-none-any.whl'
390-
% (i[0].replace('-', '_').lower(), i[1])
383+
f"{i[0].replace('-', '_').lower()}-{i[1]}-py2.py3-none-any.whl"
391384
, update=update)
392385
for i in pip_list
393386
]
@@ -671,7 +664,7 @@ def handle_specific_packages(self, package):
671664
'.',
672665
contents.replace(
673666
'.',
674-
'./Lib/site-packages/%s' % package.name,
667+
f'./Lib/site-packages/{package.name}',
675668
),
676669
)
677670
# pyuic script
@@ -691,7 +684,7 @@ def handle_specific_packages(self, package):
691684

692685
self.create_file(
693686
package,
694-
'pyuic%s.bat' % package.name[-1],
687+
f'pyuic{package.name[-1]}.bat',
695688
'Scripts',
696689
tmp_string.replace(
697690
'package.name', package.name
@@ -754,7 +747,7 @@ def install_bdist_direct(
754747
"""Install a package directly !"""
755748
self._print(
756749
package,
757-
"Installing %s" % package.fname.split(".")[-1],
750+
f"Installing {package.fname.split('.')[-1]}",
758751
)
759752
try:
760753
fname = utils.direct_pip_install(
@@ -861,7 +854,7 @@ def main(test=False):
861854
dest='target',
862855
default=sys.prefix,
863856
help='path to target Python distribution '
864-
'(default: "%s")' % sys.prefix,
857+
f'(default: "{sys.prefix}")',
865858
)
866859
parser.add_argument(
867860
'-i',
@@ -948,7 +941,7 @@ def main(test=False):
948941
if utils.is_python_distribution(args.target):
949942
dist = Distribution(args.target)
950943
else:
951-
raise WindowsError("Invalid Python distribution {args.target}")
944+
raise WindowsError(f"Invalid Python distribution {args.target}")
952945
print(f'registering {args.target}')
953946
print('continue ? Y/N')
954947
theAnswer=input()
@@ -961,7 +954,7 @@ def main(test=False):
961954
if utils.is_python_distribution(args.target):
962955
dist = Distribution(args.target)
963956
else:
964-
raise WindowsError("Invalid Python distribution {args.target}")
957+
raise WindowsError(f"Invalid Python distribution {args.target}")
965958
print(f'unregistering {args.target}')
966959
print('continue ? Y/N')
967960
theAnswer=input()
@@ -976,7 +969,7 @@ def main(test=False):
976969
parser.print_help()
977970
sys.exit()
978971
else:
979-
raise IOError("File not found: %s" % args.fname)
972+
raise IOError(f"File not found: {args.fname}")
980973
if utils.is_python_distribution(args.target):
981974
dist = Distribution(args.target)
982975
try:
@@ -993,20 +986,15 @@ def main(test=False):
993986
else:
994987
raise RuntimeError(
995988
"Package is not compatible with Python "
996-
"%s %dbit"
997-
% (
998-
dist.version,
999-
dist.architecture,
1000-
)
989+
f"{dist.version} {dist.architecture}bit"
1001990
)
1002991
except NotImplementedError:
1003992
raise RuntimeError(
1004993
"Package is not (yet) supported by WPPM"
1005994
)
1006995
else:
1007996
raise WindowsError(
1008-
"Invalid Python distribution %s"
1009-
% args.target
997+
f"Invalid Python distribution {args.target}"
1010998
)
1011999

10121000

0 commit comments

Comments
 (0)