From 61c24c817ebf4714c20406cf8b118a73c4fedabd Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Wed, 28 May 2025 11:23:28 -0400 Subject: [PATCH] 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. --- pyproject.toml | 4 +++- scripts/prepare_readme.py | 50 ++++++++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 089a5959..cfaf6724 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"] diff --git a/scripts/prepare_readme.py b/scripts/prepare_readme.py index 439a1640..c50c18ce 100644 --- a/scripts/prepare_readme.py +++ b/scripts/prepare_readme.py @@ -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: @@ -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)