MCPcopy Create free account
hub / github.com/AMAP-ML/EMF / get_git_commit_hash

Function get_git_commit_hash

trl/trl/scripts/utils.py:264–284  ·  view source on GitHub ↗
(package_name)

Source from the content-addressed store, hash-verified

262
263
264def get_git_commit_hash(package_name):
265 try:
266 # Import the package to locate its path
267 package = importlib.import_module(package_name)
268 # Get the path to the package using inspect
269 package_path = os.path.dirname(inspect.getfile(package))
270
271 # Navigate up to the Git repository root if the package is inside a subdirectory
272 git_repo_path = os.path.abspath(os.path.join(package_path, ".."))
273 git_dir = os.path.join(git_repo_path, ".git")
274
275 if os.path.isdir(git_dir):
276 # Run the git command to get the current commit hash
277 commit_hash = (
278 subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=git_repo_path).strip().decode("utf-8")
279 )
280 return commit_hash
281 else:
282 return None
283 except Exception as e:
284 return f"Error: {str(e)}"

Callers 1

print_envFunction · 0.85

Calls 1

decodeMethod · 0.45

Tested by

no test coverage detected