docs: def run_cmd(cmd):
      """
      Run a command in a subprocess, given as a list of command-line
      arguments.
  
      Returns a ``(returncode, stdout, stderr)`` tuple.
      """
  
      try:
          p = sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.PIPE)
          # XXX: May block if either stdout or stderr fill their buffers;
          # however for the commands this is currently used for that is
          # unlikely (they should have very brief output)
          stdout, stderr = p.communicate()
      except OSError as e:
          if DEBUG:
              raise
  
          if e.errno == errno.ENOENT:
              msg = 'Command not found: `{0}`'.format(' '.join(cmd))
              raise _CommandNotFound(msg, cmd)
          else:
              raise _AHBootstrapSystemExit(
                  'An unexpected error occurred when running the '
                  '`{0}` command:\n{1}'.format(' '.join(cmd), str(e)))
  
  
      # Can fail of the default locale is not configured properly.  See
      # https://github.com/astropy/astropy/issues/2749.  For the purposes under
      # consideration 'latin1' is an acceptable fallback.
      try:
          stdio_encoding = locale.getdefaultlocale()[1] or 'latin1'
      except ValueError:
          # Due to an OSX oddity locale.getdefaultlocale() can also crash
          # depending on the user's locale/language settings.  See:
          # http://bugs.python.org/issue18378
          stdio_encoding = 'latin1'
  
      # Unlikely to fail at this point but even then let's be flexible
      if not isinstance(stdout, str):
          stdout = stdout.decode(stdio_encoding, 'replace')
      if not isinstance(stderr, str):
          stderr = stderr.decode(stdio_encoding, 'replace')
  
      return (p.returncode, stdout, stderr)