Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def add_yoda_prefix(example):
# Split the dataset into train and eval sets
print(
f"Splitting dataset with {len(dataset)} rows into train ({train_split_ratio:.1%}) "
f"and eval ({(1-train_split_ratio):.1%}) sets"
f"and eval ({(1 - train_split_ratio):.1%}) sets"
)
split_dataset = dataset.train_test_split(test_size=1 - train_split_ratio, seed=42)

Expand Down
16 changes: 15 additions & 1 deletion scripts/generate_readme/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,18 @@
EXIT_ERROR = 2 # Actual error (e.g., missing function, failed to write file)

# Markdown formatting constraints (per .markdownlint.json)
MAX_LINE_LENGTH = 120 # Maximum line length for markdown content
MAX_LINE_LENGTH = 120 # Maximum line length for Markdown content

# Words with non-standard capitalization that should be preserved as-is
# instead of being title-cased. Keys must be lowercase.
SPECIAL_CASE_WORDS = {
"kfp": "KFP",
"api": "API",
"url": "URL",
"id": "ID",
"ui": "UI",
"ci": "CI",
"cd": "CD",
"automl": "AutoML",
"autorag": "AutoRAG",
}
32 changes: 2 additions & 30 deletions scripts/generate_readme/content_generator.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,18 @@
"""README content generator for KFP components and pipelines."""

import logging
import textwrap
from pathlib import Path
from typing import Any, Dict

import yaml
from jinja2 import Environment, FileSystemLoader

from scripts.generate_readme.constants import MAX_LINE_LENGTH, README_TEMPLATE
from scripts.generate_readme.utils import format_title
from scripts.generate_readme.constants import README_TEMPLATE
from scripts.generate_readme.utils import format_title, wrap_text

logger = logging.getLogger(__name__)


def wrap_text(text: str, width: int = MAX_LINE_LENGTH) -> str:
"""Wrap text to specified width while preserving paragraph breaks.

Args:
text: The text to wrap.
width: Maximum line width.

Returns:
Wrapped text with preserved paragraph structure.
"""
if not text:
return text

# Split into paragraphs (separated by blank lines)
paragraphs = text.split("\n\n")
wrapped_paragraphs = []

for paragraph in paragraphs:
# Remove existing line breaks within paragraph
paragraph = " ".join(paragraph.split())
# Wrap to width
wrapped = textwrap.fill(paragraph, width=width, break_long_words=False, break_on_hyphens=False)
wrapped_paragraphs.append(wrapped)

return "\n\n".join(wrapped_paragraphs)


class ReadmeContentGenerator:
"""Generates README.md documentation content for KFP components and pipelines."""

Expand Down
41 changes: 32 additions & 9 deletions scripts/generate_readme/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
"""Utility functions for README generation."""

import re
import textwrap

from scripts.generate_readme.constants import MAX_LINE_LENGTH, SPECIAL_CASE_WORDS


def wrap_text(text: str, width: int = MAX_LINE_LENGTH) -> str:
"""Wrap text to specified width while preserving paragraph breaks.

Args:
text: The text to wrap.
width: Maximum line width.

Returns:
Wrapped text with preserved paragraph structure.
"""
if not text:
return text

# Split into paragraphs (separated by blank lines)
paragraphs = text.split("\n\n")
wrapped_paragraphs = []

for paragraph in paragraphs:
# Remove existing line breaks within paragraph
paragraph = " ".join(paragraph.split())
# Wrap to width
wrapped = textwrap.fill(paragraph, width=width, break_long_words=False, break_on_hyphens=False)
wrapped_paragraphs.append(wrapped)

return "\n\n".join(wrapped_paragraphs)


def format_title(title: str) -> str:
Expand All @@ -18,15 +48,8 @@ def format_title(title: str) -> str:
# Replace underscores and hyphens with spaces
title = title.replace("_", " ").replace("-", " ")

# Split into words and capitalize each
# Split into words and capitalize each, preserving known special-case words
words = title.split()
formatted_words = []

for word in words:
# Keep known acronyms in uppercase
if word.upper() in ["KFP", "API", "URL", "ID", "UI", "CI", "CD"]:
formatted_words.append(word.upper())
else:
formatted_words.append(word.capitalize())
formatted_words = [SPECIAL_CASE_WORDS.get(word.lower(), word.capitalize()) for word in words]

return " ".join(formatted_words)
3 changes: 1 addition & 2 deletions scripts/validate_examples/validate_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def discover_example_files(targets: Sequence[Path]) -> List[Path]:
relative = candidate.relative_to(REPO_ROOT)
except ValueError:
warnings.warn(
f"Unable to determine relative path for {candidate} "
f"relative to repo root {REPO_ROOT}. Skipping.",
f"Unable to determine relative path for {candidate} relative to repo root {REPO_ROOT}. Skipping.",
)
continue
if relative.parts and relative.parts[0] in {"components", "pipelines"}:
Expand Down
Loading