Skip to content

Commit

Permalink
[apache#4695] Fix (python-client): Fix gradlew :clients:client-python…
Browse files Browse the repository at this point in the history
…:build failed if the package does not contain .git directory (apache#4705)

### What changes were proposed in this pull request?

Fix gradlew :clients:client-python:build failed if the package does not
contain .git directory

### Why are the changes needed?

Fix: apache#4695 

### Does this PR introduce _any_ user-facing change?

NO

### How was this patch tested?

Manually test

Co-authored-by: Yuhui <hui@datastrato.com>
  • Loading branch information
github-actions[bot] and diqiu50 authored Aug 27, 2024
1 parent e98df1b commit 6a17512
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions clients/client-python/gravitino/constants/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@

MODULE_NAME = "gravitino"
PROJECT_HOME = Path(__file__).parent.parent.parent
PROJECT_ROOT = PROJECT_HOME.parent.parent
GRAVITINO_DIR = PROJECT_HOME / MODULE_NAME
24 changes: 20 additions & 4 deletions clients/client-python/scripts/generate_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,35 @@
under the License.
"""

# coding=utf-8

import re
import configparser
import subprocess
from datetime import datetime
from gravitino.constants.root import PROJECT_ROOT

from gravitino.constants.version import Version, VERSION_INI, SETUP_FILE
from gravitino.exceptions.base import GravitinoRuntimeException

VERSION_PATTERN = r"version\s*=\s*['\"]([^'\"]+)['\"]"


def get_git_commit_id():
try:
commit_id = ""
git_path = f"{PROJECT_ROOT}/.git/"
with open(git_path + "HEAD", "r", encoding="utf-8") as file:
ref = file.readline().strip()

if ref.startswith("ref:"):
ref_path = ref.split(" ")[1]
with open(git_path + ref_path, "r", encoding="utf-8") as file:
commit_id = file.readline().strip()
return commit_id
except (FileNotFoundError, IOError):
return ""


def main():
with open(SETUP_FILE, "r", encoding="utf-8") as f:
setup_content = f.read()
Expand All @@ -37,9 +55,7 @@ def main():
else:
raise GravitinoRuntimeException("Can't find valid version info in setup.py")

git_commit = (
subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ascii").strip()
)
git_commit = get_git_commit_id()

compile_date = datetime.now().strftime("%d/%m/%Y %H:%M:%S")

Expand Down

0 comments on commit 6a17512

Please sign in to comment.