Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
MMCV
Commits
d36850f5
Unverified
Commit
d36850f5
authored
Aug 03, 2020
by
Wenwei Zhang
Committed by
GitHub
Aug 03, 2020
Browse files
Add git hash (#461)
* Add git hash * Add fallback * Add func in mmcv.utils
parent
60ce48d1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
mmcv/utils/__init__.py
mmcv/utils/__init__.py
+4
-2
mmcv/utils/version_utils.py
mmcv/utils/version_utils.py
+29
-0
No files found.
mmcv/utils/__init__.py
View file @
d36850f5
...
...
@@ -10,6 +10,7 @@ from .path import (check_file_exist, fopen, is_filepath, mkdir_or_exist,
from
.progressbar
import
(
ProgressBar
,
track_iter_progress
,
track_parallel_progress
,
track_progress
)
from
.timer
import
Timer
,
TimerError
,
check_time
from
.version_utils
import
get_git_hash
try
:
import
torch
...
...
@@ -21,7 +22,8 @@ except ImportError:
'requires_executable'
,
'is_filepath'
,
'fopen'
,
'check_file_exist'
,
'mkdir_or_exist'
,
'symlink'
,
'scandir'
,
'ProgressBar'
,
'track_progress'
,
'track_iter_progress'
,
'track_parallel_progress'
,
'Timer'
,
'TimerError'
,
'check_time'
,
'deprecated_api_warning'
'Timer'
,
'TimerError'
,
'check_time'
,
'deprecated_api_warning'
,
'get_git_hash'
]
else
:
from
.env
import
TORCH_VERSION
...
...
@@ -46,5 +48,5 @@ else:
'_AvgPoolNd'
,
'_BatchNorm'
,
'_ConvNd'
,
'_ConvTransposeMixin'
,
'_InstanceNorm'
,
'_MaxPoolNd'
,
'get_build_config'
,
'BuildExtension'
,
'CppExtension'
,
'CUDAExtension'
,
'DataLoader'
,
'PoolDataLoader'
,
'TORCH_VERSION'
,
'deprecated_api_warning'
'TORCH_VERSION'
,
'deprecated_api_warning'
,
'get_git_hash'
]
mmcv/utils/version_utils.py
0 → 100644
View file @
d36850f5
import
os
import
subprocess
def
get_git_hash
(
fallback
=
'unknown'
):
# Get git hash of the current repo
def
_minimal_ext_cmd
(
cmd
):
# construct minimal environment
env
=
{}
for
k
in
[
'SYSTEMROOT'
,
'PATH'
,
'HOME'
]:
v
=
os
.
environ
.
get
(
k
)
if
v
is
not
None
:
env
[
k
]
=
v
# LANGUAGE is used on win32
env
[
'LANGUAGE'
]
=
'C'
env
[
'LANG'
]
=
'C'
env
[
'LC_ALL'
]
=
'C'
out
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
env
=
env
).
communicate
()[
0
]
return
out
try
:
out
=
_minimal_ext_cmd
([
'git'
,
'rev-parse'
,
'HEAD'
])
sha
=
out
.
strip
().
decode
(
'ascii'
)
except
OSError
:
sha
=
fallback
return
sha
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment