Skip to content

Commit ab71abf

Browse files
committed
fix: update prepare_readme.py to support local development workflow
**Context:** The `scripts/prepare_readme.py` script converts `README.md` to `README-PYPI.md` for PyPI publication, replacing relative URLs with absolute GitHub URLs so documentation links work properly on the PyPI package page. **Problem:** Prior to these changes, `poetry install` would fail in local development with "Readme path does not exist" because `pyproject.toml` referenced `README-PYPI.md`, but this file was gitignored and only generated during the publishing process. **Fix:** Enhanced `scripts/prepare_readme.py` to automatically update `pyproject.toml` after generating `README-PYPI.md`, switching the `readme` reference from `README.md` to `README-PYPI.md`. This allows the script to handle the complete PyPI preparation workflow while ensuring local development setup works seamlessly.
1 parent 57edf6a commit ab71abf

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
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: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
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+
12+
Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
13+
"""
214

315
import re
416
import shutil
517

18+
19+
def update_pyproject_readme_path():
20+
"""Update pyproject.toml to point to the PyPI readme file."""
21+
pyproject_path = "pyproject.toml"
22+
23+
try:
24+
with open(pyproject_path, "r", encoding="utf-8") as f:
25+
content = f.read()
26+
27+
updated_content = re.sub(
28+
r'readme\s*=\s*"README\.md"', 'readme = "README-PYPI.md"', content
29+
)
30+
31+
if updated_content != content:
32+
with open(pyproject_path, "w", encoding="utf-8") as f:
33+
f.write(updated_content)
34+
print("Updated pyproject.toml to use README-PYPI.md")
35+
else:
36+
print("No changes needed in pyproject.toml")
37+
38+
except Exception as e:
39+
print(f"Failed to update pyproject.toml: {e}")
40+
41+
642
try:
743
with open("README.md", "r", encoding="utf-8") as rh:
844
readme_contents = rh.read()
@@ -23,11 +59,10 @@
2359

2460
with open("README-PYPI.md", "w", encoding="utf-8") as wh:
2561
wh.write(readme_contents)
62+
63+
print("Successfully created README-PYPI.md")
64+
update_pyproject_readme_path()
65+
2666
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)
67+
print("Failed to update README.md to use absolute URLs for PyPi")
68+
print(e)

0 commit comments

Comments
 (0)