Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add repository rst files in the sphinx docs #34405

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,6 @@ pii_report

# Pyenv Python version file
.python-version

# Auto generated rst files toc tree
/docs/custom_toctree.rst
23 changes: 23 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,36 @@ def update_settings_module(service='lms'):
os.environ['DJANGO_SETTINGS_MODULE'] = settings_module


def find_rst_files(directory):
rst_files = []
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith('.rst'):
rst_files.append(os.path.join(root, file))
return rst_files


def generate_toctree(custom_toctree_dir):
rst_files = find_rst_files(root)
toctree = "\n".join([" " + file for file in rst_files])
with open(custom_toctree_dir, 'w') as custom_docs:
custom_docs.write("\n..\n\tAutomatically Generated Toctree. See `generate_toctree` \
method in docs/conf.py.\n\tDo not change the contents of this file manually\n\n")
custom_docs.write(".. toctree::\n")
custom_docs.write(" :glob:\n")
custom_docs.write(toctree)


def on_init(app): # lint-amnesty, pylint: disable=redefined-outer-name, unused-argument
"""
Run sphinx-apidoc after Sphinx initialization.

Read the Docs won't run tox or custom shell commands, so we need this to
avoid checking in the generated reStructuredText files.
"""

generate_toctree('custom_toctree.rst')

docs_path = root / 'docs'
apidoc_path = 'sphinx-apidoc'
if hasattr(sys, 'real_prefix'): # Check to see if we are in a virtualenv
Expand Down
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ locations.
.. _Open edX Development space: https://openedx.atlassian.net/wiki/spaces/COMM/overview
.. _Open edX ReadTheDocs: http://docs.edx.org/

.. include:: custom_toctree.rst

.. toctree::
:maxdepth: 1

Expand Down
Loading