From 4b5ada8d0a2891f9b84e8cdf956010074099ab82 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Wed, 4 Dec 2019 21:08:11 +0200 Subject: [PATCH 1/3] Fstrings --- doc/make.py | 89 +++++++++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 50 deletions(-) diff --git a/doc/make.py b/doc/make.py index cbb1fa6a5324a..7d76533bc74b8 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. " + f"Value should be a valid path to a .rst or .ipynb file, " + f"or a valid pandas object " + f"(e.g. categorical.rst or pandas.DataFrame.head)" ) @staticmethod @@ -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,21 +284,23 @@ def zip_html(self): def main(): cmds = [method for method in dir(DocBuilder) if not method.startswith("_")] + joined = ",".join(cmds) + joined_epilog = f"Commands: {joined}" + + joined_cmds = ", ".join(cmds) + argparser = argparse.ArgumentParser( - description="pandas documentation builder", - epilog="Commands: {}".format(",".join(cmds)), + description="pandas documentation builder", epilog=joined_epilog, ) + argparser.add_argument( - "command", - nargs="?", - default="html", - help="command to run: {}".format(", ".join(cmds)), + "command", nargs="?", default="html", help=f"command to run: {joined_cmds}", ) argparser.add_argument( "--num-jobs", type=int, default=0, help="number of jobs used by sphinx-build" ) argparser.add_argument( - "--no-api", default=False, help="omit api and autosummary", action="store_true" + "--no-api", default=False, action="store_true", help="omit api and autosummary" ) argparser.add_argument( "--single", @@ -312,10 +308,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( @@ -326,10 +321,7 @@ def main(): action="count", dest="verbosity", default=0, - help=( - "increase verbosity (can be repeated), " - "passed to the sphinx build command" - ), + help="increase verbosity (can be repeated), passed to the sphinx build command", ) argparser.add_argument( "--warnings-are-errors", @@ -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 From efd1ee6ed16bd0427c844c214785a50c08a66fd6 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <> Date: Wed, 4 Dec 2019 22:02:32 +0200 Subject: [PATCH 2/3] STY: f-strings --- doc/make.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/make.py b/doc/make.py index 7d76533bc74b8..168def753b4f1 100755 --- a/doc/make.py +++ b/doc/make.py @@ -111,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. @@ -285,22 +285,19 @@ def main(): cmds = [method for method in dir(DocBuilder) if not method.startswith("_")] joined = ",".join(cmds) - joined_epilog = f"Commands: {joined}" - - joined_cmds = ", ".join(cmds) - argparser = argparse.ArgumentParser( - description="pandas documentation builder", epilog=joined_epilog, + description="pandas documentation builder", epilog=f"Commands: {joined}", ) + joined = ", ".join(cmds) argparser.add_argument( - "command", nargs="?", default="html", help=f"command to run: {joined_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" ) argparser.add_argument( - "--no-api", default=False, action="store_true", help="omit api and autosummary" + "--no-api", default=False, help="omit api and autosummary", action="store_true" ) argparser.add_argument( "--single", @@ -321,7 +318,10 @@ def main(): action="count", dest="verbosity", default=0, - help="increase verbosity (can be repeated), passed to the sphinx build command", + help=( + "increase verbosity (can be repeated), " + "passed to the sphinx build command" + ), ) argparser.add_argument( "--warnings-are-errors", From ae3a2e12ab301d2bc1005fd96351d7d2dc9d1c60 Mon Sep 17 00:00:00 2001 From: MomIsBestFriend <50263213+MomIsBestFriend@users.noreply.github.com> Date: Thu, 5 Dec 2019 01:23:19 +0200 Subject: [PATCH 3/3] Update make.py --- doc/make.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/make.py b/doc/make.py index 168def753b4f1..cf73f44b5dd02 100755 --- a/doc/make.py +++ b/doc/make.py @@ -90,9 +90,9 @@ def _process_single_doc(self, single_doc): else: raise ValueError( f"--single={single_doc} not understood. " - f"Value should be a valid path to a .rst or .ipynb file, " - f"or a valid pandas object " - f"(e.g. categorical.rst or pandas.DataFrame.head)" + "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