Skip to main content
  1. Dispatches/

TIL - Running make apidocs for Read the Docs

·196 words·1 min
TIL Python
Daniel Andrlik
Author
Daniel Andrlik lives in the suburbs of Philadelphia. By day he manages product teams. The rest of the time he is a podcast host and producer, writer of speculative fiction, a rabid reader, and a programmer.

I was hacking on my quote service the other day, and notice that Read the Docs wasn’t building my module level documentation, which meant that anyone that wanted to look at said modules in more detail was getting a 404 error. One option was to simply make running make apidocs a part of my standard process and committing the results, but I hate the idea of leaving something that can, and should, be automated left to my memory.

A quick Google search led me to this Github issue full of fellow souls with the exact same problem. The solution, at least until RTD supports something more elegant in its configuraton file is to add the following to the end of your conf.py file.

def run_apidoc(_):
    from sphinx.ext.apidoc import main
    import os
    import sys
    sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
    output_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), "api")
    module = os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "your_module_name_here")
    main(["-e", "-o", output_dir, module, "--force"])
    
    
def setup(app):
    app.connect("builder-inited", run_apidoc)

Note that this example assumes that your conf.py and all your docs live in a docs subdirectory at the root of your project. And assumes that you’re expecting the apidocs output to end up in the api/ subdirectory next to your _build/ directory.

Related

TIL - Importing annotations from future for concise Python typing
·110 words·1 min
TIL Python
Python 3.10 introduced several improvements for type hints, including a much more concise Union operator. This means that instead of using: def square(number: Union[int, float]) -> Union[int, float]: return number ** 2 You can instead write this:
TIL - Podcast hosts serve unreliable art mime types
·362 words·2 mins
TIL Podcasting Python Django Mime Types Rss
I’ve been toying with a small Django project that can be given a list of podcast feeds, and then regularly checks those feeds and updates some interesting metrics. Initially, I wanted to see how many comparable podcasts to my own made use of various RSS namespace elements, and also to pull some aggregate statistics around release frequency, episode length, etc…
TIL - Getting asdf Python with tkinter working on a M2 Mac
·312 words·2 mins
TIL Macos Python Homebrew Tkinter
This week I wanted to play around with tkinter a bit. But this proved to be difficult on my M2 Mac. I use asdf to manage various runtime versions, so first I checked to see if it was already working with my existing Python installation using the built in test method.