docs: def ensure_sphinx_astropy_installed():
      """
      Make sure that sphinx-astropy is available, installing it temporarily if not.
  
      This returns the available version of sphinx-astropy as well as any
      paths that should be added to sys.path for sphinx-astropy to be available.
      """
      # We've split out the Sphinx part of astropy-helpers into sphinx-astropy
      # but we want it to be auto-installed seamlessly for anyone using
      # build_docs. We check if it's already installed, and if not, we install
      # it to a local .eggs directory and add the eggs to the path (these
      # have to each be added to the path, we can't add them by simply adding
      # .eggs to the path)
      sys_path_inserts = []
      sphinx_astropy_version = None
      try:
          from sphinx_astropy import __version__ as sphinx_astropy_version  # noqa
      except ImportError:
  
          from setuptools import Distribution
          dist = Distribution()
  
          # Numpydoc 0.9.0 requires sphinx 1.6+, we can limit the version here
          # until we also makes our minimum required version Sphinx 1.6
          if SPHINX_LT_16:
              dist.fetch_build_eggs('numpydoc<0.9')
  
          # This egg build doesn't respect python_requires, not aware of
          # pre-releases. We know that mpl 3.1+ requires Python 3.6+, so this
          # ugly workaround takes care of it until there is a solution for
          # https://github.com/astropy/astropy-helpers/issues/462
          if LooseVersion(sys.version) < LooseVersion('3.6'):
              dist.fetch_build_eggs('matplotlib<3.1')
  
          eggs = dist.fetch_build_eggs('sphinx-astropy')
  
          # Find out the version of sphinx-astropy if possible. For some old
          # setuptools version, eggs will be None even if sphinx-astropy was
          # successfully installed.
          if eggs is not None:
              for egg in eggs:
                  if egg.project_name == 'sphinx-astropy':
                      sphinx_astropy_version = egg.parsed_version.public
                      break
  
          eggs_path = os.path.abspath('.eggs')
          for egg in glob.glob(os.path.join(eggs_path, '*.egg')):
              sys_path_inserts.append(egg)
  
      return sphinx_astropy_version, sys_path_inserts