code: def notebook_formats(nbk, config, path, fallback_on_current_fmt=True):
      """Return the list of formats for the current notebook"""
      metadata = nbk.get("metadata")
      jupytext_metadata = metadata.get("jupytext", {})
      formats = (
          jupytext_metadata.get("formats")
          or metadata.get("jupytext_formats")
          or (config.default_formats(path) if config else None)
      )
  
      if not formats:
          if not fallback_on_current_fmt:
              return None
          text_repr = jupytext_metadata.get("text_representation", {})
          ext = os.path.splitext(path)[1]
          fmt = {"extension": ext}
  
          if ext == text_repr.get("extension") and text_repr.get(
              "format_name"
          ):
              fmt["format_name"] = text_repr.get("format_name")
  
          formats = [fmt]
  
      formats = long_form_multiple_formats(
          formats, metadata, auto_ext_requires_language_info=False
      )
  
      # Set preferred formats if no format name has been given yet
      if config:
          formats = [
              preferred_format(
                  f, config.preferred_jupytext_formats_save
              )
              for f in formats
          ]
  
      return formats
  
imports: import json
  import os
  import warnings
  import yaml
  from traitlets import Bool, Dict, Enum, Float, List, Unicode, Union
  from traitlets.config import Configurable
  from traitlets.config.loader import PyFileConfigLoader
  from traitlets.traitlets import TraitError
  from .formats import NOTEBOOK_EXTENSIONS, long_form_multiple_formats, long_form_one_format, short_form_multiple_formats
label_desc: Use image node_id 9 for calling a global function with example usage: notebook_formats(nbk, config, path, fallback_on_current_fmt) and returns: formats, None