@@ -1860,15 +1860,14 @@ def build_options(
1860
1860
)
1861
1861
1862
1862
# Parse the output into a structured format
1863
- result = GitVersionInfo (version = "" )
1864
-
1865
- # First line is always "git version X.Y.Z"
1866
1863
lines = output .strip ().split ("\n " )
1867
1864
if not lines or not lines [0 ].startswith ("git version " ):
1868
- raise InvalidBuildOptions (output )
1865
+ first_line = lines [0 ] if lines else "(empty)"
1866
+ msg = f"Expected 'git version' in first line, got: { first_line } "
1867
+ raise InvalidBuildOptions (msg )
1869
1868
1870
1869
version_str = lines [0 ].replace ("git version " , "" ).strip ()
1871
- result . version = version_str
1870
+ result = GitVersionInfo ( version = version_str )
1872
1871
1873
1872
# Parse semantic version components
1874
1873
try :
@@ -1882,30 +1881,37 @@ def build_options(
1882
1881
# Fall back to string-only if can't be parsed
1883
1882
result .version_info = None
1884
1883
1885
- # Parse additional build info
1884
+ # Field mapping with type annotations for clarity
1885
+ field_mapping : dict [str , str ] = {
1886
+ "cpu" : "cpu" ,
1887
+ "sizeof-long" : "sizeof_long" ,
1888
+ "sizeof-size_t" : "sizeof_size_t" ,
1889
+ "shell-path" : "shell_path" ,
1890
+ "commit" : "commit" ,
1891
+ }
1892
+
1893
+ # Parse build options
1886
1894
for line in lines [1 :]:
1887
1895
line = line .strip ()
1888
1896
if not line :
1889
1897
continue
1890
1898
1891
- if ":" in line :
1892
- key , value = line .split (":" , 1 )
1893
- key = key .strip ()
1894
- value = value .strip ()
1895
-
1896
- if key == "cpu" :
1897
- result .cpu = value
1898
- elif key == "sizeof-long" :
1899
- result .sizeof_long = value
1900
- elif key == "sizeof-size_t" :
1901
- result .sizeof_size_t = value
1902
- elif key == "shell-path" :
1903
- result .shell_path = value
1904
- elif key == "commit" :
1905
- result .commit = value
1906
- # Special handling for the "no commit" line which has no colon
1907
- elif "no commit associated with this build" in line .lower ():
1899
+ # Special case for "no commit" message
1900
+ if "no commit associated with this build" in line .lower ():
1908
1901
result .commit = line
1902
+ continue
1903
+
1904
+ # Parse key:value pairs
1905
+ if ":" not in line :
1906
+ # Log unexpected format but don't fail
1907
+ continue
1908
+
1909
+ key , _ , value = line .partition (":" )
1910
+ key = key .strip ()
1911
+ value = value .strip ()
1912
+
1913
+ if key in field_mapping :
1914
+ setattr (result , field_mapping [key ], value )
1909
1915
1910
1916
return result
1911
1917
0 commit comments