41
41
42
42
43
43
def get_git_revision_hash () -> str :
44
- """ Get the git commit hash of the current repository.
44
+ """Get the git commit hash of the current repository.
45
45
46
46
This function will return the git commit hash of the current repository, or None if
47
47
the current directory is not a git repository.
@@ -57,12 +57,19 @@ def get_git_revision_hash() -> str:
57
57
os .chdir (file_directory )
58
58
59
59
try :
60
- is_git_repo = subprocess .check_output (
61
- ["git" , "rev-parse" , "--is-inside-work-tree" ],
62
- stderr = subprocess .DEVNULL ).decode ("ascii" ).strip ()
60
+ is_git_repo = (
61
+ subprocess .check_output (
62
+ ["git" , "rev-parse" , "--is-inside-work-tree" ], stderr = subprocess .DEVNULL
63
+ )
64
+ .decode ("ascii" )
65
+ .strip ()
66
+ )
63
67
if is_git_repo :
64
- commit_hash = subprocess .check_output (
65
- ["git" , "rev-parse" , "HEAD" ]).decode ("ascii" ).strip ()
68
+ commit_hash = (
69
+ subprocess .check_output (["git" , "rev-parse" , "HEAD" ])
70
+ .decode ("ascii" )
71
+ .strip ()
72
+ )
66
73
else :
67
74
commit_hash = None
68
75
except subprocess .CalledProcessError :
@@ -71,8 +78,9 @@ def get_git_revision_hash() -> str:
71
78
os .chdir (working_directory )
72
79
return commit_hash
73
80
74
- def get_version_from_file (file_name = 'VERSION' ):
75
- """ Retrieve the version from a file in the same directory as this file.
81
+
82
+ def get_version_from_file (file_name = "VERSION" ):
83
+ """Retrieve the version from a file in the same directory as this file.
76
84
77
85
The VERSION file located in src/navigate/VERSION contains the version of the
78
86
package when deployed to PyPI.
@@ -91,12 +99,13 @@ def get_version_from_file(file_name='VERSION'):
91
99
file_path = os .path .join (os .path .dirname (absolute_path ), file_name )
92
100
93
101
try :
94
- with open (file_path , 'r' ) as file :
102
+ with open (file_path , "r" ) as file :
95
103
version = file .read ().strip ()
96
104
return version
97
105
except FileNotFoundError :
98
106
return "unknown"
99
107
108
+
100
109
__commit__ = get_git_revision_hash ()
101
110
if __commit__ is None :
102
111
__commit__ = get_version_from_file ()
0 commit comments