-
Notifications
You must be signed in to change notification settings - Fork 0
Publish to Homebrew on release #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+132
−4
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #!/usr/bin/env python3 | ||
| """Update the RegShape Homebrew formula to a given version. | ||
|
|
||
| Fetches the sdist URL and sha256 for ``regshape==<version>`` from PyPI and | ||
| rewrites the top-level ``url``/``sha256`` fields of the formula (the package | ||
| source, not the dependency ``resource`` blocks). | ||
|
|
||
| Usage: | ||
| python bump_formula.py <version> | ||
|
|
||
| The formula is always read from and written to a fixed, constant path relative to | ||
| the current working directory, so no caller-supplied data is ever used to build a | ||
| filesystem path. Run this script from the tap checkout root. | ||
| """ | ||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import re | ||
| import sys | ||
| import time | ||
| import urllib.request | ||
|
|
||
| # Constant path (relative to CWD); never derived from user input. | ||
| FORMULA_PATH = "Formula/regshape.rb" | ||
|
|
||
|
|
||
| def fetch_sdist(version: str) -> tuple[str, str]: | ||
| url = f"https://pypi.org/pypi/regshape/{version}/json" | ||
| last_err: Exception | None = None | ||
| for _ in range(30): | ||
| try: | ||
| with urllib.request.urlopen(url, timeout=30) as resp: | ||
| data = json.load(resp) | ||
| for entry in data["urls"]: | ||
| if entry["packagetype"] == "sdist": | ||
| return entry["url"], entry["digests"]["sha256"] | ||
| raise RuntimeError(f"No sdist found for regshape {version}") | ||
| except Exception as err: # noqa: BLE001 - retry on propagation delay | ||
| last_err = err | ||
| time.sleep(10) | ||
| raise RuntimeError(f"regshape {version} not available on PyPI: {last_err}") | ||
|
|
||
|
|
||
| def bump(version: str) -> None: | ||
| sdist_url, sha256 = fetch_sdist(version) | ||
| with open(FORMULA_PATH, encoding="utf-8") as fh: | ||
| text = fh.read() | ||
| # Only the top-level fields are indented with exactly two spaces; resource | ||
| # blocks use four spaces, so anchored two-space matches target the package. | ||
| text, n_url = re.subn(r'^ url ".*"$', f' url "{sdist_url}"', text, count=1, flags=re.M) | ||
| text, n_sha = re.subn(r'^ sha256 ".*"$', f' sha256 "{sha256}"', text, count=1, flags=re.M) | ||
| if n_url != 1 or n_sha != 1: | ||
| raise RuntimeError("Failed to locate top-level url/sha256 in formula") | ||
| with open(FORMULA_PATH, "w", encoding="utf-8") as fh: | ||
| fh.write(text) | ||
| print(f"Bumped {FORMULA_PATH} to regshape {version}") | ||
| print(f" url {sdist_url}") | ||
| print(f" sha256 {sha256}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| if len(sys.argv) != 2: | ||
| sys.exit("usage: bump_formula.py <version>") | ||
| bump(sys.argv[1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.