@@ -41,14 +41,20 @@ def check_git(*args: str, cwd: Optional[str]):
41
41
cmd .extend (["-C" , cwd ])
42
42
cmd .extend (args )
43
43
44
- with subprocess .Popen (
45
- cmd ,
46
- stdout = subprocess .PIPE ,
47
- universal_newlines = True ,
48
- stderr = subprocess .DEVNULL ,
49
- ) as proc :
50
- if proc .stdout :
51
- return proc .stdout .readlines ()[0 ].strip ()
44
+ try :
45
+ with subprocess .Popen (
46
+ cmd ,
47
+ stdout = subprocess .PIPE ,
48
+ universal_newlines = True ,
49
+ stderr = subprocess .DEVNULL ,
50
+ ) as proc :
51
+ if proc .stdout :
52
+ lines = proc .stdout .readlines ()
53
+ return lines [0 ].strip ()
54
+ except IndexError :
55
+ pass
56
+ except FileNotFoundError :
57
+ pass
52
58
53
59
return ""
54
60
@@ -68,10 +74,7 @@ def git(*args):
68
74
return check_git (* args , cwd = git_cwd )
69
75
70
76
git_ver = "0" * hash_length
71
- try :
72
- git_ver = git ("rev-parse" , f"--short={ hash_length } " , "HEAD" )
73
- except Exception :
74
- raise
77
+ git_ver = git ("rev-parse" , f"--short={ hash_length } " , "HEAD" ) or git_ver
75
78
76
79
# version is
77
80
# - using Arduino-CLI:
@@ -80,22 +83,20 @@ def git(*args):
80
83
# - using git:
81
84
# - 5.6.7 (from release script, official release)
82
85
# - 5.6.7-42-g00d1e5 (from release script, test release)
83
- git_desc = version
84
- try :
85
- # in any case, get a better version when git is around
86
- git_desc = git ("describe" , "--tags" )
87
- except Exception :
88
- raise
86
+
87
+ # in any case, get a better version when git is around
88
+ git_desc = git ("describe" , "--tags" ) or version
89
89
90
90
if version == VERSION_UNSPECIFIED :
91
91
version = git_desc
92
92
93
93
version_triple = list (VERSION_DEFAULT )
94
94
95
- try :
96
- version_triple = version .split ("." , 2 )
97
- except ValueError :
98
- pass
95
+ if version != VERSION_UNSPECIFIED :
96
+ try :
97
+ version_triple = version .split ("." , 2 )
98
+ except ValueError :
99
+ pass
99
100
100
101
major , minor , patch = version_triple
101
102
0 commit comments