Skip to content

Commit cd0eb7e

Browse files
committed
fix(version): do not lookup parent .git for git version detection
1 parent af416db commit cd0eb7e

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

.editorconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ insert_final_newline = true
1212

1313
[*.py]
1414
indent_size = 4
15-
src_paths=nvitop
1615

1716
[*.{yaml,yml,json,xml}]
1817
indent_size = 2

nvitop-exporter/nvitop_exporter/version.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@
2828
import os
2929
import subprocess
3030

31+
root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
3132
try:
3233
prefix, sep, suffix = (
3334
subprocess.check_output( # noqa: S603
34-
['git', 'describe', '--abbrev=7'], # noqa: S607
35-
cwd=os.path.dirname(os.path.abspath(__file__)),
35+
[ # noqa: S607
36+
'git',
37+
f'--git-dir={os.path.join(root_dir, ".git")}',
38+
'describe',
39+
'--abbrev=7',
40+
],
41+
cwd=root_dir,
3642
stderr=subprocess.DEVNULL,
3743
text=True,
3844
)
@@ -53,4 +59,4 @@
5359
except (OSError, subprocess.CalledProcessError):
5460
pass
5561

56-
del os, subprocess
62+
del os, subprocess, root_dir

nvitop/version.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@
2828
import os
2929
import subprocess
3030

31+
root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
3132
try:
3233
prefix, sep, suffix = (
3334
subprocess.check_output( # noqa: S603
34-
['git', 'describe', '--abbrev=7'], # noqa: S607
35-
cwd=os.path.dirname(os.path.abspath(__file__)),
35+
[ # noqa: S607
36+
'git',
37+
f'--git-dir={os.path.join(root_dir, ".git")}',
38+
'describe',
39+
'--abbrev=7',
40+
],
41+
cwd=root_dir,
3642
stderr=subprocess.DEVNULL,
3743
text=True,
3844
)
@@ -53,7 +59,8 @@
5359
except (OSError, subprocess.CalledProcessError):
5460
pass
5561

56-
del os, subprocess
62+
del os, subprocess, root_dir
63+
5764

5865
# The package `nvidia-ml-py` is not backward compatible over releases. This may
5966
# cause problems with Old versions of NVIDIA drivers.

0 commit comments

Comments
 (0)