Skip to content

Commit

Permalink
documentation workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
alkidbaci committed Mar 5, 2024
1 parent 868e4af commit ec242f4
Show file tree
Hide file tree
Showing 10 changed files with 761 additions and 72 deletions.
78 changes: 50 additions & 28 deletions .github/workflows/sphinx.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,55 @@
# This is a basic workflow to help you get started with Actions
name: Build docs

name: Build-sphinx-docs
on:
push:
branches:
- main
- develop
- documentation # just for testing
pull_request:

on: [push,pull_request]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
jobs:
docs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.10.11" ]
max-parallel: 5

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Set up Python 3.9.18
uses: actions/setup-python@v2
with:
python-version: "3.9.18"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
# # pip install -r requirements.txt

- name: Build HTML and import
run: |
# sphinx-apidoc -o docs dicee/ && make -C docs/ html && ghp-import -n -p -f docs/_build/html


- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Prepare required software
run: |
# epstopdf & dot & noto-fonts
sudo apt update && sudo apt install texlive-font-utils graphviz fonts-noto\
- name: Build docs
run: |
sphinx-build -M html docs/ docs/_build/
- name: Build LaTeX docs
run: |
sphinx-build -M latex docs/ docs/_build/
- name: Compile LaTeX document
uses: docker://texlive/texlive:latest
with:
args: make -C docs/_build/latex
- run: |
cp docs/_build/latex/dicee.pdf docs/_build/html/
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: 'docs/_build/html'
1 change: 1 addition & 0 deletions docs/_static/documentation_options_patch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DOCUMENTATION_OPTIONS.LINK_SUFFIX = DOCUMENTATION_OPTIONS.FILE_SUFFIX
243 changes: 243 additions & 0 deletions docs/_static/js/theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
var jQuery = (typeof(window) != 'undefined') ? window.jQuery : require('jquery');

// Sphinx theme nav state
function ThemeNav () {

var nav = {
navBar: null,
win: null,
winScroll: false,
winResize: false,
linkScroll: false,
winPosition: 0,
winHeight: null,
docHeight: null,
isRunning: false
};

nav.enable = function (withStickyNav) {
var self = this;

// TODO this can likely be removed once the theme javascript is broken
// out from the RTD assets. This just ensures old projects that are
// calling `enable()` get the sticky menu on by default. All other cals
// to `enable` should include an argument for enabling the sticky menu.
if (typeof(withStickyNav) == 'undefined') {
withStickyNav = true;
}

if (self.isRunning) {
// Only allow enabling nav logic once
return;
}

self.isRunning = true;
jQuery(function ($) {
self.init($);

self.reset();
self.win.on('hashchange', self.reset);

if (withStickyNav) {
// Set scroll monitor
self.win.on('scroll', function () {
if (!self.linkScroll) {
if (!self.winScroll) {
self.winScroll = true;
requestAnimationFrame(function() { self.onScroll(); });
}
}
});
}

// Set resize monitor
self.win.on('resize', function () {
if (!self.winResize) {
self.winResize = true;
requestAnimationFrame(function() { self.onResize(); });
}
});

self.onResize();
});

};

// TODO remove this with a split in theme and Read the Docs JS logic as
// well, it's only here to support 0.3.0 installs of our theme.
nav.enableSticky = function() {
this.enable(true);
};

nav.init = function ($) {
var doc = $(document),
self = this;

this.navBar = $('div.wy-side-scroll:first');
this.win = $(window);

// Set up javascript UX bits
$(document)
// Shift nav in mobile when clicking the menu.
.on('click', "[data-toggle='wy-nav-top']", function() {
$("[data-toggle='wy-nav-shift']").toggleClass("shift");
$("[data-toggle='rst-versions']").toggleClass("shift");
})

// Nav menu link click operations
.on('click', ".wy-menu-vertical .current ul li a", function() {
var target = $(this);
// Close menu when you click a link.
$("[data-toggle='wy-nav-shift']").removeClass("shift");
$("[data-toggle='rst-versions']").toggleClass("shift");
// Handle dynamic display of l3 and l4 nav lists
self.toggleCurrent(target);
self.hashChange();
})
.on('click', "[data-toggle='rst-current-version']", function() {
$("[data-toggle='rst-versions']").toggleClass("shift-up");
})

// Make tables responsive
$("table.docutils:not(.field-list,.footnote,.citation)")
.wrap("<div class='wy-table-responsive'></div>");

// Add extra class to responsive tables that contain
// footnotes or citations so that we can target them for styling
$("table.docutils.footnote")
.wrap("<div class='wy-table-responsive footnote'></div>");
$("table.docutils.citation")
.wrap("<div class='wy-table-responsive citation'></div>");

// Add expand links to all parents of nested ul
$('.wy-menu-vertical ul').not('.simple').siblings('a').each(function () {
var link = $(this);
expand = $('<span class="toctree-expand"></span>');
expand.on('click', function (ev) {
self.toggleCurrent(link);
ev.stopPropagation();
return false;
});
link.prepend(expand);
});
};

nav.reset = function () {
// Get anchor from URL and open up nested nav
var anchor = encodeURI(window.location.hash) || '#';

try {
var vmenu = $('.wy-menu-vertical');
var link = vmenu.find('[href="' + anchor + '"]');
if (link.length === 0) {
// this link was not found in the sidebar.
// Find associated id element, then its closest section
// in the document and try with that one.
var id_elt = $('.document [id="' + anchor.substring(1) + '"]');
var closest_section = id_elt.closest('div.section');
link = vmenu.find('[href="#' + closest_section.attr("id") + '"]');
if (link.length === 0) {
// still not found in the sidebar. fall back to main section
link = vmenu.find('[href="#"]');
}
}
// If we found a matching link then reset current and re-apply
// otherwise retain the existing match
if (link.length > 0) {
$('.wy-menu-vertical .current').removeClass('current');
link.addClass('current');
link.closest('li.toctree-l1').parent().addClass('current');
for (let i = 1; i <= 10; i++) {
link.closest('li.toctree-l' + i).addClass('current');
}
link[0].scrollIntoView();
}
}
catch (err) {
console.log("Error expanding nav for anchor", err);
}

};

nav.onScroll = function () {
this.winScroll = false;
var newWinPosition = this.win.scrollTop(),
winBottom = newWinPosition + this.winHeight,
navPosition = this.navBar.scrollTop(),
newNavPosition = navPosition + (newWinPosition - this.winPosition);
if (newWinPosition < 0 || winBottom > this.docHeight) {
return;
}
this.navBar.scrollTop(newNavPosition);
this.winPosition = newWinPosition;
};

nav.onResize = function () {
this.winResize = false;
this.winHeight = this.win.height();
this.docHeight = $(document).height();
};

nav.hashChange = function () {
this.linkScroll = true;
this.win.one('hashchange', function () {
this.linkScroll = false;
});
};

nav.toggleCurrent = function (elem) {
var parent_li = elem.closest('li');
parent_li.siblings('li.current').removeClass('current');
parent_li.siblings().find('li.current').removeClass('current');
var children = parent_li.find('> ul li');
// Don't toggle terminal elements.
if (children.length) {
children.removeClass('current');
parent_li.toggleClass('current');
}
}

return nav;
};

module.exports.ThemeNav = ThemeNav();

if (typeof(window) != 'undefined') {
window.SphinxRtdTheme = {
Navigation: module.exports.ThemeNav,
// TODO remove this once static assets are split up between the theme
// and Read the Docs. For now, this patches 0.3.0 to be backwards
// compatible with a pre-0.3.0 layout.html
StickyNav: module.exports.ThemeNav,
};
}


// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// https://gist.github.com/paulirish/1579671
// MIT license

(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
|| window[vendors[x]+'CancelRequestAnimationFrame'];
}

if (!window.requestAnimationFrame)
window.requestAnimationFrame = function(callback, element) {
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function() { callback(currTime + timeToCall); },
timeToCall);
lastTime = currTime + timeToCall;
return id;
};

if (!window.cancelAnimationFrame)
window.cancelAnimationFrame = function(id) {
clearTimeout(id);
};
}());
9 changes: 9 additions & 0 deletions docs/_static/theme_tweak.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.rst-content dl:not(.docutils) dl dl dt {
width: auto;
}
.rst-content dl:not(.docutils) dl dt {
width: 96%;
}
.rst-content dl:not(.docutils) dt {
width: 100%;
}
2 changes: 2 additions & 0 deletions docs/_templates/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% extends "!search.html" %}
{% set script_files = [ '_static/documentation_options_patch.js', '_static/language_data.js' ] + script_files %}
40 changes: 37 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,52 @@
project = 'DICE Embeddings'
copyright = '2023, Caglar Demir'
author = 'Caglar Demir'
release = '0.1.2'
release = '0.1.3.2'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = ["sphinx.ext.todo", "sphinx.ext.viewcode", "sphinx.ext.autodoc"]
extensions = ["autoapi.extension",
"sphinx.ext.githubpages",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
"sphinx.ext.autodoc"]

# autoapi for dicee.
autoapi_dirs = ['../dicee']

# by default all are included but had to reinitialize this to remove private members from showing
autoapi_options = ['members', 'undoc-members', 'show-inheritance', 'show-module-summary', 'special-members',
'imported-members']

# this is set to false, so we can add it manually in index.rst together with the other .md files of the documentation.
autoapi_add_toctree_entry = False

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'furo'
html_static_path = ['_static']

# -- Options for LaTeX output ------------------------------------------------

latex_engine = 'xelatex'
latex_show_urls = 'footnote'
latex_theme = 'howto'

latex_elements = {
'preamble': r'''
\renewcommand{\pysiglinewithargsret}[3]{%
\item[{%
\parbox[t]{\linewidth}{\setlength{\hangindent}{12ex}%
\raggedright#1\sphinxcode{(}\linebreak[0]{\renewcommand{\emph}[1]{\mbox{\textit{##1}}}#2}\sphinxcode{)}\linebreak[0]\mbox{#3}}}]}
''',
'printindex': '\\def\\twocolumn[#1]{#1}\\footnotesize\\raggedright\\printindex',
}


def setup(app):
# -- Options for HTML output ---------------------------------------------
app.add_css_file('theme_tweak.css')
Loading

0 comments on commit ec242f4

Please sign in to comment.