Skip to content

Commit 8352632

Browse files
committed
Replace old style strings with f-strings
1 parent b9630e8 commit 8352632

File tree

4 files changed

+17
-53
lines changed

4 files changed

+17
-53
lines changed

gvsbuild/utils/base_project.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def exec_msbuild(self, cmd, configuration=None, add_path=None):
207207
add_path=add_path,
208208
)
209209

210-
def _msbuild_make_search_replace(self, org_platform):
210+
def _msbuild_make_search_replace(self, org_platform: str) -> tuple[bytes, bytes]:
211211
"""Return the search & replace strings (converted to bytes to update
212212
the platform Toolset version (v140, v141, ...) to use a new compiler,
213213
e.g. to use vs2017 solution's files for vs2019.
@@ -226,7 +226,7 @@ def _msbuild_make_search_replace(self, org_platform):
226226
dst_platform = "143"
227227
else:
228228
dst_platform = f"{ver}0"
229-
search = (">v%u</PlatformToolset>" % (org_platform,)).encode("utf-8")
229+
search = f">v{org_platform}</PlatformToolset>".encode()
230230
replace = f">v{dst_platform}</PlatformToolset>".encode()
231231

232232
return search, replace

gvsbuild/utils/builder.py

+8-29
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def build(self, projects):
533533
if self.opts.check_hash:
534534
return
535535

536-
# List of all the project we can mark for build because of a dependend
536+
# List of all the project we can mark for build because of a dependent
537537
self.prj_to_mark = [x for x in Project._projects if x.is_project()]
538538

539539
self.prj_done = []
@@ -551,11 +551,7 @@ def build(self, projects):
551551
if self.__build_one(p):
552552
self.prj_skipped.append(p.name)
553553
else:
554-
msg = "%-*s (%.3f s)" % (
555-
Project.name_len,
556-
p.name,
557-
time.time() - st,
558-
)
554+
msg = f"{p.name:{Project.name_len}} ({time.time() - st:.3f})"
559555
self.prj_done.append(msg)
560556
except KeyboardInterrupt:
561557
traceback.print_exc()
@@ -597,8 +593,7 @@ def build(self, projects):
597593
log.message(f" {p}")
598594
miss += len(self.prj_dropped)
599595

600-
# Don't fool appveyor
601-
log.error_exit("%u project(s) missing ;(" % (miss,))
596+
log.error_exit("%d project(s) missing ;(")
602597

603598
log.close()
604599

@@ -798,21 +793,14 @@ def __download_progress(self, count, block_size, total_size):
798793
if perc != self._old_perc:
799794
perc = min(perc, 100)
800795
self._old_perc = perc
801-
sp = "%s (%u k) - %u%%" % (
802-
self._downloading_file,
803-
total_size / 1024,
804-
self._old_perc,
805-
)
796+
sp = f"{self._downloading_file} ({total_size / 1024}k) - {self._old_perc:.0f}%"
806797
print(sp, end="\r")
807798
if len(sp) > self._old_print:
808799
# Save the len to delete the line when we change file
809800
self._old_print = len(sp)
810801
else:
811802
# Only the current, we don't know the size
812-
sp = "%s - %u k" % (
813-
self._downloading_file,
814-
c_size / 1024,
815-
)
803+
sp = f"{self._downloading_file} - {c_size / 1024:.0f} k"
816804
print(sp, end="\r")
817805
if len(sp) > self._old_print:
818806
self._old_print = len(sp)
@@ -837,14 +825,7 @@ def urlretrieve(self, url, filename, reporthook, ssl_ignore_cert=False):
837825
msg = f"Opening {url} ..."
838826
print(msg, end="\r")
839827
with contextlib.closing(urlopen(url, None, context=ssl_ctx)) as fp:
840-
print(
841-
"%*s"
842-
% (
843-
len(msg),
844-
"",
845-
),
846-
end="\r",
847-
)
828+
print(f"{'':>{len(msg)}}", end="\r")
848829
headers = fp.info()
849830

850831
with open(filename, "wb") as tfp:
@@ -870,7 +851,7 @@ def urlretrieve(self, url, filename, reporthook, ssl_ignore_cert=False):
870851

871852
if size >= 0 and read < size:
872853
raise ContentTooShortError(
873-
"retrieval incomplete: got only %i out of %i bytes" % (read, size),
854+
f"retrieval incomplete: got only {read} out of {size} bytes",
874855
result,
875856
)
876857

@@ -920,9 +901,7 @@ def __download_one(self, proj):
920901
raise
921902
log.end()
922903

923-
print(
924-
"%-*s" % (self._old_print, f"{proj.archive_file} - Download finished"),
925-
)
904+
print(f"{proj.archive_file:{self._old_print}} - Download finished")
926905
return self.__check_hash(proj)
927906

928907
def __sub_vars(self, s):

gvsbuild/utils/simple_ui.py

+4-21
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,9 @@ def _create_log(self, file_path, single, max_size_kb, opts):
131131
self._output_val("Vs path", opts.vs_install_path)
132132
self._output_val("Sdk ver", opts.win_sdk_ver)
133133

134-
def _get_delta(self, start, end=None):
135-
if not end:
136-
end = datetime.datetime.now()
134+
def _get_delta(self, start):
137135
dt = datetime.datetime.now() - start
138-
return "%u.%03u" % (
139-
dt.seconds,
140-
dt.microseconds / 1000,
141-
)
136+
return f"{dt.seconds}.{dt.microseconds // 1000:03}"
142137

143138
def _indend_check(self):
144139
if self.operations:
@@ -205,27 +200,15 @@ def _output(self, msg, add_date=True, check_indent=True):
205200
now_val = datetime.datetime.now()
206201
self.fo.write(f"{now_val.strftime('%Y-%m-%d %H:%M:%S')} {msg}\n")
207202
else:
208-
self.fo.write(
209-
"%19s %s\n"
210-
% (
211-
"",
212-
msg,
213-
)
214-
)
203+
self.fo.write(f"{msg:<20}")
215204
return False
216205
else:
217206
print(msg)
218207
# tell the caller we already print on video
219208
return True
220209

221210
def _output_val(self, msg, val):
222-
self._output(
223-
"%16s: %s"
224-
% (
225-
msg,
226-
val,
227-
)
228-
)
211+
self._output(f"{msg:<16}: {val}")
229212

230213
def message_indent(self, msg):
231214
if self._output(msg, add_date=False):

tests/test_build.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def test_no_project(typer_app, runner):
3535
assert "Missing argument" in result.output
3636

3737

38-
@pytest.mark.skipif(not sys.platform.startswith("win"), reason="windll only available on Windows")
38+
@pytest.mark.skipif(
39+
not sys.platform.startswith("win"), reason="windll only available on Windows"
40+
)
3941
def test_platform(tmp_dir, typer_app, runner):
4042
assert tmp_dir.exists()
4143
result = runner.invoke(

0 commit comments

Comments
 (0)