Skip to content

Commit

Permalink
Merge branch 'master' into cpp_autograd_tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
Jessica Lin authored Apr 14, 2020
2 parents 00ee94e + fe23c8c commit 7a1634d
Show file tree
Hide file tree
Showing 7 changed files with 1,044 additions and 44 deletions.
4 changes: 3 additions & 1 deletion conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import torch
import glob
import shutil
from custom_directives import IncludeDirective, GalleryItemDirective, CustomGalleryItemDirective
from custom_directives import IncludeDirective, GalleryItemDirective, CustomGalleryItemDirective, CustomCalloutItemDirective, CustomCardItemDirective


try:
Expand Down Expand Up @@ -237,3 +237,5 @@ def setup(app):
app.add_directive('includenodoc', IncludeDirective)
app.add_directive('galleryitem', GalleryItemDirective)
app.add_directive('customgalleryitem', CustomGalleryItemDirective)
app.add_directive('customcarditem', CustomCardItemDirective)
app.add_directive('customcalloutitem', CustomCalloutItemDirective)
141 changes: 139 additions & 2 deletions custom_directives.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from docutils.parsers.rst import Directive, directives
from docutils.statemachine import StringList
from docutils.statemachine import StringList
from docutils import nodes
import re
import os
Expand Down Expand Up @@ -142,7 +142,7 @@ class CustomGalleryItemDirective(Directive):
"""Create a sphinx gallery style thumbnail.
tooltip and figure are self explanatory. Description could be a link to
a document like in below example.
a document like in below example.
Example usage:
Expand Down Expand Up @@ -206,3 +206,140 @@ def run(self):
thumb = nodes.paragraph()
self.state.nested_parse(thumbnail, self.content_offset, thumb)
return [thumb]


class CustomCardItemDirective(Directive):
option_spec = {'header': directives.unchanged,
'image': directives.unchanged,
'link': directives.unchanged,
'card_description': directives.unchanged,
'tags': directives.unchanged}

def run(self):
try:
if 'header' in self.options:
header = self.options['header']
else:
raise ValueError('header not doc found')

if 'image' in self.options:
image = "<img src='" + self.options['image'] + "'>"
else:
image = '_static/img/thumbnails/default.png'

if 'link' in self.options:
link = self.options['link']
else:
link = ''

if 'card_description' in self.options:
card_description = self.options['card_description']
else:
card_description = ''

if 'tags' in self.options:
tags = self.options['tags']
else:
tags = ''

except FileNotFoundError as e:
print(e)
return []
except ValueError as e:
print(e)
raise
return []

card_rst = CARD_TEMPLATE.format(header=header,
image=image,
link=link,
card_description=card_description,
tags=tags)
card_list = StringList(card_rst.split('\n'))
card = nodes.paragraph()
self.state.nested_parse(card_list, self.content_offset, card)
return [card]


CARD_TEMPLATE = """
.. raw:: html
<div class="col-md-12 tutorials-card-container" data-tags={tags}>
<div class="card tutorials-card" link={link}>
<div class="card-body">
<div class="card-title-container">
<h4>{header}</h4>
</div>
<p class="card-summary">{card_description}</p>
<p class="tags">{tags}</p>
<div class="tutorials-image">{image}</div>
</div>
</div>
</div>
"""

class CustomCalloutItemDirective(Directive):
option_spec = {'header': directives.unchanged,
'description': directives.unchanged,
'button_link': directives.unchanged,
'button_text': directives.unchanged}

def run(self):
try:
if 'description' in self.options:
description = self.options['description']
else:
description = ''

if 'header' in self.options:
header = self.options['header']
else:
raise ValueError('header not doc found')

if 'button_link' in self.options:
button_link = self.options['button_link']
else:
button_link = ''

if 'button_text' in self.options:
button_text = self.options['button_text']
else:
button_text = ''

except FileNotFoundError as e:
print(e)
return []
except ValueError as e:
print(e)
raise
return []

callout_rst = CALLOUT_TEMPLATE.format(description=description,
header=header,
button_link=button_link,
button_text=button_text)
callout_list = StringList(callout_rst.split('\n'))
callout = nodes.paragraph()
self.state.nested_parse(callout_list, self.content_offset, callout)
return [callout]

CALLOUT_TEMPLATE = """
.. raw:: html
<div class="col-md-6">
<div class="text-container">
<h3>{header}</h3>
<p class="body-paragraph">{description}</p>
<a class="btn with-right-arrow callout-button" href="{button_link}">{button_text}</a>
</div>
</div>
"""
6 changes: 6 additions & 0 deletions index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ Parallel and Distributed Training
:tooltip: PyTorch distributed trainer with Amazon AWS
:description: :doc:`/beginner/aws_distributed_training_tutorial`
:figure: _static/img/distributed/DistPyTorch.jpg

.. customgalleryitem::
:tooltip: Implementing a Parameter Server Using Distributed RPC Framework
:description: :doc:`/intermediate/rpc_param_server_tutorial`
:figure: _static/img/distributed/DistPyTorch.jpg

.. raw:: html

Expand Down Expand Up @@ -372,3 +377,4 @@ Parallel and Distributed Training
intermediate/dist_tuto
intermediate/rpc_tutorial
beginner/aws_distributed_training_tutorial
intermediate/rpc_param_server_tutorial
Loading

0 comments on commit 7a1634d

Please sign in to comment.