diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e8443a7f..7831eae6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -62,20 +62,15 @@ repos: name: Disallow improper capitalization language: pygrep entry: PyBind|Numpy|Cmake|Github|PyTest - types: - - markdown + types: [markdown] exclude: ^docs/working-examples\.md$ # Autogenerated - - id: update-readme-changelog - name: Update README changelog + - id: cog + name: Cog the README language: python - entry: bin/update_readme_changelog.py - files: ^docs/changelog.md$ - - id: update-readme-options-table - name: Update README options table - language: python - entry: bin/update_readme_options_table.py --force - files: ^docs/options.md$ pass_filenames: false + entry: cog -c -P -r -I ./bin README.md + files: '^(README\.md|docs/changelog\.md|docs/options\.md|bin/readme.*)$' + additional_dependencies: [cogapp] - repo: https://github.com/codespell-project/codespell rev: v2.4.1 diff --git a/README.md b/README.md index d40d7af0..8a8f9c54 100644 --- a/README.md +++ b/README.md @@ -124,8 +124,10 @@ The following diagram summarises the steps that cibuildwheel takes on each platf Explore an interactive version of this diagram [in the docs](https://cibuildwheel.pypa.io/en/stable/#how-it-works). - - + + + + | | Option | Description | |---|---|---| @@ -159,7 +161,8 @@ The following diagram summarises the steps that cibuildwheel takes on each platf | | [`debug-traceback`](https://cibuildwheel.pypa.io/en/stable/options/#debug-traceback) | Print full traceback when errors occur. | | | [`build-verbosity`](https://cibuildwheel.pypa.io/en/stable/options/#build-verbosity) | Increase/decrease the output of the build | - + + These options can be specified in a pyproject.toml file, or as environment variables, see [configuration docs](https://cibuildwheel.pypa.io/en/latest/configuration/). @@ -222,9 +225,7 @@ This is similar to static linking, so it might have some license implications. C Changelog ========= - - - + ### v3.0.0 @@ -278,7 +279,7 @@ _26 April 2025_ - 🛠 Dependency updates, including Python 3.13.3 (#2371) - + --- diff --git a/bin/readme_changelog.py b/bin/readme_changelog.py new file mode 100755 index 00000000..29c30293 --- /dev/null +++ b/bin/readme_changelog.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +import re +from pathlib import Path + +PROJECT_ROOT = Path(__file__).parent / ".." +CHANGELOG_FILE = PROJECT_ROOT / "docs" / "changelog.md" + +# https://regexr.com/622ds +FIRST_5_CHANGELOG_ENTRIES_REGEX = re.compile(r"""(^###.*?(?=###)){5}""", re.DOTALL | re.MULTILINE) + + +def mini_changelog() -> str: + changelog_text = CHANGELOG_FILE.read_text() + + mini_changelog_match = FIRST_5_CHANGELOG_ENTRIES_REGEX.search(changelog_text) + assert mini_changelog_match, "Failed to find the first few changelog entries" + + return f"\n{mini_changelog_match.group(0).strip()}\n" + + +if __name__ == "__main__": + print(mini_changelog()) diff --git a/bin/update_readme_options_table.py b/bin/readme_options_table.py similarity index 60% rename from bin/update_readme_options_table.py rename to bin/readme_options_table.py index f78cbeac..203d6bf5 100755 --- a/bin/update_readme_options_table.py +++ b/bin/readme_options_table.py @@ -1,13 +1,11 @@ #!/usr/bin/env python3 -import argparse import dataclasses import re from pathlib import Path from typing import Final DIR: Final[Path] = Path(__file__).parent.parent.resolve() -README: Final[Path] = DIR / "README.md" OPTIONS_MD: Final[Path] = DIR / "docs" / "options.md" SECTION_HEADER_REGEX = re.compile(r"^## (?P.*?)$", re.MULTILINE) @@ -17,11 +15,6 @@ OPTION_HEADER_REGEX = re.compile( r"^### (?P.*?){.*#(?P\S+).*}\n+> ?(?P.*)$", re.MULTILINE ) -README_OPTIONS_TABLE_SECTION = re.compile( - r"""(?<=\n).*(?=)""", - re.DOTALL, -) - @dataclasses.dataclass(kw_only=True) class Option: @@ -31,17 +24,7 @@ class Option: section: str -def main() -> None: - parser = argparse.ArgumentParser( - description="Update the options table in the README from docs/options.md" - ) - parser.add_argument( - "--force", - action="store_true", - help="Updates the README inplace, rather than printing to stdout.", - ) - args = parser.parse_args() - +def get_table() -> str: options_md = OPTIONS_MD.read_text(encoding="utf-8") sections = SECTION_HEADER_REGEX.split(options_md)[1:] @@ -58,7 +41,7 @@ def main() -> None: ) options.append(option) - table_md = "\n\n" + table_md = "\n\n\n" table_md += "| | Option | Description |\n" table_md += "|---|---|---|\n" last_section: str | None = None @@ -78,21 +61,8 @@ def main() -> None: table_md += "| " + " | ".join(cells) + " |\n" table_md += "\n" - if not args.force: - print(table_md) - return - - readme_text = README.read_text(encoding="utf-8") - - if not re.search(README_OPTIONS_TABLE_SECTION, readme_text): - msg = "Options section not found in README" - raise ValueError(msg) - - readme_text = re.sub(README_OPTIONS_TABLE_SECTION, table_md, readme_text) - README.write_text(readme_text, encoding="utf-8") - - print("Updated README with options table.") + return table_md if __name__ == "__main__": - main() + print(get_table()) diff --git a/bin/update_readme_changelog.py b/bin/update_readme_changelog.py deleted file mode 100755 index 024a2337..00000000 --- a/bin/update_readme_changelog.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python3 - - -import re -import sys -from pathlib import Path - -PROJECT_ROOT = Path(__file__).parent / ".." -CHANGELOG_FILE = PROJECT_ROOT / "docs" / "changelog.md" -README_FILE = PROJECT_ROOT / "README.md" - -# https://regexr.com/622ds -FIRST_5_CHANGELOG_ENTRIES_REGEX = re.compile(r"""(^###.*?(?=###)){5}""", re.DOTALL | re.MULTILINE) - -# https://regexr.com/622e5 -README_CHANGELOG_SECTION = re.compile( - r"""(?<=\n).*(?=)""", - re.DOTALL, -) - - -def main() -> None: - changelog_text = CHANGELOG_FILE.read_text() - readme_text = README_FILE.read_text() - - mini_changelog_match = FIRST_5_CHANGELOG_ENTRIES_REGEX.search(changelog_text) - assert mini_changelog_match, "Failed to find the first few changelog entries" - - mini_changelog = "\n".join( - [ - "", - "", - "", - mini_changelog_match.group(0).strip(), - "", - "", - ] - ) - - if not re.search(README_CHANGELOG_SECTION, readme_text): - sys.exit("Changelog section not found in README") - - readme_text = re.sub(README_CHANGELOG_SECTION, mini_changelog, readme_text) - README_FILE.write_text(readme_text) - - -if __name__ == "__main__": - main()