Skip to content

Commit a2c4655

Browse files
committed
make pyGithub optional
1 parent 1a41ba3 commit a2c4655

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

tools/update_module_latest.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@
3434
from dataclasses import dataclass
3535
from urllib.parse import urlparse
3636

37-
from github import Github, GithubException
37+
try:
38+
from github import Github, GithubException
39+
HAS_PYGITHUB = True
40+
except ImportError:
41+
HAS_PYGITHUB = False
42+
Github = None
43+
GithubException = None
3844

3945

4046
@dataclass
@@ -66,6 +72,8 @@ def owner_repo(self) -> str:
6672

6773
def fetch_latest_commit(owner_repo: str, branch: str, token: str | None) -> str:
6874
"""Fetch latest commit sha for given owner_repo & branch using PyGithub."""
75+
if not HAS_PYGITHUB:
76+
raise RuntimeError("PyGithub not installed. Install it with: pip install PyGithub")
6977
try:
7078
gh = Github(token) if token else Github()
7179
repo = gh.get_repo(owner_repo)
@@ -167,6 +175,13 @@ def main(argv: list[str]) -> int:
167175
updated: list[Module] = []
168176
# Default: use gh if available unless --no-gh specified
169177
use_gh = (not args.no_gh) and shutil.which("gh") is not None
178+
179+
# If PyGithub is not available and gh CLI is not available, error out
180+
if not use_gh and not HAS_PYGITHUB:
181+
print("ERROR: Neither 'gh' CLI nor PyGithub library found.", file=sys.stderr)
182+
print("Please install PyGithub (pip install PyGithub) or install GitHub CLI.", file=sys.stderr)
183+
return 3
184+
170185
if not args.no_gh and not use_gh:
171186
print("INFO: 'gh' CLI not found; using direct GitHub API", file=sys.stderr)
172187
if args.no_gh and shutil.which("gh") is not None:

0 commit comments

Comments
 (0)