@@ -1860,15 +1860,14 @@ def build_options(
18601860 )
18611861
18621862 # Parse the output into a structured format
1863- result = GitVersionInfo (version = "" )
1864-
1865- # First line is always "git version X.Y.Z"
18661863 lines = output .strip ().split ("\n " )
18671864 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 )
18691868
18701869 version_str = lines [0 ].replace ("git version " , "" ).strip ()
1871- result . version = version_str
1870+ result = GitVersionInfo ( version = version_str )
18721871
18731872 # Parse semantic version components
18741873 try :
@@ -1882,30 +1881,37 @@ def build_options(
18821881 # Fall back to string-only if can't be parsed
18831882 result .version_info = None
18841883
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
18861894 for line in lines [1 :]:
18871895 line = line .strip ()
18881896 if not line :
18891897 continue
18901898
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 ():
19081901 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 )
19091915
19101916 return result
19111917
0 commit comments