Skip to content

Commit

Permalink
docs: update doc building to get them working on readthedocs.
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthieuDartiailh committed Feb 24, 2018
1 parent 0f5a4cb commit 578274f
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 75 deletions.
2 changes: 2 additions & 0 deletions docs/environment.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
channels:
- conda-forge
- exopy
- defaults

dependencies:
Expand All @@ -11,3 +12,4 @@ dependencies:
- ipython
- sphinx
- sphinx_rtd_theme
- enaml-pygments
40 changes: 17 additions & 23 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

from enaml.version import version_info

import sphinx_bootstrap_theme

from enaml.core.import_hooks import EnamlImporter
EnamlImporter.install()

Expand All @@ -37,7 +35,7 @@
# -- General configuration -----------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
needs_sphinx = '1.0.7'
needs_sphinx = '1.4'

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
Expand All @@ -47,19 +45,15 @@
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.pngmath',
'sphinx.ext.imgmath',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
'sphinx.ext.graphviz',
'sphinx.ext.inheritance_diagram',
'sphinx.ext.autosummary',
#'enamldoc'
'numpydoc'
'sphinx.ext.napoleon'
]

# Disable numpy auto-gen class members.
numpydoc_show_class_members = False

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

Expand All @@ -74,7 +68,7 @@

# General information about the project.
project = u'Enaml'
copyright = u'2013, Nucleic Development Team'
copyright = u'2013-2018, Nucleic Development Team'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -143,33 +137,33 @@

autosummary_generate = True

# -- Options for HTML output ---------------------------------------------------
# Napoleon config
napoleon_include_special_with_doc = False


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
# html_theme = 'nucleic_doc'
#'default'
#'agogo'
#
html_theme = 'bootstrap'
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
## html_theme_options = {
## 'pagewidth' : '70em',
## 'sidebarwidth' : '20em'
## }
html_theme_options = {
#'navbar_class': 'navbar-inverse',
'navbar_sidebarrel': False,
'bootswatch_theme': 'cosmo',
'bootstrap_version': '3',
}
#html_theme_options = {
# #'navbar_class': 'navbar-inverse',
# 'navbar_sidebarrel': False,
# 'bootswatch_theme': 'cosmo',
# 'bootstrap_version': '3',
#}

# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = ['./']
html_theme_path = sphinx_bootstrap_theme.get_html_theme_path()
#html_theme_path = sphinx_bootstrap_theme.get_html_theme_path()

# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
Expand Down
74 changes: 41 additions & 33 deletions docs/source/examples/example_doc_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from atom.api import Atom, Unicode, Value
import enaml
from enaml.qt.qt_application import QtApplication
from enaml.qt.QtGui import QPixmap
from enaml.qt.QtWidgets import QApplication
from enaml.qt.QtTest import QTest
from enaml.application import timed_call


Expand All @@ -45,17 +45,17 @@ def _observe_view(self, change):
if change['type'] == 'create':
self.view.initial_position = (10, 10)
self.view.always_on_top = True
timed_call(1500, self.snapshot)

def snapshot(self):
""" Take a snapshot of the window and close it.
"""
widget = self.view.proxy.widget
framesize = widget.window().frameSize()
QPixmap.grabWindow(QApplication.desktop().winId(), widget.x(),
widget.y(), framesize.width(),
framesize.height()).save(self.path)
screen = QApplication.primaryScreen()
screen.grabWindow(QApplication.desktop().winId(), widget.x(),
widget.y(), framesize.width(),
framesize.height()).save(self.path)
self.view.close()


Expand Down Expand Up @@ -85,6 +85,38 @@ def generate_example_doc(app, docs_path, script_path):
with open(os.path.join(script_path)) as fid:
script_text = fid.read()

temp_path = os.path.join(docs_path, os.path.basename(script_path))

with open(temp_path, 'wb') as fid:
fid.write(script_text.encode())

snapshot_success = True
mod = None
with enaml.imports():
try:
mod = __import__(script_name)
except Exception as err:
print('Could not create: %s' % script_name)
print(' %s' % err)
os.remove(temp_path)
snapshot_success = False

if mod:
try:
view = mod.Main()
snapshot = SnapShot(path=image_path, view=view)
view.show()
QTest.qWaitForWindowExposed(view.proxy.widget)
QTest.qWait(500)
snapshot.snapshot()
QTest.qWait(100)
except Exception as err:
print('Could not create: %s' % script_name)
print(' %s' % err)
snapshot_success = False
finally:
os.remove(temp_path)

docstring = script_text[script_text.find('"""') + 3:]
docstring = docstring[: docstring.find('"""')]
docstring = docstring.replace('<< autodoc-me >>\n', '').strip()
Expand All @@ -102,42 +134,18 @@ def generate_example_doc(app, docs_path, script_path):
::
$ enaml-run {1}
.. image:: images/{4}
{4}
.. literalinclude:: ../../../{2}
:language: enaml
""".format(script_title, script_name, relative_script_path,
docstring.replace('\n', '\n '), script_image_name)
docstring.replace('\n', '\n '),
('\n.. image:: images/%s\n' % script_image_name if snapshot_success
else ''))

with open(rst_path, 'wb') as fid:
fid.write(rst_template.lstrip().encode())

temp_path = os.path.join(docs_path, os.path.basename(script_path))

with open(temp_path, 'wb') as fid:
fid.write(script_text.encode())

with enaml.imports():
try:
mod = __import__(script_name)
except Exception as err:
print('Could not create: %s' % script_name)
print(' %s' % err)
os.remove(temp_path)
return
try:
view = mod.Main()
SnapShot(path=image_path, view=view)
view.show()
app.start()
except Exception as err:
print('Could not create: %s' % script_name)
print(' %s' % err)
finally:
os.remove(temp_path)


def main():
""" Generate documentation for all enaml examples requesting autodoc.
Expand Down
52 changes: 35 additions & 17 deletions docs/source/examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,29 @@ Tutorial Examples
tut_hello_world
tut_person
tut_employee


Widgets Examples
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------

.. toctree::

ex_buttons
ex_context_menu
ex_dock_area
ex_dock_pane
ex_drag_and_drop
ex_dual_slider
ex_field
ex_file_dialog
ex_flow_area
ex_focus_traversal
ex_form_spacing
ex_form
ex_group_box
ex_h_group
ex_image_view
ex_ipython_console
ex_main_window
ex_menu_bar
ex_mpl_canvas
Expand All @@ -42,17 +48,19 @@ Widgets Examples
ex_spin_box
ex_splitter
ex_tool_bar
ex_tool_buttons
ex_v_group
ex_vtk_canvas
ex_window
ex_window_children
ex_window_closing


Layout Examples
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------

Basic
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. toctree::

Expand All @@ -66,23 +74,25 @@ Basic
ex_linear_relations
ex_vbox
ex_vertical

Advanced
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. toctree::

ex_button_ring
ex_factory_func
ex_find_replace
ex_fluid
ex_manual_hbox
ex_manual_vbox
ex_nested_boxes
ex_nested_containers
ex_override_layout_constraints


Stdlib Examples
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------

.. toctree::

Expand All @@ -92,18 +102,18 @@ Stdlib Examples


Dynamic Examples
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------

.. toctree::

ex_conditional
ex_fields
ex_looper
ex_notebook_pages


Aliases Examples
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------

.. toctree::

Expand All @@ -113,8 +123,18 @@ Aliases Examples
ex_simple_widget_alias


Functions Examples
-------------------------------------------------------------------------------

.. toctree::

ex_declare_function
ex_observe_model_signal
ex_override_function


Styling Examples
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------

.. toctree::

Expand All @@ -124,18 +144,16 @@ Styling Examples


Templates Examples
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------

.. toctree::

ex_advanced
ex_basic




Applib Examples
--------------------------------------------------------------------------------
-------------------------------------------------------------------------------

.. toctree::

Expand Down
2 changes: 1 addition & 1 deletion enaml/widgets/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def show(self):
self.activate_proxy()
super(Window, self).show()

#--------------------------------------------------------------------------
#-------------------------------------------------------------------------
# Observers
#--------------------------------------------------------------------------
@observe('title', 'modality', 'icon')
Expand Down
3 changes: 2 additions & 1 deletion examples/widgets/window_closing.enaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

This example shows how to customize the closing of a window.

<< autodoc-me >>
We do not autodocument this example this is requires a more complex workflow.

"""
from enaml.widgets.api import Window
from enaml.stdlib.message_box import question
Expand Down

0 comments on commit 578274f

Please sign in to comment.