class_docstr: Context manager for setup/teardown tasks.
  
  :meta private:
docstr: Set the work task roots and leaves.
docstr_tok: ["Set","the","work","task","roots","and","leaves","."]
code: def set_work_task_roots_and_leaves(cls):
      """Set the work task roots and leaves."""
      if setup_task := cls._context_managed_setup_task:
          if isinstance(setup_task, list):
              setup_task = tuple(setup_task)
          tasks_in_context = [
              x
              for x in cls.context_map.get(setup_task, [])
              if not x.is_teardown and not x.is_setup
          ]
          if tasks_in_context:
              roots = [
                  task
                  for task in tasks_in_context
                  if not task.upstream_list
              ]
              if not roots:
                  setup_task >> tasks_in_context[0]
              else:
                  cls.set_dependency(roots, setup_task, upstream=False)
              leaves = [
                  task
                  for task in tasks_in_context
                  if not task.downstream_list
              ]
              if not leaves:
                  leaves = tasks_in_context[-1]
              cls.set_teardown_task_as_leaves(leaves)
  
      if teardown_task := cls._context_managed_teardown_task:
          if isinstance(teardown_task, list):
              teardown_task = tuple(teardown_task)
          tasks_in_context = [
              x
              for x in cls.context_map.get(teardown_task, [])
              if not x.is_teardown and not x.is_setup
          ]
          if tasks_in_context:
              leaves = [
                  task
                  for task in tasks_in_context
                  if not task.downstream_list
              ]
              if not leaves:
                  teardown_task << tasks_in_context[-1]
              else:
                  cls.set_dependency(leaves, teardown_task)
              roots = [
                  task
                  for task in tasks_in_context
                  if not task.upstream_list
              ]
              if not roots:
                  roots = tasks_in_context[0]
              cls.set_setup_task_as_roots(roots)
      cls.set_setup_teardown_relationships()
      cls.active = False
  
imports: from __future__ import annotations
  from typing import TYPE_CHECKING, cast
  from airflow.exceptions import AirflowException
label_desc: Use image node_id 16 for calling the BaseSetupTeardownContext obj's underlying member method code with example usage: obj.set_work_task_roots_and_leaves(cls) without return types