@@ -211,11 +211,11 @@ def _create_whl_repos(
211211 pip_attr ,
212212 whl_overrides ,
213213 requirements_to_whl_libraries ,
214+ logger ,
214215 ** whl_library_args ):
215216 exposed_packages = {}
216217 whl_libraries = {}
217218 whl_map = {}
218- logger = repo_utils .logger (module_ctx , "pypi:create_whl_repos" )
219219
220220 hub_name = pip_attr .hub_name
221221 pip_name = "{}_{}" .format (
@@ -295,27 +295,33 @@ def _create_whl_repos(
295295 whl_map = whl_map ,
296296 )
297297
298- def parse_modules (module_ctx , _fail = fail , simpleapi_download = simpleapi_download , available_interpreters = INTERPRETER_LABELS ):
298+ def parse_modules (
299+ module_ctx ,
300+ simpleapi_download = simpleapi_download ,
301+ available_interpreters = INTERPRETER_LABELS ,
302+ logger = None ):
299303 """Implementation of parsing the tag classes for the extension and return a struct for registering repositories.
300304
301305 Args:
302306 module_ctx: {type}`module_ctx` module context.
303- _fail: {type}`function` the failure function, mainly for testing.
304307 simpleapi_download: {type}`function` the function to download from PyPI. See
305308 {obj}`simpleapi_download` for the API docs.
306309 available_interpreters: {type}`dict[str, Label]` The available registered interpreters
307310 to use during the `repository_rule` phase. Used for testing.
311+ logger: The logger to use.
308312
309313 Returns:
310314 A struct with the following attributes:
311315 """
316+ logger = logger or repo_utils .logger (module_ctx , "pypi:parse_modules" )
317+
312318 whl_mods = {}
313319 for mod in module_ctx .modules :
314320 for whl_mod in mod .tags .whl_mods :
315321 if whl_mod .whl_name in whl_mods .get (whl_mod .hub_name , {}):
316322 # We cannot have the same wheel name in the same hub, as we
317323 # will create the same JSON file name.
318- _fail ("""\
324+ logger . fail ("""\
319325 Found same whl_name '{}' in the same hub '{}', please use a different hub_name.""" .format (
320326 whl_mod .whl_name ,
321327 whl_mod .hub_name ,
@@ -324,7 +330,7 @@ Found same whl_name '{}' in the same hub '{}', please use a different hub_name."
324330
325331 build_content = whl_mod .additive_build_content
326332 if whl_mod .additive_build_content_file != None and whl_mod .additive_build_content != "" :
327- _fail ("""\
333+ logger . fail ("""\
328334 You cannot use both the additive_build_content and additive_build_content_file arguments at the same time.
329335""" )
330336 return None
@@ -345,17 +351,17 @@ You cannot use both the additive_build_content and additive_build_content_file a
345351 for module in module_ctx .modules :
346352 for attr in module .tags .override :
347353 if not module .is_root :
348- _fail ("overrides are only supported in root modules" )
354+ logger . fail ("overrides are only supported in root modules" )
349355 return None
350356
351357 if not attr .file .endswith (".whl" ):
352- _fail ("Only whl overrides are supported at this time" )
358+ logger . fail ("Only whl overrides are supported at this time" )
353359 return None
354360
355361 whl_name = normalize_name (parse_whl_name (attr .file ).distribution )
356362
357363 if attr .file in _overriden_whl_set :
358- _fail ("Duplicate module overrides for '{}'" .format (attr .file ))
364+ logger . fail ("Duplicate module overrides for '{}'" .format (attr .file ))
359365 return None
360366 _overriden_whl_set [attr .file ] = None
361367
@@ -397,7 +403,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
397403 elif pip_hub_map [hub_name ].module_name != mod .name :
398404 # We cannot have two hubs with the same name in different
399405 # modules.
400- _fail ((
406+ logger . fail ((
401407 "Duplicate cross-module pip hub named '{hub}': pip hub " +
402408 "names must be unique across modules. First defined " +
403409 "by module '{first_module}', second attempted by " +
@@ -410,7 +416,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
410416 return None
411417
412418 elif pip_attr .python_version in pip_hub_map [hub_name ].python_versions :
413- _fail ((
419+ logger . fail ((
414420 "Duplicate pip python version '{version}' for hub " +
415421 "'{hub}' in module '{module}': the Python versions " +
416422 "used for a hub must be unique"
@@ -452,7 +458,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
452458 requirements_windows = pip_attr .requirements_windows ,
453459 extra_pip_args = pip_attr .extra_pip_args ,
454460 python_version = _major_minor_version (pip_attr .python_version ),
455- logger = repo_utils . logger ( module_ctx , "pypi:requirements_files_by_platform " ),
461+ logger = logger . child ( "requirements_by_platform " ),
456462 )
457463
458464 # if we do not have the python_interpreter set in the attributes
@@ -496,7 +502,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
496502 python_interpreter = pip_attr .python_interpreter ,
497503 python_interpreter_target = python_interpreter_target ,
498504 srcs = pip_attr ._evaluate_markers_srcs ,
499- logger = repo_utils . logger ( module_ctx , "pypi: evaluate_markers" ),
505+ logger = logger . child ( " evaluate_markers" ),
500506 )
501507
502508 requirements_by_platform = parse_requirements (
@@ -505,7 +511,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
505511 extra_pip_args = pip_attr .extra_pip_args ,
506512 get_index_urls = get_index_urls ,
507513 evaluate_markers = evaluate_markers_fn ,
508- logger = repo_utils . logger ( module_ctx , "pypi: parse_requirements" ),
514+ logger = logger . child ( " parse_requirements" ),
509515 )
510516
511517 result = _create_whl_repos (
@@ -525,6 +531,7 @@ You cannot use both the additive_build_content and additive_build_content_file a
525531 ),
526532 whl_overrides = whl_overrides ,
527533 requirements_to_whl_libraries = requirements_to_whl_libraries ,
534+ logger = logger .child ("create_whl_repos" ),
528535 # Construct args separately so that the lock file can be smaller and does
529536 # not include unused attrs.
530537 ** _common_whl_library_args (
0 commit comments