Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding short commit to
version_info
(#8145)
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
- Loading branch information
1 parent
f42dc2f
commit 575dcd9
Showing
3 changed files
with
48 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Git utilities, adopted from mypy's git utilities (https://github.com/python/mypy/blob/master/mypy/git.py).""" | ||
from __future__ import annotations | ||
|
||
import os | ||
import subprocess | ||
|
||
|
||
def is_git_repo(dir: str) -> bool: | ||
"""Is the given directory version-controlled with git?""" | ||
return os.path.exists(os.path.join(dir, '.git')) | ||
|
||
|
||
def have_git() -> bool: | ||
"""Can we run the git executable?""" | ||
try: | ||
subprocess.check_output(['git', '--help']) | ||
return True | ||
except subprocess.CalledProcessError: | ||
return False | ||
except OSError: | ||
return False | ||
|
||
|
||
def git_revision(dir: str) -> str: | ||
"""Get the SHA-1 of the HEAD of a git repository.""" | ||
return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], cwd=dir).decode('utf-8').strip() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters