code: def pretty_str(envinfo):
      def replace_nones(dct, replacement="Could not collect"):
          for key in dct.keys():
              if dct[key] is not None:
                  continue
              dct[key] = replacement
          return dct
  
      def replace_bools(dct, true="Yes", false="No"):
          for key in dct.keys():
              if dct[key] is True:
                  dct[key] = true
              elif dct[key] is False:
                  dct[key] = false
          return dct
  
      def prepend(text, tag="[prepend]"):
          lines = text.split("\n")
          updated_lines = [tag + line for line in lines]
          return "\n".join(updated_lines)
  
      def replace_if_empty(text, replacement="No relevant packages"):
          if text is not None and len(text) == 0:
              return replacement
          return text
  
      def maybe_start_on_next_line(string):
          # If `string` is multiline, prepend a \n to it.
          if string is not None and len(string.split("\n")) > 1:
              return "\n{}\n".format(string)
          return string
  
      mutable_dict = envinfo._asdict()
  
      # If nvidia_gpu_models is multiline, start on the next line
      mutable_dict["nvidia_gpu_models"] = maybe_start_on_next_line(
          envinfo.nvidia_gpu_models
      )
  
      # If the machine doesn't have CUDA, report some fields as 'No CUDA'
      dynamic_cuda_fields = [
          "cuda_runtime_version",
          "nvidia_gpu_models",
          "nvidia_driver_version",
      ]
      all_cuda_fields = dynamic_cuda_fields + ["cudnn_version"]
      all_dynamic_cuda_fields_missing = all(
          mutable_dict[field] is None for field in dynamic_cuda_fields
      )
      if (
          TORCH_AVAILABLE
          and not torch.cuda.is_available()
          and all_dynamic_cuda_fields_missing
      ):
          for field in all_cuda_fields:
              mutable_dict[field] = "No CUDA"
          if envinfo.cuda_compiled_version is None:
              mutable_dict["cuda_compiled_version"] = "None"
  
      # Replace True with Yes, False with No
      mutable_dict = replace_bools(mutable_dict)
  
      # Replace all None objects with 'Could not collect'
      mutable_dict = replace_nones(mutable_dict)
  
      # If either of these are '', replace with 'No relevant packages'
      mutable_dict["pip_packages"] = replace_if_empty(
          mutable_dict["pip_packages"]
      )
      mutable_dict["conda_packages"] = replace_if_empty(
          mutable_dict["conda_packages"]
      )
  
      # Tag conda and pip packages with a prefix
      # If they were previously None, they'll show up as ie '[conda] Could not collect'
      if mutable_dict["pip_packages"]:
          mutable_dict["pip_packages"] = prepend(
              mutable_dict["pip_packages"],
              "[{}] ".format(envinfo.pip_version),
          )
      if mutable_dict["conda_packages"]:
          mutable_dict["conda_packages"] = prepend(
              mutable_dict["conda_packages"], "[conda] "
          )
      return env_info_fmt.format(**mutable_dict)
  
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import locale
  import re
  import subprocess
  import sys
  import os
  from collections import namedtuple
  import logging
label_desc: Use image node_id 20 for calling a global function with example usage: pretty_str(envinfo) and returns: env_info_fmt, dct, dct, str, text, string, replacement, str