docs: Generate redirects for autoapi renaming

This commit is contained in:
Jeff Epler 2020-06-14 13:04:21 -05:00
parent f83b0c2507
commit cb8539b06d
2 changed files with 139 additions and 0 deletions

45
conf.py
View File

@ -14,6 +14,7 @@
# serve to show the default.
import json
import logging
import os
import subprocess
import sys
@ -82,6 +83,8 @@ autoapi_template_dir = 'docs/autoapi/templates'
autoapi_python_use_implicit_namespaces = True
autoapi_root = "shared-bindings"
redirects_file = 'docs/redirects.txt'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
@ -376,5 +379,47 @@ intersphinx_mapping = {"cpython": ('https://docs.python.org/3/', None),
"bus_device": ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),
"register": ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None)}
# Adapted from sphinxcontrib-redirects
from sphinx.builders import html as builders
TEMPLATE = """<html>
<head><meta http-equiv="refresh" content="0; url=%s"/></head>
</html>
"""
def generate_redirects(app):
path = os.path.join(app.srcdir, app.config.redirects_file)
if not os.path.exists(path):
app.info("Could not find redirects file at '%s'" % path)
return
# TODO(stephenfin): Add support for DirectoryHTMLBuilder
if not type(app.builder) == builders.StandaloneHTMLBuilder:
logging.warn("The 'sphinxcontib-redirects' plugin is only supported "
"by the 'html' builder. Skipping...")
return
with open(path) as redirects:
for line in redirects.readlines():
from_path, to_path = line.rstrip().split(' ')
logging.debug("Redirecting '%s' to '%s'" % (from_path, to_path))
from_path = os.path.splitext(from_path)[0] + ".html"
to_path_prefix = '..%s' % os.path.sep * (
len(from_path.split(os.path.sep)) - 1)
to_path = to_path_prefix + to_path
redirected_filename = os.path.join(app.builder.outdir, from_path)
redirected_directory = os.path.dirname(redirected_filename)
if not os.path.exists(redirected_directory):
os.makedirs(redirected_directory)
with open(redirected_filename, 'w') as f:
f.write(TEMPLATE % urllib.parse.quote(to_path, '#/'))
def setup(app):
app.add_css_file("customstyle.css")
app.add_config_value('redirects_file', 'redirects', 'env')
app.connect('builder-inited', generate_redirects)

94
docs/redirects.txt Normal file
View File

@ -0,0 +1,94 @@
shared-bindings/frequencyio/FrequencyIn.rst shared-bindings/frequencyio/#frequencyio.FrequencyIn
shared-bindings/fontio/BuiltinFont.rst shared-bindings/fontio/#fontio.BuiltinFont
shared-bindings/fontio/Glyph.rst shared-bindings/fontio/#fontio.Glyph
shared-bindings/aesio/AES.rst shared-bindings/aesio/#aesio.AES
shared-bindings/supervisor/Runtime.rst shared-bindings/supervisor/#supervisor.Runtime
shared-bindings/terminalio/Terminal.rst shared-bindings/terminalio/#terminalio.Terminal
shared-bindings/audiopwmio/PWMAudioOut.rst shared-bindings/audiopwmio/#audiopwmio.PWMAudioOut
shared-bindings/gamepadshift/GamePadShift.rst shared-bindings/gamepadshift/#gamepadshift.GamePadShift
shared-bindings/vectorio/Circle.rst shared-bindings/vectorio/#vectorio.Circle
shared-bindings/vectorio/Polygon.rst shared-bindings/vectorio/#vectorio.Polygon
shared-bindings/vectorio/Rectangle.rst shared-bindings/vectorio/#vectorio.Rectangle
shared-bindings/vectorio/VectorShape.rst shared-bindings/vectorio/#vectorio.VectorShape
shared-bindings/displayio/Bitmap.rst shared-bindings/displayio/#displayio.Bitmap
shared-bindings/displayio/ColorConverter.rst shared-bindings/displayio/#displayio.ColorConverter
shared-bindings/displayio/Display.rst shared-bindings/displayio/#displayio.Display
shared-bindings/displayio/EPaperDisplay.rst shared-bindings/displayio/#displayio.EPaperDisplay
shared-bindings/displayio/FourWire.rst shared-bindings/displayio/#displayio.FourWire
shared-bindings/displayio/Group.rst shared-bindings/displayio/#displayio.Group
shared-bindings/displayio/I2CDisplay.rst shared-bindings/displayio/#displayio.I2CDisplay
shared-bindings/displayio/OnDiskBitmap.rst shared-bindings/displayio/#displayio.OnDiskBitmap
shared-bindings/displayio/Palette.rst shared-bindings/displayio/#displayio.Palette
shared-bindings/displayio/ParallelBus.rst shared-bindings/displayio/#displayio.ParallelBus
shared-bindings/displayio/Shape.rst shared-bindings/displayio/#displayio.Shape
shared-bindings/displayio/TileGrid.rst shared-bindings/displayio/#displayio.TileGrid
shared-bindings/_pixelbuf/PixelBuf.rst shared-bindings/_pixelbuf/#_pixelbuf.PixelBuf
shared-bindings/gamepad/GamePad.rst shared-bindings/gamepad/#gamepad.GamePad
shared-bindings/_pew/PewPew.rst shared-bindings/_pew/#_pew.PewPew
shared-bindings/rotaryio/IncrementalEncoder.rst shared-bindings/rotaryio/#rotaryio.IncrementalEncoder
shared-bindings/audiomixer/Mixer.rst shared-bindings/audiomixer/#audiomixer.Mixer
shared-bindings/audiomixer/MixerVoice.rst shared-bindings/audiomixer/#audiomixer.MixerVoice
shared-bindings/pulseio/PWMOut.rst shared-bindings/pulseio/#pulseio.PWMOut
shared-bindings/pulseio/PulseIn.rst shared-bindings/pulseio/#pulseio.PulseIn
shared-bindings/pulseio/PulseOut.rst shared-bindings/pulseio/#pulseio.PulseOut
shared-bindings/time/struct_time.rst shared-bindings/time/#time.struct_time
shared-bindings/i2cslave/I2CSlave.rst shared-bindings/i2cslave/#i2cslave.I2CSlave
shared-bindings/i2cslave/I2CSlaveRequest.rst shared-bindings/i2cslave/#i2cslave.I2CSlaveRequest
shared-bindings/nvm/ByteArray.rst shared-bindings/nvm/#nvm.ByteArray
shared-bindings/busio/I2C.rst shared-bindings/busio/#busio.I2C
shared-bindings/busio/OneWire.rst shared-bindings/busio/#busio.OneWire
shared-bindings/busio/SPI.rst shared-bindings/busio/#busio.SPI
shared-bindings/busio/UART.rst shared-bindings/busio/#busio.UART
shared-bindings/busio/Parity.rst shared-bindings/busio/#busio.Parity
shared-bindings/ulab/array.rst shared-bindings/ulab/#ulab.array
shared-bindings/watchdog/WatchDogMode.rst shared-bindings/watchdog/#watchdog.WatchDogMode
shared-bindings/watchdog/WatchDogTimer.rst shared-bindings/watchdog/#watchdog.WatchDogTimer
shared-bindings/audioio/AudioOut.rst shared-bindings/audioio/#audioio.AudioOut
shared-bindings/ps2io/Ps2.rst shared-bindings/ps2io/#ps2io.Ps2
shared-bindings/touchio/TouchIn.rst shared-bindings/touchio/#touchio.TouchIn
shared-bindings/rgbmatrix/RGBMatrix.rst shared-bindings/rgbmatrix/#rgbmatrix.RGBMatrix
shared-bindings/audiomp3/MP3.rst shared-bindings/audiomp3/#audiomp3.MP3
shared-bindings/usb_midi/PortIn.rst shared-bindings/usb_midi/#usb_midi.PortIn
shared-bindings/usb_midi/PortOut.rst shared-bindings/usb_midi/#usb_midi.PortOut
shared-bindings/usb_hid/Device.rst shared-bindings/usb_hid/#usb_hid.Device
shared-bindings/wiznet/WIZNET5K.rst shared-bindings/wiznet/#wiznet.WIZNET5K
shared-bindings/_bleio/BluetoothError.rst shared-bindings/_bleio/#_bleio.BluetoothError
shared-bindings/_bleio/ConnectionError.rst shared-bindings/_bleio/#_bleio.ConnectionError
shared-bindings/_bleio/RoleError.rst shared-bindings/_bleio/#_bleio.RoleError
shared-bindings/_bleio/SecurityError.rst shared-bindings/_bleio/#_bleio.SecurityError
shared-bindings/_bleio/Adapter.rst shared-bindings/_bleio/#_bleio.Adapter
shared-bindings/_bleio/Address.rst shared-bindings/_bleio/#_bleio.Address
shared-bindings/_bleio/Attribute.rst shared-bindings/_bleio/#_bleio.Attribute
shared-bindings/_bleio/Characteristic.rst shared-bindings/_bleio/#_bleio.Characteristic
shared-bindings/_bleio/CharacteristicBuffer.rst shared-bindings/_bleio/#_bleio.CharacteristicBuffer
shared-bindings/_bleio/Connection.rst shared-bindings/_bleio/#_bleio.Connection
shared-bindings/_bleio/Descriptor.rst shared-bindings/_bleio/#_bleio.Descriptor
shared-bindings/_bleio/PacketBuffer.rst shared-bindings/_bleio/#_bleio.PacketBuffer
shared-bindings/_bleio/ScanEntry.rst shared-bindings/_bleio/#_bleio.ScanEntry
shared-bindings/_bleio/ScanResults.rst shared-bindings/_bleio/#_bleio.ScanResults
shared-bindings/_bleio/Service.rst shared-bindings/_bleio/#_bleio.Service
shared-bindings/_bleio/UUID.rst shared-bindings/_bleio/#_bleio.UUID
shared-bindings/socket/socket.rst shared-bindings/socket/#socket.socket
shared-bindings/microcontroller/Pin.rst shared-bindings/microcontroller/#microcontroller.Pin
shared-bindings/microcontroller/Processor.rst shared-bindings/microcontroller/#microcontroller.Processor
shared-bindings/microcontroller/RunMode.rst shared-bindings/microcontroller/#microcontroller.RunMode
shared-bindings/audiocore/RawSample.rst shared-bindings/audiocore/#audiocore.RawSample
shared-bindings/audiocore/WaveFile.rst shared-bindings/audiocore/#audiocore.WaveFile
shared-bindings/framebufferio/FramebufferDisplay.rst shared-bindings/framebufferio/#framebufferio.FramebufferDisplay
shared-bindings/audiobusio/I2SOut.rst shared-bindings/audiobusio/#audiobusio.I2SOut
shared-bindings/audiobusio/PDMIn.rst shared-bindings/audiobusio/#audiobusio.PDMIn
shared-bindings/countio/Counter.rst shared-bindings/countio/#countio.Counter
shared-bindings/storage/VfsFat.rst shared-bindings/storage/#storage.VfsFat
shared-bindings/digitalio/DigitalInOut.rst shared-bindings/digitalio/#digitalio.DigitalInOut
shared-bindings/digitalio/Direction.rst shared-bindings/digitalio/#digitalio.Direction
shared-bindings/digitalio/DriveMode.rst shared-bindings/digitalio/#digitalio.DriveMode
shared-bindings/digitalio/Pull.rst shared-bindings/digitalio/#digitalio.Pull
shared-bindings/bitbangio/I2C.rst shared-bindings/bitbangio/#bitbangio.I2C
shared-bindings/bitbangio/OneWire.rst shared-bindings/bitbangio/#bitbangio.OneWire
shared-bindings/bitbangio/SPI.rst shared-bindings/bitbangio/#bitbangio.SPI
shared-bindings/rtc/RTC.rst shared-bindings/rtc/#rtc.RTC
shared-bindings/analogio/AnalogIn.rst shared-bindings/analogio/#analogio.AnalogIn
shared-bindings/analogio/AnalogOut.rst shared-bindings/analogio/#analogio.AnalogOut
shared-bindings/_stage/Layer.rst shared-bindings/_stage/#_stage.Layer
shared-bindings/_stage/Text.rst shared-bindings/_stage/#_stage.Text
shared-bindings/samd/Clock.rst shared-bindings/samd/#samd.Clock