Search code examples
pythonpython-sphinxread-the-docs

Custom PDFs are not generated in the ReadTheDocs flyer menu


Here is my .readthedocs.yml file which includes commands to build PDF from simple-pdf extension. Although the build succeeds executing all the commands, I cant see the PDF in flyer menu.

# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

#submodules:
#  include:
#    - paamr-deployment

# Set the version of Python and other tools you might need
build:
  os: ubuntu-20.04
  tools:
    python: "3.9"
    # You can also specify other tool versions:
    # nodejs: "16"
    # rust: "1.55"
    # golang: "1.17"
  #Add custom simple-pdf to readthedocs flyer menu
    commands:
    - pip install -r docs/requirements.txt
    - rm -rf _readthedocs/pdf
    - mkdir -p _readthedocs/pdf
    - sphinx-build -b simplepdf docs _readthedocs/pdf
    - find _readthedocs/pdf -type f ! -name '*.pdf' -delete  # Delete all files except .pdf
    - find _readthedocs/pdf -mindepth 1 -type d -delete  # Delete all directories except .pdf
    - mkdir -p _readthedocs/html/
    - sphinx-build -b html docs _readthedocs/html

# Build documentation in the docs/ directory with Sphinx
sphinx:
  configuration: docs/conf.py

# If using Sphinx, optionally build your docs in additional formats such as PDF
formats: all

# Optionally declare the Python requirements required to build your docs
python:
  install:
    - requirements: docs/requirements.txt

Output:

  • Readthedocs PR build passed
  • Activated version build passed
  • On clicking on PDF option on readthedocs flyer, it says 404

Expected output:

  • Readthedocs PR build pass
  • Activated version build passe
  • On clicking on PDF option on readthedocs flyer, PDF should be downloaded

Solution

  • I was able to upload the custom PDF to readthedocs flyer using the below commands in readthedocs.yaml file.

    # rest of the yaml code
    ...
    #Upload custom simple-pdf to readthedocs flyer menu
      commands:
        - pip install -r docs/requirements.txt
        - rm -rf _readthedocs/pdf
        - mkdir -p _readthedocs/pdf
        - sphinx-build -b simplepdf docs _readthedocs/pdf
        - find _readthedocs/pdf -type f ! -name '*.pdf' -delete  # Delete all files except .pdf
        - find _readthedocs/pdf -mindepth 1 -type d -delete  # Delete all directories except .pdf
        - mkdir -p _readthedocs/html/
        - sphinx-build -b html docs _readthedocs/html
        - mv _readthedocs/pdf/*.pdf _readthedocs/pdf/$READTHEDOCS_PROJECT.pdf  # Rename the pdf
    

    Thanks for the responses and support.