diff --git a/doc/make.py b/doc/make.py index cbb1fa6a5324a..cf73f44b5dd02 100755 --- a/doc/make.py +++ b/doc/make.py @@ -60,7 +60,7 @@ def __init__( if single_doc and single_doc.endswith(".rst"): self.single_doc_html = os.path.splitext(single_doc)[0] + ".html" elif single_doc: - self.single_doc_html = "reference/api/pandas.{}.html".format(single_doc) + self.single_doc_html = f"reference/api/pandas.{single_doc}.html" def _process_single_doc(self, single_doc): """ @@ -76,7 +76,7 @@ def _process_single_doc(self, single_doc): if os.path.exists(os.path.join(SOURCE_PATH, single_doc)): return single_doc else: - raise FileNotFoundError("File {} not found".format(single_doc)) + raise FileNotFoundError(f"File {single_doc} not found") elif single_doc.startswith("pandas."): try: @@ -84,17 +84,15 @@ def _process_single_doc(self, single_doc): for name in single_doc.split("."): obj = getattr(obj, name) except AttributeError: - raise ImportError("Could not import {}".format(single_doc)) + raise ImportError(f"Could not import {single_doc}") else: return single_doc[len("pandas.") :] else: raise ValueError( - ( - "--single={} not understood. Value should be a " - "valid path to a .rst or .ipynb file, or a " - "valid pandas object (e.g. categorical.rst or " - "pandas.DataFrame.head)" - ).format(single_doc) + f"--single={single_doc} not understood. " + "Value should be a valid path to a .rst or .ipynb file, " + "or a valid pandas object " + "(e.g. categorical.rst or pandas.DataFrame.head)" ) @staticmethod @@ -113,7 +111,7 @@ def _run_os(*args): """ subprocess.check_call(args, stdout=sys.stdout, stderr=sys.stderr) - def _sphinx_build(self, kind): + def _sphinx_build(self, kind: str): """ Call sphinx to build documentation. @@ -128,7 +126,7 @@ def _sphinx_build(self, kind): >>> DocBuilder(num_jobs=4)._sphinx_build('html') """ if kind not in ("html", "latex"): - raise ValueError("kind must be html or latex, " "not {}".format(kind)) + raise ValueError(f"kind must be html or latex, not {kind}") cmd = ["sphinx-build", "-b", kind] if self.num_jobs: @@ -136,7 +134,7 @@ def _sphinx_build(self, kind): if self.warnings_are_errors: cmd += ["-W", "--keep-going"] if self.verbosity: - cmd.append("-{}".format("v" * self.verbosity)) + cmd.append(f"-{'v' * self.verbosity}") cmd += [ "-d", os.path.join(BUILD_PATH, "doctrees"), @@ -156,7 +154,7 @@ def _get_page_title(self, page): """ Open the rst file `page` and extract its title. """ - fname = os.path.join(SOURCE_PATH, "{}.rst".format(page)) + fname = os.path.join(SOURCE_PATH, f"{page}.rst") option_parser = docutils.frontend.OptionParser( components=(docutils.parsers.rst.Parser,) ) @@ -184,18 +182,6 @@ def _add_redirects(self): Create in the build directory an html file with a redirect, for every row in REDIRECTS_FILE. """ - html = """ - -
- - - -- The page has been moved to {title} -
- - - """ with open(REDIRECTS_FILE) as mapping_fd: reader = csv.reader(mapping_fd) for row in reader: @@ -214,15 +200,23 @@ def _add_redirects(self): if os.path.exists(path): raise RuntimeError( - ("Redirection would overwrite an existing file: " "{}").format( - path - ) + f"Redirection would overwrite an existing file: {path}" ) with open(path, "w") as moved_page_fd: - moved_page_fd.write( - html.format(url="{}.html".format(row[1]), title=title) - ) + html = f"""\ + + + + + ++ The page has been moved to {title} +
+ +""" + + moved_page_fd.write(html) def html(self): """ @@ -290,15 +284,14 @@ def zip_html(self): def main(): cmds = [method for method in dir(DocBuilder) if not method.startswith("_")] + joined = ",".join(cmds) argparser = argparse.ArgumentParser( - description="pandas documentation builder", - epilog="Commands: {}".format(",".join(cmds)), + description="pandas documentation builder", epilog=f"Commands: {joined}", ) + + joined = ", ".join(cmds) argparser.add_argument( - "command", - nargs="?", - default="html", - help="command to run: {}".format(", ".join(cmds)), + "command", nargs="?", default="html", help=f"command to run: {joined}", ) argparser.add_argument( "--num-jobs", type=int, default=0, help="number of jobs used by sphinx-build" @@ -312,10 +305,9 @@ def main(): type=str, default=None, help=( - 'filename (relative to the "source" folder)' - " of section or method name to compile, e.g. " - '"development/contributing.rst",' - ' "ecosystem.rst", "pandas.DataFrame.join"' + "filename (relative to the 'source' folder) of section or method name to " + "compile, e.g. 'development/contributing.rst', " + "'ecosystem.rst', 'pandas.DataFrame.join'" ), ) argparser.add_argument( @@ -340,11 +332,8 @@ def main(): args = argparser.parse_args() if args.command not in cmds: - raise ValueError( - "Unknown command {}. Available options: {}".format( - args.command, ", ".join(cmds) - ) - ) + joined = ", ".join(cmds) + raise ValueError(f"Unknown command {args.command}. Available options: {joined}") # Below we update both os.environ and sys.path. The former is used by # external libraries (namely Sphinx) to compile this module and resolve