Skip to content

Commit 67d772d

Browse files
Merge pull request #26 from gleanwork/rwjblue/push-tvslsquluzxs
fix: update `prepare_readme.py` to support local development workflow
2 parents 71ca4c1 + 61c24c8 commit 67d772d

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ version = "0.5.2"
44
description = "Python Client SDK Generated by Speakeasy."
55
authors = [{ name = "Glean Technologies, Inc." }]
66
license = "MIT"
7-
readme = "README-PYPI.md"
7+
# NOTE: scripts/prepare_readme.py tweaks this to point to README-PYPI.md for publication
8+
# The published readme has relative URLs converted to absolute URLs for PyPI compatibility
9+
readme = "README.md"
810
requires-python = ">=3.9"
911
dependencies = ["httpx >=0.28.1", "pydantic >=2.11.2"]
1012

scripts/prepare_readme.py

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,40 @@
1-
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
1+
"""
2+
Prepare README for PyPI publication.
3+
4+
This script processes README.md to create README-PYPI.md with PyPI-compatible formatting:
5+
- Converts relative URLs to absolute GitHub URLs so links work on PyPI
6+
- Updates pyproject.toml to reference the PyPI-ready README file
7+
8+
The original README.md remains unchanged for GitHub display, while README-PYPI.md
9+
is used for package publishing to ensure all documentation links function properly
10+
on the PyPI package page.
11+
"""
212

313
import re
4-
import shutil
14+
15+
16+
def update_pyproject_readme_path():
17+
"""Update pyproject.toml to point to the PyPI readme file."""
18+
pyproject_path = "pyproject.toml"
19+
20+
try:
21+
with open(pyproject_path, "r", encoding="utf-8") as f:
22+
content = f.read()
23+
24+
updated_content = re.sub(
25+
r'readme\s*=\s*"README\.md"', 'readme = "README-PYPI.md"', content
26+
)
27+
28+
if updated_content != content:
29+
with open(pyproject_path, "w", encoding="utf-8") as f:
30+
f.write(updated_content)
31+
print("Updated pyproject.toml to use README-PYPI.md")
32+
else:
33+
print("No changes needed in pyproject.toml")
34+
35+
except Exception as e:
36+
print(f"Failed to update pyproject.toml: {e}")
37+
538

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

2457
with open("README-PYPI.md", "w", encoding="utf-8") as wh:
2558
wh.write(readme_contents)
59+
60+
print("Successfully created README-PYPI.md")
61+
update_pyproject_readme_path()
62+
2663
except Exception as e:
27-
try:
28-
print("Failed to rewrite README.md to README-PYPI.md, copying original instead")
29-
print(e)
30-
shutil.copyfile("README.md", "README-PYPI.md")
31-
except Exception as ie:
32-
print("Failed to copy README.md to README-PYPI.md")
33-
print(ie)
64+
print("Failed to update README.md to use absolute URLs for PyPi")
65+
print(e)

0 commit comments

Comments
 (0)