Support running icefall outside of a git tracked directory. (#470)

* Support running icefall outside of a git tracked directory.

* Minor fixes.
This commit is contained in:
Fangjun Kuang 2022-07-08 15:03:07 +08:00 committed by GitHub
parent e5fdbcd480
commit 6c69c4e253
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,20 +29,10 @@ import torch
def get_git_sha1():
git_commit = (
subprocess.run(
["git", "rev-parse", "--short", "HEAD"],
check=True,
stdout=subprocess.PIPE,
)
.stdout.decode()
.rstrip("\n")
.strip()
)
dirty_commit = (
len(
try:
git_commit = (
subprocess.run(
["git", "diff", "--shortstat"],
["git", "rev-parse", "--short", "HEAD"],
check=True,
stdout=subprocess.PIPE,
)
@ -50,39 +40,61 @@ def get_git_sha1():
.rstrip("\n")
.strip()
)
> 0
)
git_commit = (
git_commit + "-dirty" if dirty_commit else git_commit + "-clean"
)
dirty_commit = (
len(
subprocess.run(
["git", "diff", "--shortstat"],
check=True,
stdout=subprocess.PIPE,
)
.stdout.decode()
.rstrip("\n")
.strip()
)
> 0
)
git_commit = (
git_commit + "-dirty" if dirty_commit else git_commit + "-clean"
)
except: # noqa
return None
return git_commit
def get_git_date():
git_date = (
subprocess.run(
["git", "log", "-1", "--format=%ad", "--date=local"],
check=True,
stdout=subprocess.PIPE,
try:
git_date = (
subprocess.run(
["git", "log", "-1", "--format=%ad", "--date=local"],
check=True,
stdout=subprocess.PIPE,
)
.stdout.decode()
.rstrip("\n")
.strip()
)
.stdout.decode()
.rstrip("\n")
.strip()
)
except: # noqa
return None
return git_date
def get_git_branch_name():
git_date = (
subprocess.run(
["git", "rev-parse", "--abbrev-ref", "HEAD"],
check=True,
stdout=subprocess.PIPE,
try:
git_date = (
subprocess.run(
["git", "rev-parse", "--abbrev-ref", "HEAD"],
check=True,
stdout=subprocess.PIPE,
)
.stdout.decode()
.rstrip("\n")
.strip()
)
.stdout.decode()
.rstrip("\n")
.strip()
)
except: # noqa
return None
return git_date