|
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 | +""" |
2 | 12 |
|
3 | 13 | 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 | + |
5 | 38 |
|
6 | 39 | try: |
7 | 40 | with open("README.md", "r", encoding="utf-8") as rh: |
|
23 | 56 |
|
24 | 57 | with open("README-PYPI.md", "w", encoding="utf-8") as wh: |
25 | 58 | wh.write(readme_contents) |
| 59 | + |
| 60 | + print("Successfully created README-PYPI.md") |
| 61 | + update_pyproject_readme_path() |
| 62 | + |
26 | 63 | 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