prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Don't auto-add inline links to ref section & rm if empty, per #2130
  First step to implementing #2130 , as agreed with @gvanrossum and the PEP editor team.
  
  When building, don't add redundant footnotes and references entries for URLs that are already directly linked inline. This avoids an unnecessary, potentially confusing footnote for each link, and taking up additional space in the references section for no real benefit, plus simplifies the build code and should improve build time, especially for Sphinx. Furthermore, if the references section is empty (not including now-invisible link targets), remove it, as we did before (but in a more robust manner). This allows past and future PEPs to still use inline references with targets stored in the references section, while avoiding showing a now-empty references section.
  
  These are both implemented for Sphinx and the legacy builder, and I visually inspected a variety of PEPs with various cases with both builders to ensure the desired results were achieved, and there were no obvious side effects from this change.
  
  Following merging this PR, following the plan outlined in #2130 , I'll proceed with one updating the meta-PEP docs in PEP 0, PEP 1 and PEP 12 to reflect the revised policy of using standard reST links (inline or with separate targets) rather than the references section, and follow that with a PR updating the relative handful of references in the other active meta-PEPs, for consistency.
  
  </issue>
  <code>
  [start of pep_sphinx_extensions/pep_processor/transforms/pep_footer.py]
  1 import datetime
  2 from pathlib import Path
  3 import subprocess
  4 
  5 from docutils import nodes
  6 from docutils import transforms
  7 
  8 
  9 class PEPFooter(transforms.Transform):
  10     """Footer transforms for PEPs.
  11 
  12      - Removes the References section if it is empty when rendered.
  13      - Creates a link to the (GitHub) source text.
  14 
  15     Source Link:
  16         Create the link to the source file from the document source path,
  17         and append the text to the end of the document.
  18 
  19     """
  20 
  21     # Uses same priority as docutils.transforms.TargetNotes
  22     default_priority = 520
  23 
  24     def apply(self) -> None:
  25         pep_source_path = Path(self.document["source"])
  26         if not pep_source_path.match("pep-*"):
  27             return  # not a PEP file, exit early
  28 
  29         # Iterate through sections from the end of the document
  30         for section in reversed(self.document[0]):
  31             if not isinstance(section, nodes.section):
  32                 continue
  33             title_words = section[0].astext().lower().split()
  34             if "references" in title_words:
  35                 # Remove references section if there are no displayed
  36                 # footnotes (it only has title & link target nodes)
  37                 if all(isinstance(ref_node, (nodes.title, nodes.target))
  38                        for ref_node in section):
  39                     section.parent.remove(section)
  40                 break
  41 
  42         # Add link to source text and last modified date
  43         if pep_source_path.stem != "pep-0000":
  44             self.document += _add_source_link(pep_source_path)
  45             self.document += _add_commit_history_info(pep_source_path)
  46 
  47 
  48 def _add_source_link(pep_source_path: Path) -> nodes.paragraph:
  49     """Add link to source text on VCS (GitHub)"""
  50     source_link = f"https://github.com/python/peps/blob/main/{pep_source_path.name}"
  51     link_node = nodes.reference("", source_link, refuri=source_link)
  52     return nodes.paragraph("", "Source: ", link_node)
  53 
  54 
  55 def _add_commit_history_info(pep_source_path: Path) -> nodes.paragraph:
  56     """Use local git history to find last modified date."""
  57     try:
  58         since_epoch = LAST_MODIFIED_TIMES[pep_source_path.name]
  59     except KeyError:
  60         return nodes.paragraph()
  61 
  62     iso_time = datetime.datetime.utcfromtimestamp(since_epoch).isoformat(sep=" ")
  63     commit_link = f"https://github.com/python/peps/commits/main/{pep_source_path.name}"
  64     link_node = nodes.reference("", f"{iso_time} GMT", refuri=commit_link)
  65     return nodes.paragraph("", "Last modified: ", link_node)
  66 
  67 
  68 def _get_last_modified_timestamps():
  69     # get timestamps and changed files from all commits (without paging results)
  70     args = ["git", "--no-pager", "log", "--format=#%at", "--name-only"]
  71     with subprocess.Popen(args, stdout=subprocess.PIPE) as process:
  72         all_modified = process.stdout.read().decode("utf-8")
  73         process.stdout.close()
  74         if process.wait():  # non-zero return code
  75             return {}
  76 
  77     # set up the dictionary with the *current* files
  78     last_modified = {path.name: 0 for path in Path().glob("pep-*") if path.suffix in {".txt", ".rst"}}
  79 
  80     # iterate through newest to oldest, updating per file timestamps
  81     change_sets = all_modified.removeprefix("#").split("#")
  82     for change_set in change_sets:
  83         timestamp, files = change_set.split("\n", 1)
  84         for file in files.strip().split("\n"):
  85             if file.startswith("pep-") and file[-3:] in {"txt", "rst"}:
  86                 if last_modified.get(file) == 0:
  87                     try:
  88                         last_modified[file] = float(timestamp)
  89                     except ValueError:
  90                         pass  # if float conversion fails
  91 
  92     return last_modified
  93 
  94 
  95 LAST_MODIFIED_TIMES = _get_last_modified_timestamps()
  96
  [end of pep_sphinx_extensions/pep_processor/transforms/pep_footer.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/pep_sphinx_extensions/pep_processor/transforms/pep_footer.py b/pep_sphinx_extensions/pep_processor/transforms/pep_footer.py
  --- a/pep_sphinx_extensions/pep_processor/transforms/pep_footer.py
  +++ b/pep_sphinx_extensions/pep_processor/transforms/pep_footer.py
  @@ -18,8 +18,8 @@
   
       """
   
  -    # Uses same priority as docutils.transforms.TargetNotes
  -    default_priority = 520
  +    # Set low priority so ref targets aren't removed before they are needed
  +    default_priority = 999
   
       def apply(self) -> None:
           pep_source_path = Path(self.document["source"])
  
verification_info: {"golden_diff": "diff --git a/pep_sphinx_extensions/pep_processor/transforms/pep_footer.py b/pep_sphinx_extensions/pep_processor/transforms/pep_footer.py\n--- a/pep_sphinx_extensions/pep_processor/transforms/pep_footer.py\n+++ b/pep_sphinx_extensions/pep_processor/transforms/pep_footer.py\n@@ -18,8 +18,8 @@\n \n     \"\"\"\n \n-    # Uses same priority as docutils.transforms.TargetNotes\n-    default_priority = 520\n+    # Set low priority so ref targets aren't removed before they are needed\n+    default_priority = 999\n \n     def apply(self) -> None:\n         pep_source_path = Path(self.document[\"source\"])\n", "issue": "Don't auto-add inline links to ref section & rm if empty, per #2130\nFirst step to implementing #2130 , as agreed with @gvanrossum and the PEP editor team.\r\n\r\nWhen building, don't add redundant footnotes and references entries for URLs that are already directly linked inline. This avoids an unnecessary, potentially confusing footnote for each link, and taking up additional space in the references section for no real benefit, plus simplifies the build code and should improve build time, especially for Sphinx. Furthermore, if the references section is empty (not including now-invisible link targets), remove it, as we did before (but in a more robust manner). This allows past and future PEPs to still use inline references with targets stored in the references section, while avoiding showing a now-empty references section.\r\n\r\nThese are both implemented for Sphinx and the legacy builder, and I visually inspected a variety of PEPs with various cases with both builders to ensure the desired results were achieved, and there were no obvious side effects from this change.\r\n\r\nFollowing merging this PR, following the plan outlined in #2130 , I'll proceed with one updating the meta-PEP docs in PEP 0, PEP 1 and PEP 12 to reflect the revised policy of using standard reST links (inline or with separate targets) rather than the references section, and follow that with a PR updating the relative handful of references in the other active meta-PEPs, for consistency.\n", "before_files": [{"content": "import datetime\nfrom pathlib import Path\nimport subprocess\n\nfrom docutils import nodes\nfrom docutils import transforms\n\n\nclass PEPFooter(transforms.Transform):\n    \"\"\"Footer transforms for PEPs.\n\n     - Removes the References section if it is empty when rendered.\n     - Creates a link to the (GitHub) source text.\n\n    Source Link:\n        Create the link to the source file from the document source path,\n        and append the text to the end of the document.\n\n    \"\"\"\n\n    # Uses same priority as docutils.transforms.TargetNotes\n    default_priority = 520\n\n    def apply(self) -> None:\n        pep_source_path = Path(self.document[\"source\"])\n        if not pep_source_path.match(\"pep-*\"):\n            return  # not a PEP file, exit early\n\n        # Iterate through sections from the end of the document\n        for section in reversed(self.document[0]):\n            if not isinstance(section, nodes.section):\n                continue\n            title_words = section[0].astext().lower().split()\n            if \"references\" in title_words:\n                # Remove references section if there are no displayed\n                # footnotes (it only has title & link target nodes)\n                if all(isinstance(ref_node, (nodes.title, nodes.target))\n                       for ref_node in section):\n                    section.parent.remove(section)\n                break\n\n        # Add link to source text and last modified date\n        if pep_source_path.stem != \"pep-0000\":\n            self.document += _add_source_link(pep_source_path)\n            self.document += _add_commit_history_info(pep_source_path)\n\n\ndef _add_source_link(pep_source_path: Path) -> nodes.paragraph:\n    \"\"\"Add link to source text on VCS (GitHub)\"\"\"\n    source_link = f\"https://github.com/python/peps/blob/main/{pep_source_path.name}\"\n    link_node = nodes.reference(\"\", source_link, refuri=source_link)\n    return nodes.paragraph(\"\", \"Source: \", link_node)\n\n\ndef _add_commit_history_info(pep_source_path: Path) -> nodes.paragraph:\n    \"\"\"Use local git history to find last modified date.\"\"\"\n    try:\n        since_epoch = LAST_MODIFIED_TIMES[pep_source_path.name]\n    except KeyError:\n        return nodes.paragraph()\n\n    iso_time = datetime.datetime.utcfromtimestamp(since_epoch).isoformat(sep=\" \")\n    commit_link = f\"https://github.com/python/peps/commits/main/{pep_source_path.name}\"\n    link_node = nodes.reference(\"\", f\"{iso_time} GMT\", refuri=commit_link)\n    return nodes.paragraph(\"\", \"Last modified: \", link_node)\n\n\ndef _get_last_modified_timestamps():\n    # get timestamps and changed files from all commits (without paging results)\n    args = [\"git\", \"--no-pager\", \"log\", \"--format=#%at\", \"--name-only\"]\n    with subprocess.Popen(args, stdout=subprocess.PIPE) as process:\n        all_modified = process.stdout.read().decode(\"utf-8\")\n        process.stdout.close()\n        if process.wait():  # non-zero return code\n            return {}\n\n    # set up the dictionary with the *current* files\n    last_modified = {path.name: 0 for path in Path().glob(\"pep-*\") if path.suffix in {\".txt\", \".rst\"}}\n\n    # iterate through newest to oldest, updating per file timestamps\n    change_sets = all_modified.removeprefix(\"#\").split(\"#\")\n    for change_set in change_sets:\n        timestamp, files = change_set.split(\"\\n\", 1)\n        for file in files.strip().split(\"\\n\"):\n            if file.startswith(\"pep-\") and file[-3:] in {\"txt\", \"rst\"}:\n                if last_modified.get(file) == 0:\n                    try:\n                        last_modified[file] = float(timestamp)\n                    except ValueError:\n                        pass  # if float conversion fails\n\n    return last_modified\n\n\nLAST_MODIFIED_TIMES = _get_last_modified_timestamps()\n", "path": "pep_sphinx_extensions/pep_processor/transforms/pep_footer.py"}]}