Skip to content

Commit 4abc23e

Browse files
ShaharNavehjreback
authored andcommitted
STY: fstrings doc/make.py (#30060)
1 parent 1078363 commit 4abc23e

File tree

1 file changed

+35
-46
lines changed

1 file changed

+35
-46
lines changed

doc/make.py

+35-46
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __init__(
6060
if single_doc and single_doc.endswith(".rst"):
6161
self.single_doc_html = os.path.splitext(single_doc)[0] + ".html"
6262
elif single_doc:
63-
self.single_doc_html = "reference/api/pandas.{}.html".format(single_doc)
63+
self.single_doc_html = f"reference/api/pandas.{single_doc}.html"
6464

6565
def _process_single_doc(self, single_doc):
6666
"""
@@ -76,25 +76,23 @@ def _process_single_doc(self, single_doc):
7676
if os.path.exists(os.path.join(SOURCE_PATH, single_doc)):
7777
return single_doc
7878
else:
79-
raise FileNotFoundError("File {} not found".format(single_doc))
79+
raise FileNotFoundError(f"File {single_doc} not found")
8080

8181
elif single_doc.startswith("pandas."):
8282
try:
8383
obj = pandas # noqa: F821
8484
for name in single_doc.split("."):
8585
obj = getattr(obj, name)
8686
except AttributeError:
87-
raise ImportError("Could not import {}".format(single_doc))
87+
raise ImportError(f"Could not import {single_doc}")
8888
else:
8989
return single_doc[len("pandas.") :]
9090
else:
9191
raise ValueError(
92-
(
93-
"--single={} not understood. Value should be a "
94-
"valid path to a .rst or .ipynb file, or a "
95-
"valid pandas object (e.g. categorical.rst or "
96-
"pandas.DataFrame.head)"
97-
).format(single_doc)
92+
f"--single={single_doc} not understood. "
93+
"Value should be a valid path to a .rst or .ipynb file, "
94+
"or a valid pandas object "
95+
"(e.g. categorical.rst or pandas.DataFrame.head)"
9896
)
9997

10098
@staticmethod
@@ -113,7 +111,7 @@ def _run_os(*args):
113111
"""
114112
subprocess.check_call(args, stdout=sys.stdout, stderr=sys.stderr)
115113

116-
def _sphinx_build(self, kind):
114+
def _sphinx_build(self, kind: str):
117115
"""
118116
Call sphinx to build documentation.
119117
@@ -128,15 +126,15 @@ def _sphinx_build(self, kind):
128126
>>> DocBuilder(num_jobs=4)._sphinx_build('html')
129127
"""
130128
if kind not in ("html", "latex"):
131-
raise ValueError("kind must be html or latex, " "not {}".format(kind))
129+
raise ValueError(f"kind must be html or latex, not {kind}")
132130

133131
cmd = ["sphinx-build", "-b", kind]
134132
if self.num_jobs:
135133
cmd += ["-j", str(self.num_jobs)]
136134
if self.warnings_are_errors:
137135
cmd += ["-W", "--keep-going"]
138136
if self.verbosity:
139-
cmd.append("-{}".format("v" * self.verbosity))
137+
cmd.append(f"-{'v' * self.verbosity}")
140138
cmd += [
141139
"-d",
142140
os.path.join(BUILD_PATH, "doctrees"),
@@ -156,7 +154,7 @@ def _get_page_title(self, page):
156154
"""
157155
Open the rst file `page` and extract its title.
158156
"""
159-
fname = os.path.join(SOURCE_PATH, "{}.rst".format(page))
157+
fname = os.path.join(SOURCE_PATH, f"{page}.rst")
160158
option_parser = docutils.frontend.OptionParser(
161159
components=(docutils.parsers.rst.Parser,)
162160
)
@@ -184,18 +182,6 @@ def _add_redirects(self):
184182
Create in the build directory an html file with a redirect,
185183
for every row in REDIRECTS_FILE.
186184
"""
187-
html = """
188-
<html>
189-
<head>
190-
<meta http-equiv="refresh" content="0;URL={url}"/>
191-
</head>
192-
<body>
193-
<p>
194-
The page has been moved to <a href="{url}">{title}</a>
195-
</p>
196-
</body>
197-
<html>
198-
"""
199185
with open(REDIRECTS_FILE) as mapping_fd:
200186
reader = csv.reader(mapping_fd)
201187
for row in reader:
@@ -214,15 +200,23 @@ def _add_redirects(self):
214200

215201
if os.path.exists(path):
216202
raise RuntimeError(
217-
("Redirection would overwrite an existing file: " "{}").format(
218-
path
219-
)
203+
f"Redirection would overwrite an existing file: {path}"
220204
)
221205

222206
with open(path, "w") as moved_page_fd:
223-
moved_page_fd.write(
224-
html.format(url="{}.html".format(row[1]), title=title)
225-
)
207+
html = f"""\
208+
<html>
209+
<head>
210+
<meta http-equiv="refresh" content="0;URL={row[1]}.html"/>
211+
</head>
212+
<body>
213+
<p>
214+
The page has been moved to <a href="{row[1]}.html">{title}</a>
215+
</p>
216+
</body>
217+
<html>"""
218+
219+
moved_page_fd.write(html)
226220

227221
def html(self):
228222
"""
@@ -290,15 +284,14 @@ def zip_html(self):
290284
def main():
291285
cmds = [method for method in dir(DocBuilder) if not method.startswith("_")]
292286

287+
joined = ",".join(cmds)
293288
argparser = argparse.ArgumentParser(
294-
description="pandas documentation builder",
295-
epilog="Commands: {}".format(",".join(cmds)),
289+
description="pandas documentation builder", epilog=f"Commands: {joined}",
296290
)
291+
292+
joined = ", ".join(cmds)
297293
argparser.add_argument(
298-
"command",
299-
nargs="?",
300-
default="html",
301-
help="command to run: {}".format(", ".join(cmds)),
294+
"command", nargs="?", default="html", help=f"command to run: {joined}",
302295
)
303296
argparser.add_argument(
304297
"--num-jobs", type=int, default=0, help="number of jobs used by sphinx-build"
@@ -312,10 +305,9 @@ def main():
312305
type=str,
313306
default=None,
314307
help=(
315-
'filename (relative to the "source" folder)'
316-
" of section or method name to compile, e.g. "
317-
'"development/contributing.rst",'
318-
' "ecosystem.rst", "pandas.DataFrame.join"'
308+
"filename (relative to the 'source' folder) of section or method name to "
309+
"compile, e.g. 'development/contributing.rst', "
310+
"'ecosystem.rst', 'pandas.DataFrame.join'"
319311
),
320312
)
321313
argparser.add_argument(
@@ -340,11 +332,8 @@ def main():
340332
args = argparser.parse_args()
341333

342334
if args.command not in cmds:
343-
raise ValueError(
344-
"Unknown command {}. Available options: {}".format(
345-
args.command, ", ".join(cmds)
346-
)
347-
)
335+
joined = ", ".join(cmds)
336+
raise ValueError(f"Unknown command {args.command}. Available options: {joined}")
348337

349338
# Below we update both os.environ and sys.path. The former is used by
350339
# external libraries (namely Sphinx) to compile this module and resolve

0 commit comments

Comments
 (0)