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
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ version = "0.5.2"
description = "Python Client SDK Generated by Speakeasy."
authors = [{ name = "Glean Technologies, Inc." }]
license = "MIT"
readme = "README-PYPI.md"
# NOTE: scripts/prepare_readme.py tweaks this to point to README-PYPI.md for publication
# The published readme has relative URLs converted to absolute URLs for PyPI compatibility
readme = "README.md"
requires-python = ">=3.9"
dependencies = ["httpx >=0.28.1", "pydantic >=2.11.2"]

Expand Down
50 changes: 41 additions & 9 deletions scripts/prepare_readme.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
"""
Prepare README for PyPI publication.

This script processes README.md to create README-PYPI.md with PyPI-compatible formatting:
- Converts relative URLs to absolute GitHub URLs so links work on PyPI
- Updates pyproject.toml to reference the PyPI-ready README file

The original README.md remains unchanged for GitHub display, while README-PYPI.md
is used for package publishing to ensure all documentation links function properly
on the PyPI package page.
"""

import re
import shutil


def update_pyproject_readme_path():
"""Update pyproject.toml to point to the PyPI readme file."""
pyproject_path = "pyproject.toml"

try:
with open(pyproject_path, "r", encoding="utf-8") as f:
content = f.read()

updated_content = re.sub(
r'readme\s*=\s*"README\.md"', 'readme = "README-PYPI.md"', content
)

if updated_content != content:
with open(pyproject_path, "w", encoding="utf-8") as f:
f.write(updated_content)
print("Updated pyproject.toml to use README-PYPI.md")
else:
print("No changes needed in pyproject.toml")

except Exception as e:
print(f"Failed to update pyproject.toml: {e}")


try:
with open("README.md", "r", encoding="utf-8") as rh:
Expand All @@ -23,11 +56,10 @@

with open("README-PYPI.md", "w", encoding="utf-8") as wh:
wh.write(readme_contents)

print("Successfully created README-PYPI.md")
update_pyproject_readme_path()

except Exception as e:
try:
print("Failed to rewrite README.md to README-PYPI.md, copying original instead")
print(e)
shutil.copyfile("README.md", "README-PYPI.md")
except Exception as ie:
print("Failed to copy README.md to README-PYPI.md")
print(ie)
print("Failed to update README.md to use absolute URLs for PyPi")
print(e)