diff --git a/docs/source/generate_examples.py b/docs/source/generate_examples.py index 819980d1b8e14..9c6dd5d4aa0c7 100644 --- a/docs/source/generate_examples.py +++ b/docs/source/generate_examples.py @@ -73,7 +73,7 @@ class Index: Methods: generate() -> str: Generates the index content as a string in the specified format. - """ + """ # noqa: E501 title: str description: str = field(default="") maxdepth: int = 1 @@ -111,7 +111,7 @@ class Example: 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. - """ + """ # noqa: E501 path: Path main_file: Path = field(init=False) other_files: List[Path] = field(init=False) @@ -136,7 +136,7 @@ def determine_main_file(self) -> Path: Markdown file found in the directory. Raises: IndexError: If no Markdown files are found in the directory. - """ + """ # noqa: E501 return self.path if self.path.is_file() else list( self.path.glob("*.md")).pop() @@ -150,7 +150,7 @@ def determine_other_files(self) -> List[Path]: Returns: List[Path]: A list of Path objects representing the other files in the directory. - """ + """ # noqa: E501 if self.path.is_file(): return [] is_other_file = lambda file: file.is_file() and file != self.main_file @@ -173,7 +173,7 @@ def determine_category(self) -> str: Returns: str: The category of the document. - """ + """ # noqa: E501 title = self.title.lower() with open(self.main_file, "r") as f: content = f.read().lower() @@ -192,15 +192,20 @@ def generate(self) -> str: content = f"Source <{self.url}>.\n\n" if self.main_file.suffix == ".py": content += f"# {self.title}\n\n" - include = "include" if self.main_file.suffix == ".md" else "literalinclude" + include = "include" if self.main_file.suffix == ".md" else \ + "literalinclude" content += f":::{{{include}}} {make_relative(self.main_file)}\n:::\n\n" - if self.other_files: - content += "## Example materials\n\n" - for file in self.other_files: - include = "include" if file.suffix == ".md" else "literalinclude" - content += f":::{{admonition}} {file.relative_to(self.path)}\n:class: dropdown\n\n" - content += f":::{{{include}}} {make_relative(file)}\n:::\n" - content += ":::\n\n" + + if not self.other_files: + return content + + content += "## Example materials\n\n" + for file in self.other_files: + include = "include" if file.suffix == ".md" else "literalinclude" + content += f":::{{admonition}} {file.relative_to(self.path)}\n" + content += ":class: dropdown\n\n" + content += f":::{{{include}}} {make_relative(file)}\n:::\n" + content += ":::\n\n" return content @@ -214,7 +219,7 @@ def generate_examples(): 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).", + "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).", # noqa: E501 maxdepth=2, caption="Categories") category_indices = {