@@ -186,6 +186,9 @@ def _create_whl_repos(module_ctx, pip_attr, whl_map, whl_overrides):
186186 group_deps = requirement_cycles .get (group_name , [])
187187
188188 repo_name = "{}_{}" .format (pip_name , whl_name )
189+ # print(repo_name)
190+ # print(pip_name)
191+ # print(dir(module_ctx))
189192 whl_library (
190193 name = repo_name ,
191194 requirement = requirement_line ,
@@ -332,39 +335,45 @@ def _pip_impl(module_ctx):
332335 for mod in module_ctx .modules :
333336 for pip_attr in mod .tags .parse :
334337 hub_name = pip_attr .hub_name
335- if hub_name not in pip_hub_map :
338+ # only override if the module is root.
339+ override = mod .is_root and pip_attr .override
340+ if hub_name not in pip_hub_map or override :
336341 pip_hub_map [pip_attr .hub_name ] = struct (
337342 module_name = mod .name ,
338343 python_versions = [pip_attr .python_version ],
344+ pip_attr = pip_attr ,
345+ override = override
339346 )
340- elif pip_hub_map [hub_name ].module_name != mod .name :
341- # We cannot have two hubs with the same name in different
342- # modules.
343- fail ((
344- "Duplicate cross-module pip hub named '{hub}': pip hub " +
345- "names must be unique across modules. First defined " +
346- "by module '{first_module}', second attempted by " +
347- "module '{second_module}'"
348- ).format (
349- hub = hub_name ,
350- first_module = pip_hub_map [hub_name ].module_name ,
351- second_module = mod .name ,
352- ))
353-
354- elif pip_attr .python_version in pip_hub_map [hub_name ].python_versions :
355- fail ((
356- "Duplicate pip python version '{version}' for hub " +
357- "'{hub}' in module '{module}': the Python versions " +
358- "used for a hub must be unique"
359- ).format (
360- hub = hub_name ,
361- module = mod .name ,
362- version = pip_attr .python_version ,
363- ))
364- else :
365- pip_hub_map [pip_attr .hub_name ].python_versions .append (pip_attr .python_version )
366-
367- _create_whl_repos (module_ctx , pip_attr , hub_whl_map , whl_overrides )
347+ elif not pip_hub_map [hub_name ].pip_attr .override :
348+ if pip_hub_map [hub_name ].module_name != mod .name :
349+ # We cannot have two hubs with the same name in different
350+ # modules.
351+ fail ((
352+ "Duplicate cross-module pip hub named '{hub}': pip hub " +
353+ "names must be unique across modules. First defined " +
354+ "by module '{first_module}', second attempted by " +
355+ "module '{second_module}'"
356+ ).format (
357+ hub = hub_name ,
358+ first_module = pip_hub_map [hub_name ].module_name ,
359+ second_module = mod .name ,
360+ ))
361+
362+ elif pip_attr .python_version in pip_hub_map [hub_name ].python_versions :
363+ fail ((
364+ "Duplicate pip python version '{version}' for hub " +
365+ "'{hub}' in module '{module}': the Python versions " +
366+ "used for a hub must be unique"
367+ ).format (
368+ hub = hub_name ,
369+ module = mod .name ,
370+ version = pip_attr .python_version ,
371+ ))
372+ else :
373+ pip_hub_map [pip_attr .hub_name ].python_versions .append (pip_attr .python_version )
374+
375+ for value in pip_hub_map .values ():
376+ _create_whl_repos (module_ctx , value .pip_attr , hub_whl_map , whl_overrides )
368377
369378 for hub_name , whl_map in hub_whl_map .items ():
370379 pip_repository (
@@ -421,6 +430,12 @@ A dict of labels to wheel names that is typically generated by the whl_modificat
421430The labels are JSON config files describing the modifications.
422431""" ,
423432 ),
433+ "override" : attr .bool (
434+ default = False ,
435+ doc = """
436+ If the module is root, this may override any hub_name's listed in the dependencies.
437+ """
438+ ),
424439 }, ** pip_repository_attrs )
425440
426441 # Like the pip_repository rule, we end up setting this manually so
0 commit comments