@@ -557,25 +557,14 @@ def _create_venv(ctx, output_prefix, imports, runtime_details):
557557 site_init = ctx .actions .declare_file ("{}/_bazel_site_init.py" .format (site_packages ))
558558 computed_subs = ctx .actions .template_dict ()
559559 computed_subs .add_joined ("%imports%" , imports , join_with = ":" , map_each = _map_each_identity )
560-
561- if (ctx .configuration .coverage_enabled and
562- runtime and
563- runtime .coverage_tool ):
564- coverage_tool_runfiles_path = "{}/{}" .format (
565- ctx .workspace_name ,
566- runtime .coverage_tool .short_path ,
567- )
568- else :
569- coverage_tool_runfiles_path = ""
570-
571560 ctx .actions .expand_template (
572561 template = runtime .site_init_template ,
573562 output = site_init ,
574563 substitutions = {
564+ "%coverage_tool%" : _get_coverage_tool_runfiles_path (ctx , runtime ),
575565 "%import_all%" : "True" if ctx .fragments .bazel_py .python_import_all_repositories else "False" ,
576566 "%site_init_runfiles_path%" : "{}/{}" .format (ctx .workspace_name , site_init .short_path ),
577567 "%workspace_name%" : ctx .workspace_name ,
578- "%coverage_tool%" : coverage_tool_runfiles_path ,
579568 },
580569 computed_substitutions = computed_subs ,
581570 )
@@ -590,6 +579,17 @@ def _create_venv(ctx, output_prefix, imports, runtime_details):
590579def _map_each_identity (v ):
591580 return v
592581
582+ def _get_coverage_tool_runfiles_path (ctx , runtime ):
583+ if (ctx .configuration .coverage_enabled and
584+ runtime and
585+ runtime .coverage_tool ):
586+ return "{}/{}" .format (
587+ ctx .workspace_name ,
588+ runtime .coverage_tool .short_path ,
589+ )
590+ else :
591+ return ""
592+
593593def _create_stage2_bootstrap (
594594 ctx ,
595595 * ,
@@ -605,23 +605,14 @@ def _create_stage2_bootstrap(
605605 sibling = output_sibling ,
606606 )
607607 runtime = runtime_details .effective_runtime
608- if (ctx .configuration .coverage_enabled and
609- runtime and
610- runtime .coverage_tool ):
611- coverage_tool_runfiles_path = "{}/{}" .format (
612- ctx .workspace_name ,
613- runtime .coverage_tool .short_path ,
614- )
615- else :
616- coverage_tool_runfiles_path = ""
617608
618609 template = runtime .stage2_bootstrap_template
619610
620611 ctx .actions .expand_template (
621612 template = template ,
622613 output = output ,
623614 substitutions = {
624- "%coverage_tool%" : coverage_tool_runfiles_path ,
615+ "%coverage_tool%" : _get_coverage_tool_runfiles_path ( ctx , runtime ) ,
625616 "%import_all%" : "True" if ctx .fragments .bazel_py .python_import_all_repositories else "False" ,
626617 "%imports%" : ":" .join (imports .to_list ()),
627618 "%main%" : "{}/{}" .format (ctx .workspace_name , main_py .short_path ),
0 commit comments