Files
spark/tools/py/core/git_utils.py
2026-01-04 21:18:58 +00:00

27 lines
757 B
Python

import subprocess
from typing import Optional
def git_head_version(revision: Optional[str] = None, check: bool = True):
def run_captured(*args):
res = subprocess.run(
args,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
check=check,
)
return res.stdout
args = ["git", "describe", "--tags", "--always"]
if revision:
args += revision
vers = run_captured(*args).rstrip()
if vers.startswith("v") and "." in vers:
vers = vers[1:]
if check and not vers:
raise ValueError(
"Failed to generate spark version identifier. Please re-run pack_sdk.py with --spark-version <VERSION>"
)
return vers