@@ -207,26 +207,65 @@ def parse_requirements(
207207 # Return normalized names
208208 ret_requirements = ret .setdefault (normalize_name (whl_name ), [])
209209
210+ # First, find if there's a common sdist across all platforms
211+ common_sdist = None
212+ common_sdist_hash = None
213+ all_platforms = []
210214 for r in sorted (reqs .values (), key = lambda r : r .requirement_line ):
215+ target_platforms = env_marker_target_platforms .get (r .requirement_line , r .target_platforms )
216+ all_platforms .extend (target_platforms )
211217 whls , sdist = _add_dists (
212218 requirement = r ,
213219 index_urls = index_urls .get (whl_name ),
214220 logger = logger ,
215221 )
216-
217- target_platforms = env_marker_target_platforms .get (r .requirement_line , r .target_platforms )
222+ if sdist :
223+ if not common_sdist :
224+ common_sdist = sdist
225+ common_sdist_hash = sdist .sha256
226+ elif sdist .sha256 == common_sdist_hash :
227+ continue
228+ else :
229+ common_sdist = None
230+ break
231+
232+ # If we found a common sdist, add it as a separate entry
233+ if common_sdist :
234+ # Take the first requirement's info as base since version should be same
235+ base_req = sorted (reqs .values (), key = lambda r : r .requirement_line )[0 ]
218236 ret_requirements .append (
219237 struct (
220- distribution = r .distribution ,
221- srcs = r .srcs ,
222- target_platforms = sorted (target_platforms ),
223- extra_pip_args = r .extra_pip_args ,
224- whls = whls ,
225- sdist = sdist ,
238+ distribution = base_req .distribution ,
239+ srcs = base_req .srcs ,
240+ target_platforms = sorted (all_platforms ),
241+ extra_pip_args = base_req .extra_pip_args ,
242+ whls = [] ,
243+ sdist = common_sdist ,
226244 is_exposed = is_exposed ,
227245 ),
228246 )
229247
248+ # Now add platform-specific entries with wheels
249+ for r in sorted (reqs .values (), key = lambda r : r .requirement_line ):
250+ whls , sdist = _add_dists (
251+ requirement = r ,
252+ index_urls = index_urls .get (whl_name ),
253+ logger = logger ,
254+ )
255+ if not common_sdist or len (whls ) > 0 : # Only add entries that have wheels
256+ target_platforms = env_marker_target_platforms .get (r .requirement_line , r .target_platforms )
257+ ret_requirements .append (
258+ struct (
259+ distribution = r .distribution ,
260+ srcs = r .srcs ,
261+ target_platforms = sorted (target_platforms ),
262+ extra_pip_args = r .extra_pip_args ,
263+ whls = whls ,
264+ sdist = None if common_sdist else sdist , # No sdist in wheel-specific entries
265+ is_exposed = is_exposed ,
266+ ),
267+ )
268+
230269 if logger :
231270 logger .debug (lambda : "Will configure whl repos: {}" .format (ret .keys ()))
232271
0 commit comments