Skip to content

Commit ac344c6

Browse files
twsltimvink
authored andcommitted
Use f-string
1 parent 0b3cf36 commit ac344c6

File tree

4 files changed

+47
-49
lines changed

4 files changed

+47
-49
lines changed

mkdocs_git_authors_plugin/git/command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def run(self) -> int:
6969
p.check_returncode()
7070
except subprocess.CalledProcessError:
7171
msg = ["GitCommand error:"]
72-
msg.append('Command "%s" failed' % " ".join(args))
73-
msg.append("Return code: %s" % p.returncode)
72+
msg.append(f'Command "{' '.join(args)}" failed')
73+
msg.append(f"Return code: {p.returncode}")
7474
msg.append("Output:")
7575
msg.append(p.stdout.decode("utf-8"))
7676
msg.append("Error messages:")

mkdocs_git_authors_plugin/git/page.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ def __init__(self, repo: Repo, path: Path, strict: bool) -> None:
3838
except GitCommandError:
3939
if self._strict:
4040
logger.warning(
41-
"[git-authors-plugin] %s has not been committed yet. Lines are not counted"
42-
% path
41+
f"[git-authors-plugin] {path} has not been committed yet. Lines are not counted"
4342
)
4443
else:
4544
logger.info(
46-
"[git-authors-plugin] %s has not been committed yet. Lines are not counted"
47-
% path
45+
f"[git-authors-plugin] {path} has not been committed yet. Lines are not counted"
4846
)
4947

5048
def add_total_lines(self, cnt: int = 1) -> None:

mkdocs_git_authors_plugin/util.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def page_authors_summary(page, config: dict) -> str:
5757

5858
for author in authors:
5959
contrib = (
60-
" (%s)" % author.contribution(page.path(), str)
60+
f" ({author.contribution(page.path(), str)})"
6161
if page.repo().config("show_contribution") and len(page.get_authors()) > 1
6262
else ""
6363
)
@@ -67,13 +67,13 @@ def page_authors_summary(page, config: dict) -> str:
6767
.config("href")
6868
.format(email=author.email(), name=author.name())
6969
)
70-
author_name = "<a href='%s'>%s</a>" % (href, author.name())
70+
author_name = f"<a href='{href}'>{author.name()}</a>"
7171
else:
7272
author_name = author.name()
73-
authors_summary.append("%s%s" % (author_name, contrib))
73+
authors_summary.append(f"{author_name}{contrib}")
7474

7575
authors_summary_str = ", ".join(authors_summary)
76-
return "<span class='git-page-authors git-authors'>%s</span>" % authors_summary_str
76+
return f"<span class='git-page-authors git-authors'>{authors_summary_str}</span>"
7777

7878

7979
def site_authors_summary(authors, config: GitAuthorsPluginConfig) -> str:
@@ -104,13 +104,13 @@ def site_authors_summary(authors, config: GitAuthorsPluginConfig) -> str:
104104
"""
105105
for author in authors:
106106
contribution = (
107-
" (%s)" % author.contribution(None, str) if config.show_contribution else ""
107+
f" ({author.contribution(None, str)})" if config.show_contribution else ""
108108
)
109-
lines = ": %s lines" % author.lines() if config.show_line_count else ""
109+
lines = f": {author.lines()} lines" if config.show_line_count else ""
110110
author_name = ""
111111
if config.show_email_address:
112112
href = config["href"].format(email=author.email(), name=author.name())
113-
author_name = '<a href="%s">%s</a>' % (href, author.name())
113+
author_name = f'<a href="{href}">{author.name()}</a>'
114114
else:
115115
author_name = author.name()
116116
result += """

tests/test_basic.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ def test_basic_working(tmp_path, mkdocs_file: str) -> None:
8181
See https://github.com/timvink/mkdocs-git-authors-plugin/issues/60
8282
"""
8383
result = build_docs_setup(f"tests/basic_setup/{mkdocs_file}", tmp_path)
84-
assert result.exit_code == 0, (
85-
"'mkdocs build' command failed. Error: %s" % result.stdout
86-
)
84+
assert (
85+
result.exit_code == 0
86+
), f"'mkdocs build' command failed. Error: {result.stdout}"
8787

8888
index_file = tmp_path / "index.html"
89-
assert index_file.exists(), "%s does not exist" % index_file
89+
assert index_file.exists(), f"{index_file} does not exist"
9090

9191
contents = index_file.read_text()
9292
assert re.search("<span class='git-page-authors", contents)
@@ -96,12 +96,12 @@ def test_basic_working(tmp_path, mkdocs_file: str) -> None:
9696
def test_custom_href(tmp_path) -> None:
9797
""" """
9898
result = build_docs_setup("tests/basic_setup/mkdocs_custom_href.yml", tmp_path)
99-
assert result.exit_code == 0, (
100-
"'mkdocs build' command failed. Error: %s" % result.stdout
101-
)
99+
assert (
100+
result.exit_code == 0
101+
), f"'mkdocs build' command failed. Error: {result.stdout}"
102102

103103
index_file = tmp_path / "index.html"
104-
assert index_file.exists(), "%s does not exist" % index_file
104+
assert index_file.exists(), f"{index_file} does not exist"
105105

106106
contents = index_file.read_text()
107107
assert re.search("<span class='git-page-authors", contents)
@@ -121,12 +121,12 @@ def test_custom_href(tmp_path) -> None:
121121

122122
def test_no_email(tmp_path) -> None:
123123
result = build_docs_setup("tests/basic_setup/mkdocs_no_email.yml", tmp_path)
124-
assert result.exit_code == 0, (
125-
"'mkdocs build' command failed. Error: %s" % result.stdout
126-
)
124+
assert (
125+
result.exit_code == 0
126+
), f"'mkdocs build' command failed. Error: {result.stdout}"
127127

128128
index_file = tmp_path / "index.html"
129-
assert index_file.exists(), "%s does not exist" % index_file
129+
assert index_file.exists(), f"{index_file} does not exist"
130130

131131
contents = index_file.read_text()
132132
assert re.search("<span class='git-page-authors", contents)
@@ -135,25 +135,25 @@ def test_no_email(tmp_path) -> None:
135135

136136
def test_exclude_working(tmp_path) -> None:
137137
result = build_docs_setup("tests/basic_setup/mkdocs_exclude.yml", tmp_path)
138-
assert result.exit_code == 0, (
139-
"'mkdocs build' command failed. Error: %s" % result.stdout
140-
)
138+
assert (
139+
result.exit_code == 0
140+
), f"'mkdocs build' command failed. Error: {result.stdout}"
141141

142142
page_file = tmp_path / "page_with_tag/index.html"
143-
assert page_file.exists(), "%s does not exist" % page_file
143+
assert page_file.exists(), f"{page_file} does not exist"
144144

145145
contents = page_file.read_text()
146146
assert not re.search("<span class='git-page-authors", contents)
147147

148148

149149
def test_ignore_authors_working(tmp_path) -> None:
150150
result = build_docs_setup("tests/basic_setup/mkdocs_ignore_authors.yml", tmp_path)
151-
assert result.exit_code == 0, (
152-
"'mkdocs build' command failed. Error: %s" % result.stdout
153-
)
151+
assert (
152+
result.exit_code == 0
153+
), f"'mkdocs build' command failed. Error: {result.stdout}"
154154

155155
page_file = tmp_path / "page_with_tag/index.html"
156-
assert page_file.exists(), "%s does not exist" % page_file
156+
assert page_file.exists(), f"{page_file} does not exist"
157157

158158
contents = page_file.read_text()
159159
assert re.search("<span class='git-page-authors", contents)
@@ -197,9 +197,9 @@ def test_exclude_working_with_genfiles(tmp_path) -> None:
197197
result = build_docs_setup(
198198
str(testproject_path / "mkdocs.yml"), str(testproject_path / "site")
199199
)
200-
assert result.exit_code == 0, (
201-
"'mkdocs build' command failed. Error: %s" % result.stdout
202-
)
200+
assert (
201+
result.exit_code == 0
202+
), f"'mkdocs build' command failed. Error: { result.stdout}"
203203

204204
# files generated ourselves right before build but not committed, should not generate warnings
205205
assert "manually_created.md has not been committed yet." not in result.stdout
@@ -213,12 +213,12 @@ def test_enabled_working(tmp_path) -> None:
213213
result = build_docs_setup(
214214
"tests/basic_setup/mkdocs_complete_material_disabled.yml", tmp_path
215215
)
216-
assert result.exit_code == 0, (
217-
"'mkdocs build' command failed. Error: %s" % result.stdout
218-
)
216+
assert (
217+
result.exit_code == 0
218+
), f"'mkdocs build' command failed. Error: {result.stdout}"
219219

220220
page_file = tmp_path / "page_with_tag/index.html"
221-
assert page_file.exists(), "%s does not exist" % page_file
221+
assert page_file.exists(), f"{page_file} does not exist"
222222

223223
contents = page_file.read_text()
224224
assert not re.search("<span class='git-page-authors", contents)
@@ -249,9 +249,9 @@ def test_project_with_no_commits(tmp_path) -> None:
249249
result = build_docs_setup(
250250
str(testproject_path / "website/mkdocs.yml"), str(testproject_path / "site")
251251
)
252-
assert result.exit_code == 0, (
253-
"'mkdocs build' command failed. Error: %s" % result.stdout
254-
)
252+
assert (
253+
result.exit_code == 0
254+
), f"'mkdocs build' command failed. Error: {result.stdout}"
255255

256256

257257
def test_building_empty_site(tmp_path) -> None:
@@ -282,9 +282,9 @@ def test_building_empty_site(tmp_path) -> None:
282282
result = build_docs_setup(
283283
str(testproject_path / "website/mkdocs.yml"), str(testproject_path / "site")
284284
)
285-
assert result.exit_code == 0, (
286-
"'mkdocs build' command failed. Error: %s" % result.stdout
287-
)
285+
assert (
286+
result.exit_code == 0
287+
), f"'mkdocs build' command failed. Error: {result.stdout}"
288288

289289

290290
def test_fallback(tmp_path) -> None:
@@ -313,6 +313,6 @@ def test_fallback(tmp_path) -> None:
313313
str(testproject_path / "website/mkdocs.yml"), str(testproject_path / "site")
314314
)
315315
# import pdb; pdb.set_trace()
316-
assert result.exit_code == 0, (
317-
"'mkdocs build' command failed. Error: %s" % result.stdout
318-
)
316+
assert (
317+
result.exit_code == 0
318+
), f"'mkdocs build' command failed. Error: {result.stdout}"

0 commit comments

Comments
 (0)