@@ -361,18 +361,30 @@ def showcase_library(
361361 # Install the library with a constraints file.
362362 session .install ("-e" , tmp_dir , "-r" , constraints_path )
363363 else :
364- # modify constraints file to support async_rest min constraints
364+ # Modify constraints file to support async_rest min constraints.
365+ # TODO: Move into own contraints-async-rest.txt file once
366+ # async-rest is fully supported
365367 async_rest_constraints = {
366368 "google-auth" : "2.35.0" ,
367369 "google-api-core" : "2.21.0" ,
368370 }
371+ with open (constraints_path ) as f :
372+ constraints_lines = [
373+ line .strip ()
374+ for line in f
375+ if line .strip () and not line .startswith ("#" )
376+ ]
377+ # Only modify dependencies in the original constraints file.
378+ replace_keys = {
379+ key for key in async_rest_constraints
380+ if any (line .startswith (key ) for line in constraints_lines )
381+ }
382+ # Replace async_rest constraints in final output.
369383 constraints = [
370- line .strip ()
371- for line in open (constraints_path )
372- if all ([key not in line for key in async_rest_constraints .keys ()])
373- and not line .startswith ("#" )
374- and line .strip ()
375- ] + [f"{ key } =={ value } " for key , value in async_rest_constraints .items ()]
384+ line for line in original_lines
385+ if not any (line .startswith (key ) for key in replace_keys )
386+ ] + [f"{ k } =={ async_rest_constraints [k ]} " for k in replace_keys ]
387+
376388 session .install ("-e" , f"{ tmp_dir } [async_rest]" , * constraints )
377389 else :
378390 # The ads templates do not have constraints files.
0 commit comments