Ported over changes to Sphinx from astropy core package