Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Rater Scoring Modeling Tool (RSMTool) is a python package which automates and co

We expect the primary users of RSMTool to be researchers working on developing new automated scoring engines or on improving existing ones. Note that RSMTool is not a scoring engine by itself but rather a tool for building and evaluating machine learning models that may be used in such engines.

For installation and usage, please see the `official documentation <http://rsmtool.readthedocs.io>`_.
For installation and usage, please see the `official documentation <https://rsmtool.readthedocs.io>`_. If you use the `Dash <https://kapeli.com/dash>`_ app on macOS, you can also download the complete RSMTool documentation for offline use. Go to the Dash preferences, click on "Downloads", then "User Contributed", and search for "RSMTool".

Requirements
------------
Expand Down
8 changes: 7 additions & 1 deletion doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ help:
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
dash: export DASH=True
dash: clean
@$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
python "$(SOURCEDIR)/add_dash_anchors.py" "$(BUILDDIR)/html"
doc2dash -n RSMTool -d "$(BUILDDIR)" -I index.html "$(BUILDDIR)/html"
cp assets/dash_icon.png "$(BUILDDIR)/RSMTool.DocSet/icon.png"
87 changes: 87 additions & 0 deletions doc/add_dash_anchors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Add Dash-style anchors to already-generated HTML documentation.

This script iterates over pre-specified HTML files generated via
sphinx-build, finds all of the sections, and adds Dash-style anchors
so that when those HTML files are displayed in the Dash macOS app,
the sections are displayed in a Dash TOC on the right.

:author: Nitin Madnani (nmadnani@ets.org)
:organization: ETS
"""

import argparse
import logging
import re
import pathlib
import unicodedata
from urllib.parse import quote

from bs4 import BeautifulSoup

# pre-define the list of HTML files we want to miodify
FILES_TO_MODIFY = ["advanced_usage.html", "api.html", "contributing.html",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we make sure this list is up-to-date? Can we create it automatically based on directory content?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I tried this but struggled with it. There are some auto-generated HTML files that we do not want to add Dash nchors to (for example, genindex.html). I haven’t been able to figure out if this set is fixed and so we can just include all files except the ones in this set. I can work on this in the future.

"custom_notebooks.html", "evaluation.html",
"getting_started.html", "pipeline.html",
"internal.html", "tutorial.html",
"usage_rsmtool.html", "utilities.html", "who.html"]
PILCROW = unicodedata.lookup('PILCROW SIGN')


def main(): # noqa: D103

# set up an argument parser
parser = argparse.ArgumentParser(prog='add_dash_anchors.py')
parser.add_argument("htmldir",
type=pathlib.Path,
help="path to the already-built HTML documentation")

# parse given command line arguments
args = parser.parse_args()

# set up the logging
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)

# iterate over all the built HTML files
for htmlfile in args.htmldir.glob("**/*.html"):

# we only care about the pre-specified html files
if htmlfile.name in FILES_TO_MODIFY:

logging.info(f'Processing {htmlfile.name} ...')

# parse the file
with open(htmlfile, 'r') as htmlfh:
soup = BeautifulSoup(htmlfh, features='html.parser')

# each HTML file has a main section which we do not need
# but we need _all_ of the other sections
sections = soup.body.div.find_all("div", class_="section")[1:]
for section in sections:
section_title = section.find(re.compile(r'^h[0-9]')).text
section_title = section_title.rstrip(PILCROW)

# convert this title to percent-encoded format which will be
# the name of our entry
entry_name = quote(section_title)
entry_type = 'Section'
anchor_name = f"//apple_ref/cpp/{entry_type}/{entry_name}"

# create a new anchor tag for this subsection
anchor_tag = soup.new_tag('a',
attrs={'name': anchor_name,
'class': "dashAnchor"})

# insert this new tag right before the section
section.insert_before(anchor_tag)

# overwrite the original HTML file
with open(htmlfile, 'w') as outfh:
outfh.write(str(soup))


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ From :py:mod:`~rsmtool.configuration_parser` Module
:members:
:undoc-members:
:show-inheritance:
:exclude-members: deprecated_positional_argument

From :py:mod:`~rsmtool.container` Module
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
Binary file added doc/assets/dash_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
Loading