We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Create a script for 2.0 API Reference docs


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `docs/pydoc/renderers.py`
Content:
```
1 import os
2 import sys
3 import io
4 import dataclasses
5 import typing as t
6 import base64
7 import warnings
8 from pathlib import Path
9 
10 import requests
11 import docspec
12 from pydoc_markdown.interfaces import Context, Renderer
13 from pydoc_markdown.contrib.renderers.markdown import MarkdownRenderer
14 
15 
16 README_FRONTMATTER = """---
17 title: {title}
18 excerpt: {excerpt}
19 category: {category}
20 slug: {slug}
21 parentDoc: {parent_doc}
22 order: {order}
23 hidden: false
24 ---
25 
26 """
27 
28 
29 def create_headers(version: str):
30     # Utility function to create Readme.io headers.
31     # We assume the README_API_KEY env var is set since we check outside
32     # to show clearer error messages.
33     README_API_KEY = os.getenv("README_API_KEY")
34     token = base64.b64encode(f"{README_API_KEY}:".encode()).decode()
35     return {"authorization": f"Basic {token}", "x-readme-version": version}
36 
37 
38 @dataclasses.dataclass
39 class ReadmeRenderer(Renderer):
40     """
41     This custom Renderer is heavily based on the `MarkdownRenderer`,
42     it just prepends a front matter so that the output can be published
43     directly to readme.io.
44     """
45 
46     # These settings will be used in the front matter output
47     title: str
48     category_slug: str
49     excerpt: str
50     slug: str
51     order: int
52     parent_doc_slug: str = ""
53     # Docs categories fetched from Readme.io
54     categories: t.Dict[str, str] = dataclasses.field(init=False)
55     # This exposes a special `markdown` settings value that can be used to pass
56     # parameters to the underlying `MarkdownRenderer`
57     markdown: MarkdownRenderer = dataclasses.field(default_factory=MarkdownRenderer)
58 
59     def init(self, context: Context) -> None:
60         self.markdown.init(context)
61         self.version = self._doc_version()
62         self.categories = self._readme_categories(self.version)
63 
64     def _doc_version(self) -> str:
65         """
66         Returns the docs version.
67         """
68         root = Path(__file__).absolute().parent.parent.parent
69         full_version = (root / "VERSION.txt").read_text()
70         major, minor = full_version.split(".")[:2]
71         if "rc0" in full_version:
72             return f"v{major}.{minor}-unstable"
73         return f"v{major}.{minor}"
74 
75     def _readme_categories(self, version: str) -> t.Dict[str, str]:
76         """
77         Fetch the categories of the given version from Readme.io.
78         README_API_KEY env var must be set to correctly get the categories.
79         Returns dictionary containing all the categories slugs and their ids.
80         """
81         README_API_KEY = os.getenv("README_API_KEY")
82         if not README_API_KEY:
83             warnings.warn("README_API_KEY env var is not set, using a placeholder category ID")
84             return {"haystack-classes": "ID"}
85 
86         headers = create_headers(version)
87 
88         res = requests.get("https://dash.readme.com/api/v1/categories", headers=headers, timeout=60)
89 
90         if not res.ok:
91             sys.exit(f"Error requesting {version} categories")
92 
93         return {c["slug"]: c["id"] for c in res.json()}
94 
95     def _doc_id(self, doc_slug: str, version: str) -> str:
96         """
97         Fetch the doc id of the given doc slug and version from Readme.io.
98         README_API_KEY env var must be set to correctly get the id.
99         If doc_slug is an empty string return an empty string.
100         """
101         if not doc_slug:
102             # Not all docs have a parent doc, in case we get no slug
103             # we just return an empty string.
104             return ""
105 
106         README_API_KEY = os.getenv("README_API_KEY")
107         if not README_API_KEY:
108             warnings.warn("README_API_KEY env var is not set, using a placeholder doc ID")
109             return "fake-doc-id"
110 
111         headers = create_headers(version)
112         res = requests.get(f"https://dash.readme.com/api/v1/docs/{doc_slug}", headers=headers, timeout=60)
113         if not res.ok:
114             sys.exit(f"Error requesting {doc_slug} doc for version {version}")
115 
116         return res.json()["id"]
117 
118     def render(self, modules: t.List[docspec.Module]) -> None:
119         if self.markdown.filename is None:
120             sys.stdout.write(self._frontmatter())
121             self.markdown.render_single_page(sys.stdout, modules)
122         else:
123             with io.open(self.markdown.filename, "w", encoding=self.markdown.encoding) as fp:
124                 fp.write(self._frontmatter())
125                 self.markdown.render_single_page(t.cast(t.TextIO, fp), modules)
126 
127     def _frontmatter(self) -> str:
128         return README_FRONTMATTER.format(
129             title=self.title,
130             category=self.categories[self.category_slug],
131             parent_doc=self._doc_id(self.parent_doc_slug, self.version),
132             excerpt=self.excerpt,
133             slug=self.slug,
134             order=self.order,
135         )
136
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/docs/pydoc/renderers.py b/docs/pydoc/renderers.py
--- a/docs/pydoc/renderers.py
+++ b/docs/pydoc/renderers.py
@@ -133,3 +133,16 @@
             slug=self.slug,
             order=self.order,
         )
+
+
+@dataclasses.dataclass
+class ReadmePreviewRenderer(ReadmeRenderer):
+    """
+    This custom Renderer behaves just like the ReadmeRenderer but renders docs with the hardcoded version 2.0 to generate correct category ids.
+    """
+
+    def _doc_version(self) -> str:
+        """
+        Returns the hardcoded docs version 2.0.
+        """
+        return "v2.0"

{"golden_diff": "diff --git a/docs/pydoc/renderers.py b/docs/pydoc/renderers.py\n--- a/docs/pydoc/renderers.py\n+++ b/docs/pydoc/renderers.py\n@@ -133,3 +133,16 @@\n             slug=self.slug,\n             order=self.order,\n         )\n+\n+\n+@dataclasses.dataclass\n+class ReadmePreviewRenderer(ReadmeRenderer):\n+    \"\"\"\n+    This custom Renderer behaves just like the ReadmeRenderer but renders docs with the hardcoded version 2.0 to generate correct category ids.\n+    \"\"\"\n+\n+    def _doc_version(self) -> str:\n+        \"\"\"\n+        Returns the hardcoded docs version 2.0.\n+        \"\"\"\n+        return \"v2.0\"\n", "issue": "Create a script for 2.0 API Reference docs\n\n", "before_files": [{"content": "import os\nimport sys\nimport io\nimport dataclasses\nimport typing as t\nimport base64\nimport warnings\nfrom pathlib import Path\n\nimport requests\nimport docspec\nfrom pydoc_markdown.interfaces import Context, Renderer\nfrom pydoc_markdown.contrib.renderers.markdown import MarkdownRenderer\n\n\nREADME_FRONTMATTER = \"\"\"---\ntitle: {title}\nexcerpt: {excerpt}\ncategory: {category}\nslug: {slug}\nparentDoc: {parent_doc}\norder: {order}\nhidden: false\n---\n\n\"\"\"\n\n\ndef create_headers(version: str):\n    # Utility function to create Readme.io headers.\n    # We assume the README_API_KEY env var is set since we check outside\n    # to show clearer error messages.\n    README_API_KEY = os.getenv(\"README_API_KEY\")\n    token = base64.b64encode(f\"{README_API_KEY}:\".encode()).decode()\n    return {\"authorization\": f\"Basic {token}\", \"x-readme-version\": version}\n\n\n@dataclasses.dataclass\nclass ReadmeRenderer(Renderer):\n    \"\"\"\n    This custom Renderer is heavily based on the `MarkdownRenderer`,\n    it just prepends a front matter so that the output can be published\n    directly to readme.io.\n    \"\"\"\n\n    # These settings will be used in the front matter output\n    title: str\n    category_slug: str\n    excerpt: str\n    slug: str\n    order: int\n    parent_doc_slug: str = \"\"\n    # Docs categories fetched from Readme.io\n    categories: t.Dict[str, str] = dataclasses.field(init=False)\n    # This exposes a special `markdown` settings value that can be used to pass\n    # parameters to the underlying `MarkdownRenderer`\n    markdown: MarkdownRenderer = dataclasses.field(default_factory=MarkdownRenderer)\n\n    def init(self, context: Context) -> None:\n        self.markdown.init(context)\n        self.version = self._doc_version()\n        self.categories = self._readme_categories(self.version)\n\n    def _doc_version(self) -> str:\n        \"\"\"\n        Returns the docs version.\n        \"\"\"\n        root = Path(__file__).absolute().parent.parent.parent\n        full_version = (root / \"VERSION.txt\").read_text()\n        major, minor = full_version.split(\".\")[:2]\n        if \"rc0\" in full_version:\n            return f\"v{major}.{minor}-unstable\"\n        return f\"v{major}.{minor}\"\n\n    def _readme_categories(self, version: str) -> t.Dict[str, str]:\n        \"\"\"\n        Fetch the categories of the given version from Readme.io.\n        README_API_KEY env var must be set to correctly get the categories.\n        Returns dictionary containing all the categories slugs and their ids.\n        \"\"\"\n        README_API_KEY = os.getenv(\"README_API_KEY\")\n        if not README_API_KEY:\n            warnings.warn(\"README_API_KEY env var is not set, using a placeholder category ID\")\n            return {\"haystack-classes\": \"ID\"}\n\n        headers = create_headers(version)\n\n        res = requests.get(\"https://dash.readme.com/api/v1/categories\", headers=headers, timeout=60)\n\n        if not res.ok:\n            sys.exit(f\"Error requesting {version} categories\")\n\n        return {c[\"slug\"]: c[\"id\"] for c in res.json()}\n\n    def _doc_id(self, doc_slug: str, version: str) -> str:\n        \"\"\"\n        Fetch the doc id of the given doc slug and version from Readme.io.\n        README_API_KEY env var must be set to correctly get the id.\n        If doc_slug is an empty string return an empty string.\n        \"\"\"\n        if not doc_slug:\n            # Not all docs have a parent doc, in case we get no slug\n            # we just return an empty string.\n            return \"\"\n\n        README_API_KEY = os.getenv(\"README_API_KEY\")\n        if not README_API_KEY:\n            warnings.warn(\"README_API_KEY env var is not set, using a placeholder doc ID\")\n            return \"fake-doc-id\"\n\n        headers = create_headers(version)\n        res = requests.get(f\"https://dash.readme.com/api/v1/docs/{doc_slug}\", headers=headers, timeout=60)\n        if not res.ok:\n            sys.exit(f\"Error requesting {doc_slug} doc for version {version}\")\n\n        return res.json()[\"id\"]\n\n    def render(self, modules: t.List[docspec.Module]) -> None:\n        if self.markdown.filename is None:\n            sys.stdout.write(self._frontmatter())\n            self.markdown.render_single_page(sys.stdout, modules)\n        else:\n            with io.open(self.markdown.filename, \"w\", encoding=self.markdown.encoding) as fp:\n                fp.write(self._frontmatter())\n                self.markdown.render_single_page(t.cast(t.TextIO, fp), modules)\n\n    def _frontmatter(self) -> str:\n        return README_FRONTMATTER.format(\n            title=self.title,\n            category=self.categories[self.category_slug],\n            parent_doc=self._doc_id(self.parent_doc_slug, self.version),\n            excerpt=self.excerpt,\n            slug=self.slug,\n            order=self.order,\n        )\n", "path": "docs/pydoc/renderers.py"}], "after_files": [{"content": "import os\nimport sys\nimport io\nimport dataclasses\nimport typing as t\nimport base64\nimport warnings\nfrom pathlib import Path\n\nimport requests\nimport docspec\nfrom pydoc_markdown.interfaces import Context, Renderer\nfrom pydoc_markdown.contrib.renderers.markdown import MarkdownRenderer\n\n\nREADME_FRONTMATTER = \"\"\"---\ntitle: {title}\nexcerpt: {excerpt}\ncategory: {category}\nslug: {slug}\nparentDoc: {parent_doc}\norder: {order}\nhidden: false\n---\n\n\"\"\"\n\n\ndef create_headers(version: str):\n    # Utility function to create Readme.io headers.\n    # We assume the README_API_KEY env var is set since we check outside\n    # to show clearer error messages.\n    README_API_KEY = os.getenv(\"README_API_KEY\")\n    token = base64.b64encode(f\"{README_API_KEY}:\".encode()).decode()\n    return {\"authorization\": f\"Basic {token}\", \"x-readme-version\": version}\n\n\n@dataclasses.dataclass\nclass ReadmeRenderer(Renderer):\n    \"\"\"\n    This custom Renderer is heavily based on the `MarkdownRenderer`,\n    it just prepends a front matter so that the output can be published\n    directly to readme.io.\n    \"\"\"\n\n    # These settings will be used in the front matter output\n    title: str\n    category_slug: str\n    excerpt: str\n    slug: str\n    order: int\n    parent_doc_slug: str = \"\"\n    # Docs categories fetched from Readme.io\n    categories: t.Dict[str, str] = dataclasses.field(init=False)\n    # This exposes a special `markdown` settings value that can be used to pass\n    # parameters to the underlying `MarkdownRenderer`\n    markdown: MarkdownRenderer = dataclasses.field(default_factory=MarkdownRenderer)\n\n    def init(self, context: Context) -> None:\n        self.markdown.init(context)\n        self.version = self._doc_version()\n        self.categories = self._readme_categories(self.version)\n\n    def _doc_version(self) -> str:\n        \"\"\"\n        Returns the docs version.\n        \"\"\"\n        root = Path(__file__).absolute().parent.parent.parent\n        full_version = (root / \"VERSION.txt\").read_text()\n        major, minor = full_version.split(\".\")[:2]\n        if \"rc0\" in full_version:\n            return f\"v{major}.{minor}-unstable\"\n        return f\"v{major}.{minor}\"\n\n    def _readme_categories(self, version: str) -> t.Dict[str, str]:\n        \"\"\"\n        Fetch the categories of the given version from Readme.io.\n        README_API_KEY env var must be set to correctly get the categories.\n        Returns dictionary containing all the categories slugs and their ids.\n        \"\"\"\n        README_API_KEY = os.getenv(\"README_API_KEY\")\n        if not README_API_KEY:\n            warnings.warn(\"README_API_KEY env var is not set, using a placeholder category ID\")\n            return {\"haystack-classes\": \"ID\"}\n\n        headers = create_headers(version)\n\n        res = requests.get(\"https://dash.readme.com/api/v1/categories\", headers=headers, timeout=60)\n\n        if not res.ok:\n            sys.exit(f\"Error requesting {version} categories\")\n\n        return {c[\"slug\"]: c[\"id\"] for c in res.json()}\n\n    def _doc_id(self, doc_slug: str, version: str) -> str:\n        \"\"\"\n        Fetch the doc id of the given doc slug and version from Readme.io.\n        README_API_KEY env var must be set to correctly get the id.\n        If doc_slug is an empty string return an empty string.\n        \"\"\"\n        if not doc_slug:\n            # Not all docs have a parent doc, in case we get no slug\n            # we just return an empty string.\n            return \"\"\n\n        README_API_KEY = os.getenv(\"README_API_KEY\")\n        if not README_API_KEY:\n            warnings.warn(\"README_API_KEY env var is not set, using a placeholder doc ID\")\n            return \"fake-doc-id\"\n\n        headers = create_headers(version)\n        res = requests.get(f\"https://dash.readme.com/api/v1/docs/{doc_slug}\", headers=headers, timeout=60)\n        if not res.ok:\n            sys.exit(f\"Error requesting {doc_slug} doc for version {version}\")\n\n        return res.json()[\"id\"]\n\n    def render(self, modules: t.List[docspec.Module]) -> None:\n        if self.markdown.filename is None:\n            sys.stdout.write(self._frontmatter())\n            self.markdown.render_single_page(sys.stdout, modules)\n        else:\n            with io.open(self.markdown.filename, \"w\", encoding=self.markdown.encoding) as fp:\n                fp.write(self._frontmatter())\n                self.markdown.render_single_page(t.cast(t.TextIO, fp), modules)\n\n    def _frontmatter(self) -> str:\n        return README_FRONTMATTER.format(\n            title=self.title,\n            category=self.categories[self.category_slug],\n            parent_doc=self._doc_id(self.parent_doc_slug, self.version),\n            excerpt=self.excerpt,\n            slug=self.slug,\n            order=self.order,\n        )\n\n\n@dataclasses.dataclass\nclass ReadmePreviewRenderer(ReadmeRenderer):\n    \"\"\"\n    This custom Renderer behaves just like the ReadmeRenderer but renders docs with the hardcoded version 2.0 to generate correct category ids.\n    \"\"\"\n\n    def _doc_version(self) -> str:\n        \"\"\"\n        Returns the hardcoded docs version 2.0.\n        \"\"\"\n        return \"v2.0\"\n", "path": "docs/pydoc/renderers.py"}]}