code: def build_environment(service):
      """Create a runtime environment object."""
      # legacy
      checks = {  # noqa: F841
          "azure_nb": AzureNBEnvironment,
          "databricks": _detect_databricks,
          "vscode": _detect_vscode,
          "azure": _detect_azure_notebook,
          "azureml_vm": _detect_azureml_notebook_vm,
          "kaggle": _detect_kaggle,
          "sagemaker": _detect_sagemaker,
          "binder": _detect_binder,
          "colab": _detect_colab,
          "ipython-zmq": _detect_ipython_zmq,
          "ipython": _detect_ipython,
      }
  
      azure_nb_environment = AzureNBEnvironment(service)
      credentialed_vm_environment = CredentialedVMEnvironment(service)
      databricks_environment = DatabricksEnvironment(service)
      local_ipython_environment = LocalIPythonEnvironment(service)
      public_vm_environment = PublicVMEnvironment(service)
  
      # Todo: Add case for detecting and using a Jupyterlab environment
      # note: the order matters since Databricks requirements
      # are a superset of local requirements, for example
      if databricks_environment.successfully_detected:
          env = databricks_environment
      elif azure_nb_environment.successfully_detected:
          env = azure_nb_environment
      elif local_ipython_environment.successfully_detected:
          env = local_ipython_environment
      elif public_vm_environment.successfully_detected:
          env = public_vm_environment
      elif credentialed_vm_environment.successfully_detected:
          env = credentialed_vm_environment
      else:
          raise Exception("Failed to detect Ipython environment")
  
      env.select(service)  # TODO: simplify
      return env
  
file_path: responsible-ai-toolbox/rai_core_flask/rai_core_flask/environment_detector.py
imports: import os
  from .environments import AzureNBEnvironment, CredentialedVMEnvironment, DatabricksEnvironment, LocalIPythonEnvironment, PublicVMEnvironment
label_desc: Use image node_id 12 for calling a global function with example usage: build_environment(service) and returns: env