code: def list_subcommands() -> list[str]:
      """List all jupyter subcommands
  
      searches PATH for `jupyter-name`
  
      Returns a list of jupyter's subcommand names, without the `jupyter-` prefix.
      Nested children (e.g. jupyter-sub-subsub) are not included.
      """
      subcommand_tuples = set()
      # construct a set of `('foo', 'bar') from `jupyter-foo-bar`
      for d in _path_with_self():
          try:
              names = os.listdir(d)
          except OSError:
              continue
          for name in names:
              if name.startswith("jupyter-"):
                  if sys.platform.startswith("win"):
                      # remove file-extension on Windows
                      name = os.path.splitext(name)[
                          0
                      ]  # noqa: PTH122, PLW2901
                  subcommand_tuples.add(tuple(name.split("-")[1:]))
      # build a set of subcommand strings, excluding subcommands whose parents are defined
      subcommands = set()
      # Only include `jupyter-foo-bar` if `jupyter-foo` is not already present
      for sub_tup in subcommand_tuples:
          if not any(
              sub_tup[:i] in subcommand_tuples
              for i in range(1, len(sub_tup))
          ):
              subcommands.add("-".join(sub_tup))
      return sorted(subcommands)
  
imports: from __future__ import annotations
  import argparse
  import errno
  import json
  import os
  import site
  import sys
  import sysconfig
  from pathlib import Path
  from shutil import which
  from subprocess import Popen
  from typing import Any
  from .None import paths
  from .version import __version__
label_desc: Use image node_id 2 for calling a global function with example usage: list_subcommands() and returns: sorted