@@ -60,7 +60,7 @@ def __init__(
60
60
if single_doc and single_doc .endswith (".rst" ):
61
61
self .single_doc_html = os .path .splitext (single_doc )[0 ] + ".html"
62
62
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"
64
64
65
65
def _process_single_doc (self , single_doc ):
66
66
"""
@@ -76,25 +76,23 @@ def _process_single_doc(self, single_doc):
76
76
if os .path .exists (os .path .join (SOURCE_PATH , single_doc )):
77
77
return single_doc
78
78
else :
79
- raise FileNotFoundError ("File {} not found" . format ( single_doc ) )
79
+ raise FileNotFoundError (f "File { single_doc } not found" )
80
80
81
81
elif single_doc .startswith ("pandas." ):
82
82
try :
83
83
obj = pandas # noqa: F821
84
84
for name in single_doc .split ("." ):
85
85
obj = getattr (obj , name )
86
86
except AttributeError :
87
- raise ImportError ("Could not import {}" . format ( single_doc ) )
87
+ raise ImportError (f "Could not import { single_doc } " )
88
88
else :
89
89
return single_doc [len ("pandas." ) :]
90
90
else :
91
91
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)"
98
96
)
99
97
100
98
@staticmethod
@@ -113,7 +111,7 @@ def _run_os(*args):
113
111
"""
114
112
subprocess .check_call (args , stdout = sys .stdout , stderr = sys .stderr )
115
113
116
- def _sphinx_build (self , kind ):
114
+ def _sphinx_build (self , kind : str ):
117
115
"""
118
116
Call sphinx to build documentation.
119
117
@@ -128,15 +126,15 @@ def _sphinx_build(self, kind):
128
126
>>> DocBuilder(num_jobs=4)._sphinx_build('html')
129
127
"""
130
128
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 } " )
132
130
133
131
cmd = ["sphinx-build" , "-b" , kind ]
134
132
if self .num_jobs :
135
133
cmd += ["-j" , str (self .num_jobs )]
136
134
if self .warnings_are_errors :
137
135
cmd += ["-W" , "--keep-going" ]
138
136
if self .verbosity :
139
- cmd .append ("-{}" . format ( "v" * self .verbosity ) )
137
+ cmd .append (f "-{ 'v' * self .verbosity } " )
140
138
cmd += [
141
139
"-d" ,
142
140
os .path .join (BUILD_PATH , "doctrees" ),
@@ -156,7 +154,7 @@ def _get_page_title(self, page):
156
154
"""
157
155
Open the rst file `page` and extract its title.
158
156
"""
159
- fname = os .path .join (SOURCE_PATH , "{ }.rst". format ( page ) )
157
+ fname = os .path .join (SOURCE_PATH , f" { page } .rst" )
160
158
option_parser = docutils .frontend .OptionParser (
161
159
components = (docutils .parsers .rst .Parser ,)
162
160
)
@@ -184,18 +182,6 @@ def _add_redirects(self):
184
182
Create in the build directory an html file with a redirect,
185
183
for every row in REDIRECTS_FILE.
186
184
"""
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
- """
199
185
with open (REDIRECTS_FILE ) as mapping_fd :
200
186
reader = csv .reader (mapping_fd )
201
187
for row in reader :
@@ -214,15 +200,23 @@ def _add_redirects(self):
214
200
215
201
if os .path .exists (path ):
216
202
raise RuntimeError (
217
- ("Redirection would overwrite an existing file: " "{}" ).format (
218
- path
219
- )
203
+ f"Redirection would overwrite an existing file: { path } "
220
204
)
221
205
222
206
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 )
226
220
227
221
def html (self ):
228
222
"""
@@ -290,15 +284,14 @@ def zip_html(self):
290
284
def main ():
291
285
cmds = [method for method in dir (DocBuilder ) if not method .startswith ("_" )]
292
286
287
+ joined = "," .join (cmds )
293
288
argparser = argparse .ArgumentParser (
294
- description = "pandas documentation builder" ,
295
- epilog = "Commands: {}" .format ("," .join (cmds )),
289
+ description = "pandas documentation builder" , epilog = f"Commands: { joined } " ,
296
290
)
291
+
292
+ joined = ", " .join (cmds )
297
293
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 } " ,
302
295
)
303
296
argparser .add_argument (
304
297
"--num-jobs" , type = int , default = 0 , help = "number of jobs used by sphinx-build"
@@ -312,10 +305,9 @@ def main():
312
305
type = str ,
313
306
default = None ,
314
307
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'"
319
311
),
320
312
)
321
313
argparser .add_argument (
@@ -340,11 +332,8 @@ def main():
340
332
args = argparser .parse_args ()
341
333
342
334
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 } " )
348
337
349
338
# Below we update both os.environ and sys.path. The former is used by
350
339
# external libraries (namely Sphinx) to compile this module and resolve
0 commit comments