Skip to content

Commit

Permalink
Make typing Python 3.8 compatible for RTD
Browse files Browse the repository at this point in the history
  • Loading branch information
hmellor committed Jan 6, 2025
1 parent 00fdcb8 commit 66763fa
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions docs/source/generate_examples.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
from dataclasses import dataclass, field
from pathlib import Path
from typing import List

ROOT_DIR = Path(__file__).parent.parent.parent.resolve()
ROOT_DIR_RELATIVE = '../../../..'
Expand Down Expand Up @@ -67,7 +68,7 @@ class Index:
description (str): A brief description of the index. Defaults to an empty string.
maxdepth (int): The maximum depth of the table of contents. Defaults to 1.
caption (str): An optional caption for the table of contents. Defaults to an empty string.
documents (list[str]): A list of document paths to include in the index. Defaults to an empty list.
documents (List[str]): A list of document paths to include in the index. Defaults to an empty list.
Methods:
generate() -> str:
Expand All @@ -77,7 +78,7 @@ class Index:
description: str = field(default="")
maxdepth: int = 1
caption: str = field(default="")
documents: list[str] = field(default_factory=list)
documents: List[str] = field(default_factory=list)

def generate(self) -> str:
content = f"# {self.title}\n\n"
Expand All @@ -97,23 +98,23 @@ class Example:
Attributes:
path (Path): The path to the main directory or file.
main_file (Path): The main file in the directory.
other_files (list[Path]): List of other files in the directory.
other_files (List[Path]): List of other files in the directory.
title (str): The title of the document.
url (str): The URL to the document on GitHub.
category (str): The category of the document.
Methods:
__post_init__(): Initializes the main_file, other_files, title, url, and category attributes.
determine_main_file() -> Path: Determines the main file in the given path.
determine_other_files() -> list[Path]: Determines other files in the directory excluding the main file.
determine_other_files() -> List[Path]: Determines other files in the directory excluding the main file.
determine_title() -> str: Determines the title of the document.
determine_url() -> str: Determines the URL to the document on GitHub.
determine_category() -> str: Determines the category of the document based on its title and content.
generate() -> str: Generates the documentation content.
"""
path: Path
main_file: Path = field(init=False)
other_files: list[Path] = field(init=False)
other_files: List[Path] = field(init=False)
title: str = field(init=False)
url: str = field(init=False)
category: str = field(init=False)
Expand All @@ -139,7 +140,7 @@ def determine_main_file(self) -> Path:
return self.path if self.path.is_file() else list(
self.path.glob("*.md")).pop()

def determine_other_files(self) -> list[Path]:
def determine_other_files(self) -> List[Path]:
"""
Determine other files in the directory excluding the main file.
Expand All @@ -148,7 +149,7 @@ def determine_other_files(self) -> list[Path]:
files that are not the main file.
Returns:
list[Path]: A list of Path objects representing the other files in the directory.
List[Path]: A list of Path objects representing the other files in the directory.
"""
if self.path.is_file():
return []
Expand Down Expand Up @@ -185,7 +186,8 @@ def determine_category(self) -> str:

def generate(self) -> str:
# Convert the path to a relative path from __file__
make_relative = lambda path: ROOT_DIR_RELATIVE / path.relative_to(ROOT_DIR)
make_relative = lambda path: ROOT_DIR_RELATIVE / path.relative_to(
ROOT_DIR)

content = f"Source <{self.url}>.\n\n"
if self.main_file.suffix == ".py":
Expand All @@ -209,10 +211,12 @@ def generate_examples():
EXAMPLE_DOC_DIR.mkdir(parents=True)

# Generate examples_index and examples_{category}_index files
examples_index = Index(title="Examples",
description="A collection of examples demonstrating usage of vLLM.\n\nAll documented examples are autogenerated from examples found in [vllm/examples](https://github.com/vllm-project/vllm/tree/main/examples).",
maxdepth=2,
caption="Categories")
examples_index = Index(
title="Examples",
description=
"A collection of examples demonstrating usage of vLLM.\n\nAll documented examples are autogenerated from examples found in [vllm/examples](https://github.com/vllm-project/vllm/tree/main/examples).",
maxdepth=2,
caption="Categories")
category_indices = {
category: Index(title=category,
description=category_info["description"])
Expand Down

0 comments on commit 66763fa

Please sign in to comment.