Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const releaseSensitivePatterns = [
/^\.codex\//,
];

/**
* @returns {string[]} List of staged file paths
*/
const getStagedFiles = () => {
try {
return execSync('git diff --cached --name-only', { encoding: 'utf8' }).split('\n').filter(Boolean);
Expand All @@ -17,6 +20,10 @@ const getStagedFiles = () => {
}
};

/**
* @param {{ type: string | null | undefined }} parsed - Parsed commit message object
* @returns {[true] | [false, string]} Validation result: [true] on pass, [false, message] on fail
*/
const releaseTypeRule = (parsed) => {
const files = getStagedFiles();
const touched = files.filter((file) => releaseSensitivePatterns.some((pattern) => pattern.test(file)));
Expand Down
28 changes: 20 additions & 8 deletions script/lib/brew_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import sys
from pathlib import Path
from typing import Any


def parse_args() -> argparse.Namespace:
Expand All @@ -25,15 +26,15 @@ def parse_args() -> argparse.Namespace:
return parser.parse_args()


def load_manifest(path: Path) -> dict:
def load_manifest(path: Path) -> dict[str, Any]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep brew_categories compatible with Python 3.8

When brew-deps.sh runs on a machine where python3 is still Python 3.8, this annotation is evaluated at import time and dict[str, Any] raises TypeError: 'type' object is not subscriptable before the script can do any work. The wrapper only checks that python3 exists and the docs advertise this as a generic Homebrew helper, so this change regresses users with older but still common python3 installations unless annotations are postponed or typing.Dict/List style is used.

Useful? React with 👍 / 👎.

try:
with path.open() as fh:
return json.load(fh)
except FileNotFoundError as exc:
raise SystemExit(f"Manifest not found: {path}") from exc


def matches(match_spec: dict, item: str) -> bool:
def matches(match_spec: dict[str, Any], item: str) -> bool:
if any(item == exact for exact in match_spec.get("exact", [])):
return True
if any(item.startswith(prefix) for prefix in match_spec.get("prefix", [])):
Expand All @@ -44,9 +45,12 @@ def matches(match_spec: dict, item: str) -> bool:
return False


def categorize(items, categories):
assigned = set()
sections = []
def categorize(
items: list[str],
categories: list[dict[str, Any]],
) -> tuple[list[tuple[str, list[str]]], list[str]]:
assigned: set[str] = set()
sections: list[tuple[str, list[str]]] = []
for category in categories:
match_spec = category.get("match", {})
matched = [item for item in items if item not in assigned and matches(match_spec, item)]
Expand All @@ -57,7 +61,11 @@ def categorize(items, categories):
return sections, remaining


def emit_human(sections, remaining, show_uncategorized: bool):
def emit_human(
sections: list[tuple[str, list[str]]],
remaining: list[str],
show_uncategorized: bool,
) -> None:
for title, rows in sections:
print(f"=== {title} ===")
print("\n".join(rows) if rows else "")
Expand All @@ -67,7 +75,11 @@ def emit_human(sections, remaining, show_uncategorized: bool):
print("\n".join(remaining) if remaining else "")


def emit_brew(sections, remaining, item_type):
def emit_brew(
sections: list[tuple[str, list[str]]],
remaining: list[str],
item_type: str,
) -> None:
keyword = "brew" if item_type == "formulae" else "cask"
for title, rows in sections:
if not rows:
Expand All @@ -83,7 +95,7 @@ def emit_brew(sections, remaining, item_type):
print()


def main():
def main() -> None:
args = parse_args()
manifest = load_manifest(Path(args.manifest))
items = [line.strip() for line in sys.stdin if line.strip()]
Expand Down
Loading